Release 20031118.
[wine/multimedia.git] / server / unicode.c
blob16aea3df0f793f27480dcdffb6e739b71411f9ea
1 /*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <ctype.h>
25 #include <stdio.h>
27 #include "unicode.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....";
33 char buffer[256];
34 char *pos = buffer;
35 int count = 0;
37 for (; len; str++, len--)
39 if (pos > buffer + sizeof(buffer) - 8)
41 fwrite( buffer, pos - buffer, 1, f );
42 count += pos - buffer;
43 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 );
49 else
50 pos += sprintf( pos, "\\x%x", *str );
51 continue;
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 );
60 else
61 pos += sprintf( pos, "\\%o", *str );
62 continue;
64 if (*str == '\\' || *str == escape[0] || *str == escape[1]) *pos++ = '\\';
65 *pos++ = *str;
67 fwrite( buffer, pos - buffer, 1, f );
68 count += pos - buffer;
69 return count;