unicode string generator

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

unicode string generator

Post by eddy »

Some functions for your UNICODE executable :
  • Unicode chr
  • Char list generator
I used these functions for my bitmap font generator.

Code: Select all

;PB 4.4+
;// you must enable the following option : Create UNICODE executable
CompilerIf #PB_Compiler_Unicode
   Procedure.s UnicodeCharList(first.U, last.U)
      If first>=0 And first<=last
         Protected len.i=last-first+1
         Protected charlist.s=Space(len)
         Protected i.i
         For i=0 To len-1
            PokeU(@charlist+i*SizeOf(Character), first+i)
         Next
         
         ProcedureReturn charlist
      EndIf
   EndProcedure
   
   Procedure.s UChr(code.U)
      If code>=0 And code<65536
         Protected unicodeChar.s=" "
         PokeU(@unicodeChar, code)
         
         ProcedureReturn unicodeChar
      EndIf 
   EndProcedure
CompilerElse
   MessageRequester("Warning", "You didn't compile an UNICODE executable!", #PB_MessageRequester_Ok)
   End 
CompilerEndIf

MessageRequester("UNICODE STRING GENERATOR    "+UChr(200), UnicodeCharList(31, 1024))
Last edited by eddy on Thu Oct 29, 2009 2:08 am, edited 1 time in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: unicode string generator

Post by Demivec »

Line 5 should be changed from:

Code: Select all

If first>=0 And first<last
to:

Code: Select all

If first>=0 And first<=last
to handle the case when first = last for a very small character list. :wink:
Post Reply