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
CreatePreferences PB 5.51
Re: CreatePreferences PB 5.51
In this thread Fred describes this as a feature, not a bug and a feature request has been posted to do it differently.Trion wrote:CreatePreferences makes now a blank line in the first line.
Re: CreatePreferences PB 5.51
If files created by this library are expected to be consumed by it then why the workaround? 

Re: CreatePreferences PB 5.51
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
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.
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
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.kenmo wrote:The UTF-8 BOM has to be there, because OpenPreferences() will read UTF-8 text as ASCII if there's no BOM.
Re: CreatePreferences PB 5.51
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.

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
PB UTF-8

0d and 0a makes blank line
With Notepad++ UTF-8

No blank line in the editor
Richard

0d and 0a makes blank line
With Notepad++ UTF-8

No blank line in the editor
Richard
Re: CreatePreferences PB 5.51
Why would it matter what Notepad++ does? It is a PureBasic library.Trion wrote:With Notepad++ UTF-8
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.