Page 1 of 1
CreatePreferences PB 5.51
Posted: Mon Jan 16, 2017 1:13 am
by Trion
Hello,
CreatePreferences makes now a blank line in the first line.
PureBasic - Preference example file
Windows 10 64 Bit
<blank line>
[Global]
ApplicationName = MP3 Player
Version = 1.1b
; This is the Window dimension
;
[Window]
WindowX = 123
WindowY = 124
WindowZ = -125.500000
Richard
Re: CreatePreferences PB 5.51
Posted: Mon Jan 16, 2017 2:15 am
by Demivec
Trion wrote:CreatePreferences makes now a blank line in the first line.
In this
thread Fred describes this as a feature, not a bug and a feature request has been posted to do it differently.
Re: CreatePreferences PB 5.51
Posted: Mon Jan 16, 2017 8:00 am
by Mistrel
If files created by this library are expected to be consumed by it then why the workaround?

Re: CreatePreferences PB 5.51
Posted: Mon Jan 16, 2017 5:20 pm
by kenmo
The blank line is there to separate the UTF-8 BOM from the first preference entry.
See
http://www.purebasic.fr/english/viewtop ... =3&t=56113
The UTF-8 BOM has to be there, because OpenPreferences() will read UTF-8 text as ASCII if there's no BOM.
See
http://www.purebasic.fr/english/viewtop ... =4&t=67221
Code: Select all
File.s = GetTemporaryDirectory() + "temp.ini"
CreateFile(0, File, #PB_UTF8)
WriteString(0, "Name = Héllo")
CloseFile(0)
OpenPreferences(File) ; Open UTF-8 prefs file WITHOUT B.O.M.
Debug ReadPreferenceString("Name", "")
ClosePreferences()
OpenFile(0, File, #PB_UTF8)
Debug StringField( ReadString(0), 2, " = ")
CloseFile(0)
Ideally, you could avoid the BOM/newline with a #PB_Preferences_NoBOM flag.
But OpenPreferences() would need to accept #PB_UTF8 like OpenFile(), to read UTF-8 text correctly.
I've just accepted the extra blank line.

Re: CreatePreferences PB 5.51
Posted: Mon Jan 16, 2017 8:52 pm
by Mistrel
kenmo wrote:The UTF-8 BOM has to be there, because OpenPreferences() will read UTF-8 text as ASCII if there's no BOM.
If the file is both supplied and consumed by the same library then it already has control of the format being both written to and read from disk. Therefore I don't understand why there is any worry about whether it will be read incorrectly.
Re: CreatePreferences PB 5.51
Posted: Tue Jan 17, 2017 2:48 am
by kenmo
I personally agree
But for now, Unicode PureBasic forces a UTF-8 BOM and blank line, for ASCII program safety.
So we must accept a harmless blank line, or write your own preferences file manually, in your choice of encoding, with or without BOMs.
Re: CreatePreferences PB 5.51
Posted: Wed Jan 18, 2017 12:07 am
by Trion
PB UTF-8
0d and 0a makes blank line
With Notepad++ UTF-8
No blank line in the editor
Richard
Re: CreatePreferences PB 5.51
Posted: Wed Jan 18, 2017 1:14 am
by Demivec
Trion wrote:With Notepad++ UTF-8
Why would it matter what Notepad++ does? It is a PureBasic library.
As explained in the thread that was linked to above, the blank line is used as a delimeter. The contents of the file are read until the end of the first line. If there is a BOM for UTF-8 there then the contents of the file are unicode, else it is ASCII.