Set the itemID member of the DRAWITEMSTRUCT to the number of the
[wine/multimedia.git] / server / unicode.c
blob3ba4e03224e4281c2e4f72cdbf335dff736159ab
1 /*
2 * Unicode routines for use inside the server
4 * Copyright (C) 1999 Alexandre Julliard
5 */
7 #include <stdio.h>
9 #include "unicode.h"
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....";
15 char buffer[256];
16 char *pos = buffer;
17 int count = 0;
19 for (; len; str++, len--)
21 if (pos > buffer + sizeof(buffer) - 8)
23 fwrite( buffer, pos - buffer, 1, f );
24 count += pos - buffer;
25 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 );
31 else
32 pos += sprintf( pos, "\\x%x", *str );
33 continue;
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 );
42 else
43 pos += sprintf( pos, "\\%o", *str );
44 continue;
46 if (*str == '\\' || *str == escape[0] || *str == escape[1]) *pos++ = '\\';
47 *pos++ = *str;
49 fwrite( buffer, pos - buffer, 1, f );
50 count += pos - buffer;
51 return count;