2 * UCW Library -- String Routines
4 * (c) 2006 Pavel Charvat <pchar@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
13 #include "lib/chartype.h"
16 /* Expands C99-like escape sequences.
17 * It is safe to use the same buffer for both input and output. */
19 str_unesc(byte *d, byte *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");