Page 1 of 1

unicode string generator

Posted: Mon Oct 26, 2009 10:25 pm
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))

Re: unicode string generator

Posted: Tue Oct 27, 2009 8:28 am
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: