Home » U++ Library support » U++ Core » LoadFile problem with accented chars
Re: LoadFile problem with accented chars [message #20032 is a reply to message #20016] |
Wed, 11 February 2009 15:05   |
 |
koldo
Messages: 3443 Registered: August 2008
|
Senior Veteran |
|
|
Hello luzr
Everything solved. I inclose you some of the proposed functions:
String LoadFileBOM(const char *path)
{
String s = LoadFile(path);
if (((s[0]&0xFF) == 0xFF) && ((s[1]&0xFF) == 0xFE)) { // UTF16 Little Endian
StringBuffer ws = s.Mid(2);
s = ToUtf8((wchar *)ws.Begin(), ws.GetCount()*sizeof(char)/sizeof(wchar));
} else if (((s[0]&0xFF) == 0xEF) && ((s[1]&0xFF) == 0xBB) && ((s[2]&0xFF) == 0xBF)) // UTF8
s = s.Mid(3);
else // May be ISO8859-1
s = ToUtf8(ToUnicode(s, CHARSET_ISO8859_1));
return s;
}
bool SaveBOMUtf8(Stream& out, const String& data) {
if(!out.IsOpen() || out.IsError())
return false;
unsigned char bom[] = {0xEF, 0xBB, 0xBF};
out.Put(bom, 3);
out.Put((const char *)data, data.GetLength());
out.Close();
return out.IsOK();
}
bool SaveFileBOMUtf8(const char *path, const String& data)
{
FileOut out(path);
return SaveBOMUtf8(out, data);
}
When loading it checks the BOM if it is UTF-16 little endian or UTF-8. If there is no BOM it is considered to be ISO8859-1. It always return a UTF-8 String.
When saving it always save to UTF-8.
If they are right I will do the rest of functions.
There was no problem with EditString. My error was because it handles UTF-8 but not ISO8859-1 chars.
Best regards
Koldo
Best regards
IƱaki
[Updated on: Wed, 11 February 2009 15:07] Report message to a moderator
|
|
|
 |
|
LoadFile problem with accented chars
By: koldo on Sat, 07 February 2009 22:27
|
 |
|
Re: LoadFile problem with accented chars
By: mirek on Sun, 08 February 2009 08:06
|
 |
|
Re: LoadFile problem with accented chars
By: koldo on Sun, 08 February 2009 22:11
|
 |
|
Re: LoadFile problem with accented chars
By: mirek on Mon, 09 February 2009 08:12
|
 |
|
Re: LoadFile problem with accented chars
By: koldo on Mon, 09 February 2009 08:47
|
 |
|
Re: LoadFile problem with accented chars
By: mirek on Mon, 09 February 2009 17:28
|
 |
|
Re: LoadFile problem with accented chars
By: koldo on Tue, 10 February 2009 09:23
|
 |
|
Re: LoadFile problem with accented chars
By: koldo on Wed, 11 February 2009 15:05
|
 |
|
Re: LoadFile problem with accented chars
|
 |
|
Re: LoadFile problem with accented chars
By: koldo on Wed, 11 February 2009 19:26
|
 |
|
Re: LoadFile problem with accented chars
By: koldo on Thu, 12 February 2009 01:13
|
 |
|
Re: LoadFile problem with accented chars
By: mirek on Thu, 12 February 2009 18:02
|
 |
|
Re: LoadFile problem with accented chars
By: koldo on Fri, 13 February 2009 09:50
|
 |
|
Re: LoadFile problem with accented chars
By: mirek on Fri, 13 February 2009 11:05
|
 |
|
Re: LoadFile problem with accented chars
By: koldo on Fri, 13 February 2009 19:09
|
 |
|
Re: LoadFile problem with accented chars
By: mirek on Sun, 15 February 2009 00:05
|
Goto Forum:
Current Time: Sun Aug 17 02:02:57 CEST 2025
Total time taken to generate the page: 0.06212 seconds
|