fwrite() - asian characters broken -
dax123 - 02.08.2010
I'm using korean version of windows and having a problem with scripting
I write a file to scriptfiles folder and I try to verify it with notepad,
if I use fwrite() function it just writes any korean character broken(or asian characters whatever..that requires UTF-
for example:
pawn Код:
new File:temp;
temp = fopen( "sample.txt", io_write );
fwrite( temp, "서버의 정책을 지정합니다." ) // which means 'assigning a policy for a server' for korean
fclose( temp );
and when I open the sample.txt it shows the characters like:
Код:
Њ*№цАЗ БЂГҐА» БцБЂЗХЋПЋЩ.
even when I open the text file with UTF-8 encoding the characters were still corrupted.
traditional workarounds like re-formatting( format(text,sizeof(text),"%s",text); )or using fixchars() function didn't work either.
but when I use fputchar() and set the utf8 argument to false then it shows fine in notepad.
so I had to make a workaround function like this:
pawn Код:
stock c_fwrite( File: handle, const string[] )
{
for( new i = 0; i < strlen( string ); i++ ) fputchar( handle, string[i], false);
return ;
}
so here is the question:
do you guys have a way to avoid UTF-8 character corruption with fwrite function?
thanks in advance.
Re: fwrite() - asian characters broken -
dax123 - 03.08.2010
anyone? maybe pro users like ****** can answer?
Re: fwrite() - asian characters broken -
bigcomfycouch - 03.08.2010
From the PAWN manual
Quote:
The line reading and writing functions support UTF-8 encoding when the string
to read/write is in unpacked format. When the source or destination string is a
packed string, the line functions assume ascii or another 8-bit encoding —such
as one of the ISO/IEC 8859 character sets (ISO/IEC 8859-1 is informally known
as “Latin-1”).
|
pawn Код:
new string[128], File:temp = fopen("sample.txt", io_write);
strpack(string, "서버의 정책을 지정합니다.", 128);
fwrite(temp, string) // which means 'assigning a policy for a server' for korean
fclose(temp);
Re: fwrite() - asian characters broken -
dax123 - 03.08.2010
Quote:
Originally Posted by bigcomfycouch
From the PAWN manual
pawn Код:
new string[128], File:temp = fopen("sample.txt", io_write); strpack(string, "서버의 정책을 지정합니다.", 128); fwrite(temp, string) // which means 'assigning a policy for a server' for korean fclose(temp);
|
wow I'll try it right away
Re: fwrite() - asian characters broken -
dax123 - 03.08.2010
it doesn't work.
strpack does nothing (like uuencode does nothing)
any suggestions?
Re: fwrite() - asian characters broken -
bigcomfycouch - 03.08.2010
edited
pawn Код:
new string[128];
new File: temp = fopen("sample.txt", io_write);
format(string, 128, "서버의 정책을 지정합니다.");
for(new j = 0; j < strlen(string); j++)
{
if(string[j] == '\0') break;
fputchar(temp, string[j], true);
}
fclose(temp);
can't test, non-latin characters are question marks for me in pawno
Re: fwrite() - asian characters broken -
dax123 - 06.08.2010
Quote:
Originally Posted by bigcomfycouch
edited
pawn Код:
new string[128]; new File: temp = fopen("sample.txt", io_write); format(string, 128, "서버의 정책을 지정합니다."); for(new j = 0; j < strlen(string); j++) { if(string[j] == '\0') break; fputchar(temp, string[j], true); } fclose(temp);
can't test, non-latin characters are question marks for me in pawno
|
doesn't work
It only works when utf8 argument is false
thanks anyway
Re: fwrite() - asian characters broken -
XPlatform - 06.08.2010
What about instead of writing the character, write the character value, and read them back? That should work.
Re: fwrite() - asian characters broken -
Souvlaki - 06.08.2010
pawn Код:
#define fwrite fwrite_utf8
//here your whole code
/*and at the bottom of your script*/
#undef fwrite
stock fwrite_utf8(File:handle, str[], bool:use_utf8 = false)
{
new x=0;
if(!handle) return 0;
while(str[x] != EOS) {
fputchar(handle, str[x], use_utf8);
x++;
}
return x;
}
Then fwrite will be able to write in utf-8 characters.But it will crash on linux :S
Re: fwrite() - asian characters broken -
dax123 - 06.08.2010
Quote:
Originally Posted by Souvlaki
pawn Код:
#define fwrite fwrite_utf8
//here your whole code
/*and at the bottom of your script*/
#undef fwrite stock fwrite_utf8(File:handle, str[], bool:use_utf8 = false) { new x=0; if(!handle) return 0; while(str[x] != EOS) { fputchar(handle, str[x], use_utf8); x++; }
return x; }
Then fwrite will be able to write in utf-8 characters.But it will crash on linux :S
|
sounds like hell :S:S:S