Page 1 of 1
ReadPreferenceString() has a problem with unicode files
Posted: Thu Feb 15, 2024 4:37 pm
by Lebostein
Generate a ini file (unicode):
Code: Select all
[EUR]
symbol = €
[GBP]
symbol = £
[CZK]
symbol = Kč
[PLN]
symbol = Zł
and try to read the values:
Code: Select all
OpenPreferences("test.ini")
ExaminePreferenceGroups()
While NextPreferenceGroup()
Debug ReadPreferenceString("symbol", "")
Wend
ClosePreferences()
What you get is:
â¬
£
KÄ
ZÅ
// Moved from "Bugs - Mac OSX" to "Coding Questions" (Kiffi)
Re: ReadPreferenceString() has a problem with unicode files
Posted: Thu Feb 15, 2024 5:13 pm
by Marc56us
PureBasic - Preference
[...] The file format is in unicode UTF-8 with a BOM [...]
(save your INI with a BOM)
Re: ReadPreferenceString() has a problem with unicode files
Posted: Thu Feb 15, 2024 5:18 pm
by STARGÅTE
Since PB 6.10, OpenPreferences has an additional parameter for the Encoding, try it out:
Code: Select all
OpenPreferences("test.ini", 0, #PB_UTF8)
Re: ReadPreferenceString() has a problem with unicode files
Posted: Thu Feb 15, 2024 6:01 pm
by Lebostein
Thanks! Nice to know.
But what happens if I create a preference file with CreatePreferences()? Here the new encoding flag is missing...
Edit: most of the Apple / Mac OS Text editors I use ignore/remove the BOM (i.e. Apples TextEdit or other editors like Smultron), because mac OS is fully based on UTF-8 without BOM. For testing I started windows and use Notepad++ to generate a UTF-8 file with BOM.
Re: ReadPreferenceString() has a problem with unicode files
Posted: Thu Feb 15, 2024 8:02 pm
by STARGÅTE
CreatePreferences creates always a UTF-8 file.
You can use the flag: #PB_Preference_NoBOM, to remove the usually set UTF8 BOM.
Re: ReadPreferenceString() has a problem with unicode files
Posted: Thu Feb 22, 2024 11:02 am
by Lebostein
Thanks. In Beta 6 #PB_Preference_NoBOM for CreatePreferences() is not known by the Debugger (returns an error, missplaced constant), but I hope this is fixed in the final.