Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
koldo is currently offline  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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Core package build flags
Next Topic: Hi! Performance question
Goto Forum:
  


Current Time: Sun Aug 17 02:02:57 CEST 2025

Total time taken to generate the page: 0.06212 seconds