Page 1 of 2
[Solved] CreatePreferences() - remove BOM in Unicode mode
Posted: Tue Aug 20, 2013 3:32 pm
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.
Re: 5.20B11: CreatePreferences() empty line
Posted: Tue Aug 20, 2013 7:23 pm
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.
Re: 5.20B11: CreatePreferences() empty line
Posted: Wed Aug 21, 2013 12:00 am
by Korolev Michael
Yes, I noticed this behaviour in 5.11 too.
Re: 5.20B11: CreatePreferences() empty line
Posted: Wed Aug 21, 2013 12:04 am
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.
Re: [Done] 5.20B11: CreatePreferences() empty line
Posted: Wed Aug 21, 2013 12:09 am
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!

Re: [Done] 5.20B11: CreatePreferences() empty line
Posted: Wed Aug 21, 2013 5:38 am
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
Re: [Done] 5.20B11: CreatePreferences() empty line
Posted: Wed Aug 21, 2013 9:40 am
by Fred
What about using the #PB_Preference_GroupSeparator flag ?
Re: [Done] 5.20B11: CreatePreferences() empty line
Posted: Wed Aug 21, 2013 11:33 am
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.
Re: [No, not done] 5.20B11: CreatePreferences() empty line
Posted: Wed Aug 21, 2013 11:59 am
by Fred
Moved to feature and request as it's not a bug.
Re: [Done] 5.20B11: CreatePreferences() empty line
Posted: Wed Aug 21, 2013 12:26 pm
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.
No hack needed.
You can start with my work for example:
http://forums.purebasic.com/german/view ... =8&t=12117
MFG PMV
Re: CreatePreferences() - remove BOM in Unicode mode
Posted: Wed Aug 21, 2013 1:31 pm
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?
Re: CreatePreferences() - remove BOM in Unicode mode
Posted: Wed Aug 21, 2013 4:23 pm
by Korolev Michael
Fred, I propose to make for CreatePreferences() an optional flag, something like #PB_Preference_FirstLineEmpty
Re: CreatePreferences() - remove BOM in Unicode mode
Posted: Thu Aug 22, 2013 11:49 am
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.

Re: CreatePreferences() - remove BOM in Unicode mode
Posted: Thu Aug 22, 2013 12:38 pm
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?
MFG PMV
Re: CreatePreferences() - remove BOM in Unicode mode
Posted: Thu Aug 22, 2013 3:53 pm
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.