(1) Would I be correct in saying that #PB_Unicode is necessary if I want to use the below search by using CompareMemory? I got some odd results if the memory contained #PB_UTF8 data, as I think characters under UTF8 are of variable length. The key question perhaps — (2) unless one needs to write data to a file for reading by another application that needs UTF8, is #PB_Unicode generally the best choice internally in PB? Thanks
Code: Select all
; **
; ** Search *Buffer for *SearchBuf, beginning at StartPos.i, ending at EndPos.i
; **
Procedure.i Search_Receive(StartPos.i, EndPos.i, *Buffer, *SearchBuf, SearchLen.i)
Protected ChrPos.i, FoundPos.i
EndPos.i - SearchLen.i + 1 ; Don't need to search beyond frame end - search length
For ChrPos.i = StartPos.i To EndPos.i Step 2 ; Search from specf'd position in the buffer onwards
If CompareMemory(*Buffer + ChrPos.i - 1, *SearchBuf, SearchLen.i) ; Compare next 'n' bytes with the full search string
FoundPos.i = ChrPos.i ; Indicate we found the match at this char. position
Break ; Don't continue, as we've found the match
EndIf
Next
ProcedureReturn FoundPos.i ; Return the found character position (or 0 if not)
EndProcedure