Print / PrintN with Flag #PB_Ascii / #PB_UTF8 / #PB_Unicode

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Print / PrintN with Flag #PB_Ascii / #PB_UTF8 / #PB_Unicode

Post by Josh »

sorry for my bad english
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Print / PrintN with Flag #PB_Ascii / #PB_UTF8 / #PB_Unic

Post by kenmo »

+1 This would be useful.

Here is a workaround :)

Code: Select all

Procedure _Print(Text.s, Format.i)
  If (Text)
    Protected Bytes.i, *Mem
    If (Format = #PB_Default)
      CompilerIf (#PB_Compiler_Unicode)
        Format = #PB_Unicode
      CompilerElse
        Format = #PB_Ascii
      CompilerEndIf
    EndIf
    Select (Format)
      Case #PB_Ascii
        Bytes = StringByteLength(Text, #PB_Ascii)
        *Mem = AllocateMemory(Bytes)
        If (*Mem)
          PokeS(*Mem, Text, -1, #PB_Ascii | #PB_String_NoZero)
        EndIf
      Case #PB_UTF8
        Bytes = StringByteLength(Text, #PB_UTF8)
        *Mem = AllocateMemory(Bytes)
        If (*Mem)
          PokeS(*Mem, Text, -1, #PB_UTF8 | #PB_String_NoZero)
        EndIf
      Case #PB_Unicode
        Bytes = StringByteLength(Text, #PB_Unicode)
        *Mem = AllocateMemory(Bytes)
        If (*Mem)
          PokeS(*Mem, Text, -1, #PB_Unicode | #PB_String_NoZero)
        EndIf
    EndSelect
    If (*Mem)
      WriteConsoleData(*Mem, Bytes)
      FreeMemory(*Mem)
    EndIf
  EndIf
EndProcedure

Macro Print(Text, Format = #PB_Default)
  _Print(Text, (Format))
EndMacro

Macro PrintN(Text, Format = #PB_Default)
  CompilerIf (#PB_Compiler_OS = #PB_OS_Windows)
    Print(Text + #CRLF$, (Format))
  CompilerElse
    Print(Text + #LF$, (Format))
  CompilerEndIf
EndMacro
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Print / PrintN with Flag #PB_Ascii / #PB_UTF8 / #PB_Unic

Post by ts-soft »

And a Flag for OEM: Print("blabla", #PB_OEMtoCHAR)
Print("blabla", #PB_CHARtoOEM)
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
fryquez
Enthusiast
Enthusiast
Posts: 367
Joined: Mon Dec 21, 2015 8:12 pm

Re: Print / PrintN with Flag #PB_Ascii / #PB_UTF8 / #PB_Unic

Post by fryquez »

Not only the Print() function, but all the Console related functions should get codepage options.

WriteProgramString
ConsoleError
ReadProgramError
...
Post Reply