+static void unescapeString(string_t * tmp)
+{
+ char *p, *p1;
+ /* fixme - this routine expects the string to be
+ null-terminated */
+
+ for (p1=(char*)tmp->str; (p=strchr(p1, '\\')); p1 = p+1)
+ {
+ int nr=2;
+ int new=1;
+ switch(p[1])
+ {
+ case '\\': p[0] = '\\'; break;
+ case '"': p[0] = '"'; break;
+ case 'b': p[0] = '\b'; break;
+ case 'f': p[0] = '\f'; break;
+ case 'n': p[0] = '\n'; break;
+ case 'r': p[0] = '\r'; break;
+ case 't': p[0] = '\t'; break;
+ case 'x': case 'u': {
+ int max=4;
+ int num=0;
+ char*utf8;
+ char bracket = 0;
+ if(p[1] == 'u')
+ max = 6;
+ if(p[2] == '{') {
+ bracket = 1;nr++;max++;
+ }
+ while(strchr("0123456789abcdefABCDEF", p[nr]) && (bracket || nr < max)) {
+ num <<= 4;
+ if(p[nr]>='0' && p[nr]<='9') num |= p[nr] - '0';
+ if(p[nr]>='a' && p[nr]<='f') num |= p[nr] - 'a' + 10;
+ if(p[nr]>='A' && p[nr]<='F') num |= p[nr] - 'A' + 10;
+ nr++;
+ }
+ if(bracket && p[nr]=='}') {
+ bracket = 0;
+ nr++;
+ }
+ utf8 = getUTF8(num);
+ new = strlen(utf8);
+ memcpy(p, utf8, new); // do not copy the terminating zero
+ break;
+ }
+ default:
+ continue;
+ }
+ tmp->len -= (nr-new);
+ {
+ int t;
+ char*to=p+new,*from=p+nr;
+ while(*from) {
+ *to = *from;
+ to++;
+ from++;
+ }
+ }
+ }
+}
+