1999-11-25 22:30:24 +01:00
|
|
|
/*
|
|
|
|
* Unicode routines for use inside the server
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-11-25 22:30:24 +01:00
|
|
|
*/
|
|
|
|
|
2002-04-26 21:05:15 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2000-07-25 23:01:59 +02:00
|
|
|
#include <ctype.h>
|
1999-11-25 22:30:24 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "unicode.h"
|
|
|
|
|
|
|
|
/* dump a Unicode string with proper escaping */
|
2003-10-22 01:57:25 +02:00
|
|
|
int dump_strW( const WCHAR *str, size_t len, FILE *f, const char escape[2] )
|
1999-11-25 22:30:24 +01:00
|
|
|
{
|
|
|
|
static const char escapes[32] = ".......abtnvfr.............e....";
|
|
|
|
char buffer[256];
|
|
|
|
char *pos = buffer;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (; len; str++, len--)
|
|
|
|
{
|
|
|
|
if (pos > buffer + sizeof(buffer) - 8)
|
|
|
|
{
|
|
|
|
fwrite( buffer, pos - buffer, 1, f );
|
|
|
|
count += pos - buffer;
|
|
|
|
pos = buffer;
|
|
|
|
}
|
|
|
|
if (*str > 127) /* hex escape */
|
|
|
|
{
|
|
|
|
if (len > 1 && str[1] < 128 && isxdigit((char)str[1]))
|
|
|
|
pos += sprintf( pos, "\\x%04x", *str );
|
|
|
|
else
|
|
|
|
pos += sprintf( pos, "\\x%x", *str );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*str < 32) /* octal or C escape */
|
|
|
|
{
|
|
|
|
if (!*str && len == 1) continue; /* do not output terminating NULL */
|
|
|
|
if (escapes[*str] != '.')
|
|
|
|
pos += sprintf( pos, "\\%c", escapes[*str] );
|
|
|
|
else if (len > 1 && str[1] >= '0' && str[1] <= '7')
|
|
|
|
pos += sprintf( pos, "\\%03o", *str );
|
|
|
|
else
|
|
|
|
pos += sprintf( pos, "\\%o", *str );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*str == '\\' || *str == escape[0] || *str == escape[1]) *pos++ = '\\';
|
|
|
|
*pos++ = *str;
|
|
|
|
}
|
|
|
|
fwrite( buffer, pos - buffer, 1, f );
|
|
|
|
count += pos - buffer;
|
|
|
|
return count;
|
|
|
|
}
|