[Solved] CreatePreferences() - remove BOM in Unicode mode

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

[Solved] CreatePreferences() - remove BOM in Unicode mode

Post by Korolev Michael »

Code: Select all

CreatePreferences("1.ini")
WritePreferenceString("Key","Value")
ClosePreferences()
When compiled in Unicode mode, creates redundant #CRLF$ sequence in start of preference file.
Last edited by Korolev Michael on Sun Sep 08, 2013 10:19 am, edited 2 times in total.
Former user of pirated PB.
Now registered user :].
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Re: 5.20B11: CreatePreferences() empty line

Post by USCode »

Korolev Michael wrote:

Code: Select all

CreatePreferences("1.ini")
WritePreferenceString("Key","Value")
ClosePreferences()
When compiled in Unicode mode, creates redundant #CRLF$ sequence in start of preference file.
Looks like this one has been around for awhile, I was able to replicate in PB 5.11 (x64) on Win7.
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: 5.20B11: CreatePreferences() empty line

Post by Korolev Michael »

Yes, I noticed this behaviour in 5.11 too.
Former user of pirated PB.
Now registered user :].
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: 5.20B11: CreatePreferences() empty line

Post by freak »

It is on purpose. The file starts with an UTF-8 byte order mark because preferences are written as UTF-8 in unicode mode. The newline is there so programs that don't understand the BOM don't confuse it as part of the first key.
quidquid Latine dictum sit altum videtur
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Re: [Done] 5.20B11: CreatePreferences() empty line

Post by USCode »

freak wrote:It is on purpose. The file starts with an UTF-8 byte order mark because preferences are written as UTF-8 in unicode mode. The newline is there so programs that don't understand the BOM don't confuse it as part of the first key.
Ah, makes sense. These guys are GOOD! :mrgreen:
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: [Done] 5.20B11: CreatePreferences() empty line

Post by Korolev Michael »

I reckon, file must look as programmer expects. It's problem of those programs, if they can't determine codepage correctly. If programmer wants empty line to help other programs - please, provide him a choice.

What we have:

Code: Select all


[Group_1]
Key0=Value0
Key2=Value2
[Group_2]
Key3=Value3
Key3=Value3
But this looks tidier:

Code: Select all

[Group_1]
Key0=Value0
Key2=Value2

[Group_2]
Key3=Value3
Key3=Value3
Last edited by Korolev Michael on Wed Aug 21, 2013 7:22 am, edited 1 time in total.
Former user of pirated PB.
Now registered user :].
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [Done] 5.20B11: CreatePreferences() empty line

Post by Fred »

What about using the #PB_Preference_GroupSeparator flag ?
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: [Done] 5.20B11: CreatePreferences() empty line

Post by Korolev Michael »

Thanks, @Fred, I forgot to look at available flags. But these were optional, first newline is still annoying. It's MY config for MY program. So, why do I need to make hacks for "programs that don't understand the BOM", as @freak said?

Can you do something with this? Please, allow to programmers make decision about necessity of newline.
Former user of pirated PB.
Now registered user :].
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [No, not done] 5.20B11: CreatePreferences() empty line

Post by Fred »

Moved to feature and request as it's not a bug.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: [Done] 5.20B11: CreatePreferences() empty line

Post by PMV »

Korolev Michael wrote:It's MY config for MY program. So, why do I need to make hacks for "programs that don't understand the BOM", as @freak said?
lol? You are using a build-in-feature ... that is designed to work with
themself and not to work with program XYZ. And it is not Freds
mistake if you want to use a program, that can't handle BOOM.
Especially ... if you want OUR way, do it YOURself. :lol:
No hack needed. :shock:

You can start with my work for example:
http://forums.purebasic.com/german/view ... =8&t=12117
:)

MFG PMV
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: CreatePreferences() - remove BOM in Unicode mode

Post by Korolev Michael »

Agreed, it's not-a-bug.
@PMV I don't have much time to invent my own wheel. There is standard function and we can make it better, isn't it?
Former user of pirated PB.
Now registered user :].
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: CreatePreferences() - remove BOM in Unicode mode

Post by Korolev Michael »

Fred, I propose to make for CreatePreferences() an optional flag, something like #PB_Preference_FirstLineEmpty
Former user of pirated PB.
Now registered user :].
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

Re: CreatePreferences() - remove BOM in Unicode mode

Post by Olby »

Korolev Michael wrote:Fred, I propose to make for CreatePreferences() an optional flag, something like #PB_Preference_FirstLineEmpty
Does this affects your program, will the world end if you'll have an additional blank line in there? I mean most feature requests are "valid-ish", but this one seems to be just nitpicking on something that 99.9% perhaps haven't even noticed. If you really need to remove that blank line why not just open the file and remove the first line manually using the file access library commands. Sorry, but to me this request just seems a waste of PB developers time they can rather be spending implementing more great new functionality and fixing bugs. :(
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: CreatePreferences() - remove BOM in Unicode mode

Post by PMV »

Korolev Michael wrote:Agreed, it's not-a-bug.
@PMV I don't have much time to invent my own wheel. There is standard function and we can make it better, isn't it?
Why should some one else do something for you, if
you even doesn't care enough to do it yourself? :lol:
:wink:

MFG PMV
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Re: CreatePreferences() - remove BOM in Unicode mode

Post by USCode »

I know it isn't ideal but you could of course write a quick file routine that removes that extra newline, or reformats the file anyway you prefer for that matter.
Post Reply