2 * Unicode routines for use inside the server
4 * Copyright (C) 1999 Alexandre Julliard
12 /* dump a Unicode string with proper escaping */
13 int dump_strW( const WCHAR *str, size_t len, FILE *f, char escape[2] )
15 static const char escapes[32] = ".......abtnvfr.............e....";
20 for (; len; str++, len--)
22 if (pos > buffer + sizeof(buffer) - 8)
24 fwrite( buffer, pos - buffer, 1, f );
25 count += pos - buffer;
28 if (*str > 127) /* hex escape */
30 if (len > 1 && str[1] < 128 && isxdigit((char)str[1]))
31 pos += sprintf( pos, "\\x%04x", *str );
33 pos += sprintf( pos, "\\x%x", *str );
36 if (*str < 32) /* octal or C escape */
38 if (!*str && len == 1) continue; /* do not output terminating NULL */
39 if (escapes[*str] != '.')
40 pos += sprintf( pos, "\\%c", escapes[*str] );
41 else if (len > 1 && str[1] >= '0' && str[1] <= '7')
42 pos += sprintf( pos, "\\%03o", *str );
44 pos += sprintf( pos, "\\%o", *str );
47 if (*str == '\\' || *str == escape[0] || *str == escape[1]) *pos++ = '\\';
50 fwrite( buffer, pos - buffer, 1, f );
51 count += pos - buffer;