2 * Unicode routines for use inside the server
4 * Copyright (C) 1999 Alexandre Julliard
11 /* dump a Unicode string with proper escaping */
12 int dump_strW( const WCHAR *str, size_t len, FILE *f, char escape[2] )
14 static const char escapes[32] = ".......abtnvfr.............e....";
19 for (; len; str++, len--)
21 if (pos > buffer + sizeof(buffer) - 8)
23 fwrite( buffer, pos - buffer, 1, f );
24 count += pos - buffer;
27 if (*str > 127) /* hex escape */
29 if (len > 1 && str[1] < 128 && isxdigit((char)str[1]))
30 pos += sprintf( pos, "\\x%04x", *str );
32 pos += sprintf( pos, "\\x%x", *str );
35 if (*str < 32) /* octal or C escape */
37 if (!*str && len == 1) continue; /* do not output terminating NULL */
38 if (escapes[*str] != '.')
39 pos += sprintf( pos, "\\%c", escapes[*str] );
40 else if (len > 1 && str[1] >= '0' && str[1] <= '7')
41 pos += sprintf( pos, "\\%03o", *str );
43 pos += sprintf( pos, "\\%o", *str );
46 if (*str == '\\' || *str == escape[0] || *str == escape[1]) *pos++ = '\\';
49 fwrite( buffer, pos - buffer, 1, f );
50 count += pos - buffer;