2 * Unicode routines for use inside the server
4 * Copyright (C) 1999 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
29 /* dump a Unicode string with proper escaping */
30 int dump_strW( const WCHAR
*str
, size_t len
, FILE *f
, const char escape
[2] )
32 static const char escapes
[32] = ".......abtnvfr.............e....";
37 for (; len
; str
++, len
--)
39 if (pos
> buffer
+ sizeof(buffer
) - 8)
41 fwrite( buffer
, pos
- buffer
, 1, f
);
42 count
+= pos
- buffer
;
45 if (*str
> 127) /* hex escape */
47 if (len
> 1 && str
[1] < 128 && isxdigit((char)str
[1]))
48 pos
+= sprintf( pos
, "\\x%04x", *str
);
50 pos
+= sprintf( pos
, "\\x%x", *str
);
53 if (*str
< 32) /* octal or C escape */
55 if (!*str
&& len
== 1) continue; /* do not output terminating NULL */
56 if (escapes
[*str
] != '.')
57 pos
+= sprintf( pos
, "\\%c", escapes
[*str
] );
58 else if (len
> 1 && str
[1] >= '0' && str
[1] <= '7')
59 pos
+= sprintf( pos
, "\\%03o", *str
);
61 pos
+= sprintf( pos
, "\\%o", *str
);
64 if (*str
== '\\' || *str
== escape
[0] || *str
== escape
[1]) *pos
++ = '\\';
67 fwrite( buffer
, pos
- buffer
, 1, f
);
68 count
+= pos
- buffer
;