String Characters & PB_COMPILER_UNICODE (Ascii/Unicode)
Posted: Wed Sep 27, 2006 9:07 pm
Code updated For 5.20+
Here's something that I just recently noticed and started using. Probably obvious to other people but... well... I'm slow.
Anyway, in the past if I was writing a routine to scan through a string and needed it to be compatible with ascii and unicode, I'd do some compiler-if statements for incrementing the string pointer, getting the character index, etc...
However, you can use bit-shifting to be more lazy
Like that. Try it under both unicode & non-unicode to see what I mean.
..: Edit :.. Fixed a misplaced addition
Here's something that I just recently noticed and started using. Probably obvious to other people but... well... I'm slow.
Anyway, in the past if I was writing a routine to scan through a string and needed it to be compatible with ascii and unicode, I'd do some compiler-if statements for incrementing the string pointer, getting the character index, etc...
However, you can use bit-shifting to be more lazy

Code: Select all
Structure CHAR
c.c
EndStructure
;-
Procedure.l FindDash(Text.s)
;
Define.l HoldIndex
;
Define.CHAR *HoldChar = @Text
;
While *HoldChar\c <> '-' And *HoldChar\c
;
*HoldChar + (1 << #PB_COMPILER_UNICODE)
;
Wend
;
HoldIndex = ((*HoldChar - @Text) >> #PB_COMPILER_UNICODE) + 1
;
ProcedureReturn HoldIndex
;
EndProcedure
;-
Debug FindDash("Please - test this string.")
;-
End
;-
..: Edit :.. Fixed a misplaced addition
