2 * UCW Library -- String Unescaping
4 * (c) 2006 Pavel Charvat <pchar@ucw.cz>
5 * (c) 2007 Martin Mares <mj@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
14 #include "ucw/string.h"
15 #include "ucw/chartype.h"
19 str_unesc(char *d, const char *s)
26 case 'a': *d++ = '\a'; s += 2; break;
27 case 'b': *d++ = '\b'; s += 2; break;
28 case 'f': *d++ = '\f'; s += 2; break;
29 case 'n': *d++ = '\n'; s += 2; break;
30 case 'r': *d++ = '\r'; s += 2; break;
31 case 't': *d++ = '\t'; s += 2; break;
32 case 'v': *d++ = '\v'; s += 2; break;
33 case '\?': *d++ = '\?'; s += 2; break;
34 case '\'': *d++ = '\''; s += 2; break;
35 case '\"': *d++ = '\"'; s += 2; break;
36 case '\\': *d++ = '\\'; s += 2; break;
41 DBG("\\x used with no following hex digits");
46 uns v = strtoul(s + 2, &p, 16);
50 DBG("hex escape sequence out of range");
55 if (s[1] >= '0' && s[1] <= '7')
59 for (uns i = 0; i < 2 && *s >= '0' && *s <= '7'; s++, i++)
60 v = (v << 3) + *s - '0';
64 DBG("octal escape sequence out of range");
82 int main(int argc, char **argv)
87 char tmp[strlen(argv[1]) + 1];
88 int len = str_unesc(tmp, argv[1]) - tmp;
91 mem_to_hex(hex, tmp, len, ' ');