CreatePreferences()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

CreatePreferences()

Post by NoahPhense »

Not sure what version this started at.. because I have not been coding for while. But the code below I have in a lot of my apps. Been testing it and now, it creates a blank line 1 in a new file. (?)

Code: Select all

Procedure.b WriteINIFile_New()
  ret.b = 0
  If CreatePreferences("my.ini")
    PreferenceComment("")
    PreferenceComment("xxx")
    PreferenceComment("")
    PreferenceGroup("settings")
    WritePreferenceString("xxx", "xxx")
    ClosePreferences()
    ret + 1
  EndIf
  ProcedureReturn ret
EndProcedure
- np
Last edited by NoahPhense on Sat May 16, 2015 2:48 am, edited 1 time in total.
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: CreatePreferences()

Post by kenmo »

I have seen this too (PB 5.31 / Windows).

It only happens in Unicode mode!

It's also one of the things I mention (and "fix") in this post yesterday :D
http://www.purebasic.fr/english/viewtop ... 12&t=62236
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: CreatePreferences()

Post by NoahPhense »

Hey Kenmo, that's some great code you made there. Looks like you put a lot of thought into it. I will give it a check later.

For now, I have changed out of Unicode. That fixed the empty first line.

- np
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: CreatePreferences()

Post by Fred »

User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: CreatePreferences()

Post by kenmo »

Thanks for the link, Fred. The reason makes sense now -- the newline is added as a divider between the UTF-8 BOM and the first key name.


So instead, how about a #PB_Preference_NoBOM flag (which would remove the BOM and the newline) for those of us who prefer the UTF-8 Everywhere approach :)
utf8everywhere.org wrote:From the Unicode Standard (v6.2, p.30): "Use of a BOM is neither required nor recommended for UTF-8".

Byte order issues are yet another reason to avoid UTF-16. UTF-8 has no endianness issues, and the UTF-8 BOM exists only to manifest that this is a UTF-8 stream. If UTF-8 remains the only popular encoding (as it already is in the internet world), the BOM becomes redundant. In practice, most UTF-8 text files omit BOMs today.
Post Reply