Page 1 of 1

Forced Preferences utf8 BOM

Posted: Wed Nov 19, 2025 9:38 am
by Sergey
Hi,
when I want to change value my ini file becomes with BOM+CRLF (5 bytes: EF BB BF 0D 0A) again :|

Code: Select all

#test_filename = "test_file.ini"

If CreatePreferences(#test_filename, #PB_Preference_NoBOM)
	PreferenceGroup("main")
	WritePreferenceString("key", "value1")
	ClosePreferences()
EndIf

MessageRequester("", "File created, size: " + Str(FileSize(#test_filename))); 22 bytes

If OpenPreferences(#test_filename)
	PreferenceGroup("main")
	WritePreferenceString("key", "value2")
	ClosePreferences()
EndIf

MessageRequester("", "File size: " + Str(FileSize(#test_filename))); 27 bytes[/code]

Re: Forced Preferences utf8 BOM

Posted: Wed Nov 19, 2025 11:46 am
by Axolotl
Yeah, good observation.
I am pretty sure that this is not a bug, its a feature.

And this has been discussed several times. Ultimately, it's a design decision made by FRED.
And don't forget that prefs is (precisely) not ini. It just happens to use the same format.

BTW: I would still think it would be good if that were changed (at some point)...... especially the CRLF at the end. :)

Important Note: Don't scold me, I'm just repeating what I learned here.

Re: Forced Preferences utf8 BOM

Posted: Wed Nov 19, 2025 12:07 pm
by Sergey
Axolotl wrote: Wed Nov 19, 2025 11:46 am ... especially the CRLF at the end. :)
Thank Axolotl for answer
I agree with you to remove CRLF

I think that the meaning of #PB_Preference_NoBOM in CreatePreferences is lost if it appears independently
You need to check OpenPreferences for the presence of BOM and if it was present write it or not write it if it was not there

Re: Forced Preferences utf8 BOM

Posted: Wed Nov 19, 2025 2:46 pm
by kenmo
Not sure if this is a "bug" or a "feature request" but I agree, OpenPreferences should preserve whether there's a BOM, or else maybe allow the NoBOM flag like CreatePreferences().

In the meantime a procedure can be used to remove it. Read file to buffer, check for BOM + CRLF, if found write the file contents back minus those initial bytes.