These don't depend on any PB functions.
Code: Select all
;DisableDebugger
Structure CharArray
c.c[0]
EndStructure
Procedure IsHexStrPtr(*string.CharArray, *ignore.CharArray = 0)
Protected i, idx, x, res
If *string
IsHexStrPtr_Loop:
x = *string\c[i]
i + 1
If x = 0 : Goto IsHexStrPtr_Exit : EndIf ;if null character then exit.
If *ignore ;skip over some characters.(case sensitive)
idx = 0
While *ignore\c[idx]
If x = *ignore\c[idx] : Goto IsHexStrPtr_Loop : EndIf
idx + 1
Wend
EndIf
res = 1
If x < '0' : Goto IsHexStrPtr_NotHex : EndIf
If x <= '9' : Goto IsHexStrPtr_Loop : EndIf
x | $20 ;into lowercase character.
If x < 'a' : Goto IsHexStrPtr_NotHex : EndIf
If x <= 'f' : Goto IsHexStrPtr_Loop : EndIf
IsHexStrPtr_NotHex:
res = 0
IsHexStrPtr_Exit:
EndIf
ProcedureReturn res
EndProcedure
Procedure IsHexStr(string.s, ignore.s = "")
Protected i, idx, x, res
Protected *str.CharArray = @string, *ignore.CharArray = @ignore
If string
IsHexStr_Loop:
x = *str\c[i]
i + 1
If x = 0 : Goto IsHexStr_Exit : EndIf ;if null character then exit.
If *ignore ;skip over some characters.(case sensitive)
idx = 0
While *ignore\c[idx]
If x = *ignore\c[idx] : Goto IsHexStr_Loop : EndIf
idx + 1
Wend
EndIf
res = 1
If x < '0' : Goto IsHexStr_NotHex : EndIf
If x <= '9' : Goto IsHexStr_Loop : EndIf
x | $20 ;into lowercase character.
If x < 'a' : Goto IsHexStr_NotHex : EndIf
If x <= 'f' : Goto IsHexStr_Loop : EndIf
IsHexStr_NotHex:
res = 0
IsHexStr_Exit:
EndIf
ProcedureReturn res
EndProcedure
;test.
Debug IsHexStrPtr(0, 0) ;0
Debug IsHexStrPtr(0) ;0
Debug IsHexStrPtr(@"", @"") ;0
Debug IsHexStrPtr(@"", @" ") ;0
Debug IsHexStrPtr(@"") ;0
Debug IsHexStrPtr(@" z", @" ") ;0
Debug IsHexStrPtr(@" ", @" ") ;0
Debug IsHexStrPtr(@" ") ;0
Debug " "
Debug IsHexStrPtr(@"a d 1 9 84fdc1", @" ") ;1
Debug IsHexStrPtr(@"a0 ad fe 99 84", @" ") ;1
Debug IsHexStrPtr(@"a0 ad fe 99 84") ;0
Debug IsHexStrPtr(@"0123456789abcdefABCDEF", @"") ;1
Debug IsHexStrPtr(@"0123456789abcdefABCDEF") ;1
Debug IsHexStrPtr(@"0123456789abcdefABCDEFg", @"") ;0
Debug IsHexStrPtr(@"0123456789abcdefABCDEFg") ;0
Debug IsHexStrPtr(@"0 ", @" ") ;1
Debug IsHexStrPtr(@"0 g", @" ") ;0
Debug IsHexStrPtr(@"0 aaG", @" g") ;0
Debug " "
Debug IsHexStr("", "") ;0
Debug IsHexStr("", " ") ;0
Debug IsHexStr("") ;0
Debug IsHexStr(" z", " ") ;0
Debug IsHexStr(" ", " ") ;0
Debug IsHexStr(" ") ;0
Debug " "
Debug IsHexStr("a d 1 9 84fdc1", " ") ;1
Debug IsHexStr("a0 ad fe 99 84", " ") ;1
Debug IsHexStr("a0 ad fe 99 84") ;0
Debug IsHexStr("0123456789abcdefABCDEF", "") ;1
Debug IsHexStr("0123456789abcdefABCDEF") ;1
Debug IsHexStr("0123456789abcdefABCDEFg", "") ;0
Debug IsHexStr("0123456789abcdefABCDEFg") ;0
Debug IsHexStr("0 ", " ") ;1
Debug IsHexStr("0 g", " ") ;0
Debug IsHexStr("0 aaG", " g") ;0