Commit 44224325 authored by Alexandre Julliard's avatar Alexandre Julliard

wrc: Added support for utf-8 codepage.

parent d8c3e7de
......@@ -347,12 +347,13 @@ static struct keyword *iskeyword(char *kw)
<pp_pragma>[^\n]* yy_pop_state(); if (pedantic) parser_warning("Unrecognized #pragma directive '%s'",yytext);
<pp_code_page>\({ws}*default{ws}*\)[^\n]* current_codepage = -1; yy_pop_state();
<pp_code_page>\({ws}*utf8{ws}*\)[^\n]* current_codepage = CP_UTF8; yy_pop_state();
<pp_code_page>\({ws}*[0-9]+{ws}*\)[^\n]* {
char *p = yytext;
yy_pop_state();
while (*p < '0' || *p > '9') p++;
current_codepage = strtol( p, NULL, 10 );
if (current_codepage && !wine_cp_get_table( current_codepage ))
if (current_codepage && current_codepage != CP_UTF8 && !wine_cp_get_table( current_codepage ))
{
parser_error("Codepage %d not supported", current_codepage);
current_codepage = 0;
......
......@@ -244,26 +244,38 @@ string_t *convert_string(const string_t *str, enum str_e type, int codepage)
{
const union cptable *cptable = codepage ? wine_cp_get_table( codepage ) : NULL;
string_t *ret = xmalloc(sizeof(*ret));
int res;
if (!cptable && str->type != type)
error( "Current language is Unicode only, cannot convert strings" );
if (!codepage && str->type != type)
parser_error( "Current language is Unicode only, cannot convert string" );
if((str->type == str_char) && (type == str_unicode))
{
ret->type = str_unicode;
ret->size = wine_cp_mbstowcs( cptable, 0, str->str.cstr, str->size, NULL, 0 );
ret->size = cptable ? wine_cp_mbstowcs( cptable, 0, str->str.cstr, str->size, NULL, 0 )
: wine_utf8_mbstowcs( 0, str->str.cstr, str->size, NULL, 0 );
ret->str.wstr = xmalloc( (ret->size+1) * sizeof(WCHAR) );
wine_cp_mbstowcs( cptable, 0, str->str.cstr, str->size, ret->str.wstr, ret->size );
if (cptable)
res = wine_cp_mbstowcs( cptable, MB_ERR_INVALID_CHARS, str->str.cstr, str->size,
ret->str.wstr, ret->size );
else
res = wine_utf8_mbstowcs( MB_ERR_INVALID_CHARS, str->str.cstr, str->size,
ret->str.wstr, ret->size );
if (res == -2)
parser_error( "Invalid character in string '%.*s' for codepage %u\n",
str->size, str->str.cstr, codepage );
ret->str.wstr[ret->size] = 0;
}
else if((str->type == str_unicode) && (type == str_char))
{
ret->type = str_char;
ret->size = wine_cp_wcstombs( cptable, 0, str->str.wstr, str->size,
NULL, 0, NULL, NULL );
ret->size = cptable ? wine_cp_wcstombs( cptable, 0, str->str.wstr, str->size, NULL, 0, NULL, NULL )
: wine_utf8_wcstombs( str->str.wstr, str->size, NULL, 0 );
ret->str.cstr = xmalloc( ret->size + 1 );
wine_cp_wcstombs( cptable, 0, str->str.wstr, str->size, ret->str.cstr, ret->size,
NULL, NULL );
if (cptable)
wine_cp_wcstombs( cptable, 0, str->str.wstr, str->size, ret->str.cstr, ret->size, NULL, NULL );
else
wine_utf8_wcstombs( str->str.wstr, str->size, ret->str.cstr, ret->size );
ret->str.cstr[ret->size] = 0;
}
else if(str->type == str_unicode)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment