WritePreferenceString with leading spaces

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

WritePreferenceString with leading spaces

Post by Michael Vogel »

Hi,
just wondered that WritePreferenceString does not use doublequotes at the beginning and end of the string?!

ReadPreferenceString() works fine with values like...

Code: Select all

value = " test "
...but when rewriting this back to a preference file, it is seen as...

Code: Select all

value =  test 
So the next time it will be only "test" without the spaces...

Is this like it should work? Do I have to add the doublequotes by myself or could this be a problem (with future versions)?

Code: Select all

If Trim(Text)<>Text
	Text=#DOUBLEQUOTE$+Text+#DOUBLEQUOTE$
EndIf
WritePreferenceString(Name,Text)
Michael
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Post by Kukulkan »

Hi Michael,

I suggest you to store such values in base64 encoded format (now usable in unicode executables, too ;-) )

Code: Select all

; encodes a string to Base64 encoding 
Procedure.s b64encode(Original.s) 
  If Original.s = "": ProcedureReturn "": EndIf 
  Result.s = Space(StringByteLength(Original.s) * 1.36) 
  length.l = Base64Encoder(@Original.s, StringByteLength(Original.s), @Result.s, Len(Result.s)) 
  ProcedureReturn Left(Result.s, length.l) 
EndProcedure 

; decodes a Base64 encoded string 
Procedure.s b64decode(Encoded.s) 
  If Encoded.s = "": ProcedureReturn "": EndIf 
  Result.s = Space(StringByteLength(Encoded.s)) 
  length.l = Base64Decoder(@Encoded.s, StringByteLength(Encoded.s), @Result.s, Len(Result.s)) 
  ProcedureReturn Left(Result.s, length.l) 
EndProcedure

Debug Chr(34)+b64decode(b64encode("This is a test string"))+Chr(34)
Kukulkan
Last edited by Kukulkan on Mon Sep 15, 2008 3:13 pm, edited 2 times in total.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Kukulan, funzt nicht richtig!
You must correct your procedure, I've just tested it for validity.

Code: Select all

; encodes a string to Base64 encoding 
Procedure.s b64encode(Original.s) 
  If Original.s = "": ProcedureReturn "": EndIf 
  Result.s = Space(Len(Original.s) * 1.36) 
  length.l = Base64Encoder(@Original.s, Len(Original.s), @Result.s, Len(Result.s)) 
  ProcedureReturn Left(Result.s, length.l) 
EndProcedure 

; decodes a Base64 encoded string 
Procedure.s b64decode(Encoded.s) 
  If Encoded.s = "": ProcedureReturn "": EndIf 
  Result.s = Space(Len(Encoded.s)) 
  length.l = Base64Decoder(@Encoded.s, Len(Encoded.s), @Result.s, Len(Result.s)) 
  ProcedureReturn Left(Result.s, length.l) 
EndProcedure 


Debug Chr(34)+b64decode(b64encode("Aha-Erlebnis!"))+Chr(34)
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Post by Kukulkan »

Hi And51,

Thank you. You are right if you say that the code did not work in unicode-executables. I corrected this in the code postet above. Now the code works in both variations (ascii and unicode).

Kukulkan
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Ouuups! :oops:

I didn't say the word "unicode", actually... Somehow I forgot it. I have uicode activated by default so I didn't thought this is the actueal reason.
Eigentlich, it was your own idea. :lol:
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

> Eigentlich
is german, i think "in fact" is the right vocable
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

@ TS-Soft
:wink: In fact, I know...
:wink: :wink: And in fact, you can also use "actually" for "eigentlich"; it's the same.
:wink: :wink: :wink: It's only a little joke.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Post by Kukulkan »

Hi,

In my opinion, Eigentlich is best translated with in fact.

Kukulkan
Post Reply