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 #20016 is a reply to message #19983] Tue, 10 February 2009 09:23 Go to previous messageGo to previous message
koldo is currently offline  koldo
Messages: 3372
Registered: August 2008
Senior Veteran
Hello luzr

I have had problems. In reading an UTF16-Little Endian, ToUtf8 does not seem to do it well.

I have used this function:
String  LoadFileBOM(const char *path)
{
	String s = LoadFile(path);
	if (((s[0]&0xFF) == 0xFF) && ((s[1]&0xFF) == 0xFE))					// UTF16 Little Endian
		s = ToUtf8(s.Mid(2).ToWString());
	else if (((s[0]&0xFF) == 0xEF) && ((s[1]&0xFF) == 0xBB) && ((s[2]&0xFF) == 0xBF))	// UTF8
		s = s.Mid(3);
	return s;
}


that is called from here:

String s = LoadFileBOM("demo_u_16le.txt");
String ss;
	
for (int i = 0; i < s.GetCount(); ++i)
	ss.Cat(Format("%d: %0x;\n", i, s[i]&0xFF));
	
ss.Cat(s);
TestLineEdit.SetData(ss);
TestEditString.SetData(ss);
TestDocEdit.SetData(ss);


As the file only contains "Aupá", the output should have to be:

Quote:

0: 41;
1: 75;
2: 70;
3: c3;
4: a1;
Aupá


but it is:

Quote:

0: 41;
1: 0;
2: 75;
3: 0;
4: 70;
5: 0;
6: e1;
7: 0;
Aup


Another question. When loading an UTF8 file with the later code, LineEdit and DocEdit reads it right but EditString shows a strange char. Does EditString not show UTF8 or I am doing it wrong?.

Best regards
Koldo


Best regards
Iñaki
 
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: Wed Jun 12 07:32:25 CEST 2024

Total time taken to generate the page: 0.02625 seconds