Page 1 of 2

PB 6.10 b1 - OpenPreference()

Posted: Wed Dec 27, 2023 11:39 am
by User_Russian
Fred wrote: Fri Dec 22, 2023 6:14 pmAdded: 'Encoding' optional parameter to OpenPreference()
ini file (ascii encoding).

Code: Select all

Ключ = значение
Key = value
pb file

Code: Select all

Debug OpenPreferences("Test.txt", 0, #PB_Ascii)
Debug ReadPreferenceString("Ключ", "")
Debug ReadPreferenceString("Key", "")
Result of executing this code

Code: Select all

280

value
But the result must be

Code: Select all

280
значение
value
There is also no parameter in CreatePreferences() to save in the required encoding.

Re: PB 6.10 b1 - OpenPreference()

Posted: Wed Dec 27, 2023 12:06 pm
by juergenkulow

Code: Select all

Debug OpenPreferences("/tmp/test.pref", 0, #PB_UTF8)
Debug ReadPreferenceString("Ключ", "")
Debug ReadPreferenceString("Key", "")
; 21241184
; значение
; value

Re: PB 6.10 b1 - OpenPreference()

Posted: Wed Dec 27, 2023 12:28 pm
by User_Russian
Other applications can read/write to an ini file in ascii or UTF16 (UCS2) encoding.
What's the point of adding an encoding parameter that only supports UTF8?
Function OpenPreference() without this parameter supports UTF8.

Re: PB 6.10 b1 - OpenPreference()

Posted: Wed Dec 27, 2023 1:11 pm
by juergenkulow
My questions about ReadPreferenceString are:
What exactly are the Encoding parameter as of PB6.10?
How does the Linux version differ from the Windows version?

Re: PB 6.10 b1 - OpenPreference()

Posted: Wed Dec 27, 2023 1:39 pm
by Sicro
These strings "Ключ" and "значение" cannot be saved with the character encoding "ISO-8859-1", which PureBasic uses for "ASCII" as far as I know.

See also:

Code: Select all

If CreateFile(0, GetTemporaryDirectory() + "test.txt", #PB_Ascii)
  WriteStringN(0, "Ключ = значение" + #CRLF$ + "Key = value")
  CloseFile(0)
EndIf

If ReadFile(0, GetTemporaryDirectory() + "test.txt", #PB_Ascii)
  Debug ReadString(0, #PB_File_IgnoreEOL)
  CloseFile(0)
EndIf
Debug wrote: =
Key = value

Re: PB 6.10 b1 - OpenPreference()

Posted: Wed Dec 27, 2023 1:59 pm
by User_Russian
Ascii encoding corresponds to Windows localization.
In this case it is https://en.wikipedia.org/wiki/Windows-1251

Sicro, your code works correctly.

Code: Select all

Ключ = значение
Key = value
In PB 4.30 and previous versions, when selecting the ascii subsystem, preference lib works correctly with ascii ini files.
But after remains to unicode only (PB 4.40), ini files in ascii encoding are unreadable.

Re: PB 6.10 b1 - OpenPreference()

Posted: Wed Dec 27, 2023 2:15 pm
by AZJIO
Linux does not support cp1251 encoding natively. This is a Windows thing.

Re: PB 6.10 b1 - OpenPreference()

Posted: Tue Jan 16, 2024 8:35 am
by Fred
Ascii behaves the same way than before (ie: ini file without BOM). The new encoding parameter is only to allow to load ini whithout BOM in UTF-8 mode. Doc will be updated.

Re: PB 6.10 b1 - OpenPreference()

Posted: Tue Jan 16, 2024 10:35 am
by User_Russian
Fred wrote: Tue Jan 16, 2024 8:35 amThe new encoding parameter is only to allow to load ini whithout BOM in UTF-8 mode. Doc will be updated.
Other applications save data not only in UTF-8, but also in ASCII and UTF-16 encodings and in this case, the Preference library is useless, because it cannot read/save in encodings other than UTF-8.

Re: PB 6.10 b1 - OpenPreference()

Posted: Tue Jan 16, 2024 10:48 am
by Fred
Yes, it' not meant to be an universal library but tailored for PB apps.

Re: PB 6.10 b1 - OpenPreference()

Posted: Tue Jan 16, 2024 11:26 am
by User_Russian
But then why do we need flag #PB_Preference_NoBOM if function CreatePreferences() saves with BOM?
In any case, if this is a PB-only library, there is no need for #PB_Preference_NoBOM.

Re: PB 6.10 b1 - OpenPreference()

Posted: Tue Jan 16, 2024 2:09 pm
by AZJIO
User_Russian wrote: Tue Jan 16, 2024 11:26 am But then why do we need flag #PB_Preference_NoBOM if function CreatePreferences() saves with BOM?
In any case, if this is a PB-only library, there is no need for #PB_Preference_NoBOM.
https://www.purebasic.fr/english/viewtopic.php?p=577057

Re: PB 6.10 b1 - OpenPreference()

Posted: Tue Jan 16, 2024 3:21 pm
by User_Russian
AZJIO wrote: Tue Jan 16, 2024 2:09 pm
User_Russian wrote: Tue Jan 16, 2024 11:26 am But then why do we need flag #PB_Preference_NoBOM if function CreatePreferences() saves with BOM?
In any case, if this is a PB-only library, there is no need for #PB_Preference_NoBOM.
https://www.purebasic.fr/english/viewtopic.php?p=577057
Fred wrote that the Preference library is only for PB applications.
Fred wrote: Tue Jan 16, 2024 10:48 am Yes, it' not meant to be an universal library but tailored for PB apps.
Therefore it cannot be used for editing *.desktop in Linux. This may sound strange, but this is Fred's answer...

Re: PB 6.10 b1 - OpenPreference()

Posted: Tue Jan 16, 2024 3:56 pm
by AZJIO
It is not difficult to embed the flag

Code: Select all

If flag <> #PB_Preference_NoBOM
	WriteStringFormat(0, #PB_UTF8)
EndIf
And it will be supported on any OS.
The #PB_Ascii flag will require all "Windows code pages" to be embedded.
User_Russian wrote: Tue Jan 16, 2024 3:21 pm Therefore it cannot be used for editing *.desktop in Linux.
Let's consider this a random coincidence.

Re: PB 6.10 b1 - OpenPreference()

Posted: Tue Jan 16, 2024 4:22 pm
by User_Russian
AZJIO wrote: Tue Jan 16, 2024 3:56 pmThe #PB_Ascii flag will require all "Windows code pages" to be embedded.
File functions support required encodings (#PB_Ascii, #PB_UTF8 and #PB_Unicode).