1. I think you're overlooking something...
Your example code will never work in ASCII mode, because of this part:
How can you store characters outside the ASCII range in an ASCII string??? I think PB will produce "?" when this runs in ASCII mode.
2.
If I compile in Unicode, then I have much more problems at other places, e.g. with the pipe to another app.
If you want to support Unicode text, I really really really recommend you use Unicode mode and work on other problems like piping, instead of using ASCII mode...
Unicode characters and UTF-8 text are very difficult to handle in ASCII mode, because strings will only handle characters 0-255 !!
3. If you need them...
Code: Select all
Procedure.i UTF8(String$)
Protected Bytes.i = 1 + StringByteLength(String$, #PB_UTF8)
Protected *Mem = AllocateMemory(Bytes)
If (*Mem)
PokeS(*Mem, String$, -1, #PB_UTF8)
EndIf
ProcedureReturn (*Mem)
EndProcedure
Procedure.i Ascii(String$)
Protected Bytes.i = 1 + StringByteLength(String$, #PB_Ascii)
Protected *Mem = AllocateMemory(Bytes)
If (*Mem)
PokeS(*Mem, String$, -1, #PB_Ascii)
EndIf
ProcedureReturn (*Mem)
EndProcedure