ProgramParameter() and utf8

Everything else that doesn't fall into one of the other PB categories.
User avatar
Kukulkan
Addict
Addict
Posts: 1422
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

ProgramParameter() and utf8

Post by Kukulkan »

Hello,

I'm just wondering if older versions of PureBasic converted utf8 encoded commandline parameters to Unicode automatically? With PB5.21 I get the utf8 encoded string as unicode. This is ok so far and I can solve by using PeekS() and PokesS() but I think that older PB versions converted the utf8 parameter to unicode by themselves?

Any hints about this and how to deal with such commandline parameters?

Kukulkan
Fred
Administrator
Administrator
Posts: 18547
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: ProgramParameter() and utf8

Post by Fred »

IIRC, these commands never converted from utf8 to unicode automatically.
User avatar
Kukulkan
Addict
Addict
Posts: 1422
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: ProgramParameter() and utf8

Post by Kukulkan »

Ok, thanks Fred.

So I think UTF8 and manual conversion is the only way to securely submit commandline parameters to a PureBasic application if they contain unicode characters, right?

Kukulkan
Fred
Administrator
Administrator
Posts: 18547
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: ProgramParameter() and utf8

Post by Fred »

You mean on Linux or Windows ?
User avatar
Kukulkan
Addict
Addict
Posts: 1422
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: ProgramParameter() and utf8

Post by Kukulkan »

Both. My application gets compiled on Windows, Linux and MacOS. I like to have it the same behaviour on all platforms. I think utf8 is the best. Do you agree?

As I'm compiling in Unicode, I have to convert the utf8 parameters to Unicode in my code:

Code: Select all

Procedure.s ConvertUTF8toUnicode(utf8String.s)
  ; works only if compiled in unicode mode!
  Protected result.s = ""
  Protected *a = AllocateMemory(Len(utf8String.s)+1)
  ; poke it as ascii
  PokeS(*a, utf8String.s,-1,#PB_Ascii)
  ; peek it as utf8
  result.s = PeekS(*a, -1, #PB_UTF8)
  FreeMemory(*a)
  ProcedureReturn result.s
EndProcedure
Best

Kukulkan
Post Reply