2 * UCW Library -- String Routines
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 "lib/chartype.h"
17 /* Expands C99-like escape sequences.
18 * It is safe to use the same buffer for both input and output. */
20 str_unesc(char *d, const char *s)
27 case 'a': *d++ = '\a'; s += 2; break;
28 case 'b': *d++ = '\b'; s += 2; break;
29 case 'f': *d++ = '\f'; s += 2; break;
30 case 'n': *d++ = '\n'; s += 2; break;
31 case 'r': *d++ = '\r'; s += 2; break;
32 case 't': *d++ = '\t'; s += 2; break;
33 case 'v': *d++ = '\v'; s += 2; break;
34 case '\?': *d++ = '\?'; s += 2; break;
35 case '\'': *d++ = '\''; s += 2; break;
36 case '\"': *d++ = '\"'; s += 2; break;
37 case '\\': *d++ = '\\'; s += 2; break;
42 DBG("\\x used with no following hex digits");
47 uns v = strtoul(s + 2, &p, 16);
51 DBG("hex escape sequence out of range");
56 if (s[1] >= '0' && s[1] <= '7')
60 for (uns i = 0; i < 2 && *s >= '0' && *s <= '7'; s++, i++)
61 v = (v << 3) + *s - '0';
65 DBG("octal escape sequence out of range");
78 str_format_flags(char *dest, const char *fmt, uns flags)
81 for (uns i=0; fmt[i]; i++)