diff --git a/compiler/res/prog8lib/string.p8 b/compiler/res/prog8lib/string.p8 index 9e673d645..07575d440 100644 --- a/compiler/res/prog8lib/string.p8 +++ b/compiler/res/prog8lib/string.p8 @@ -383,4 +383,55 @@ fail clc ; yes, no match found, return with c=0 rts }} } + + asmsub isdigit(ubyte character @A) -> bool @Pc { + %asm {{ + cmp #'0' + bcs + + rts ++ cmp #'9'+1 + bcc + + clc + rts ++ sec + rts + }} + } + + asmsub isupper(ubyte character @A) -> bool @Pc { + %asm {{ + cmp #'A' + bcs + + rts ++ cmp #'Z'+1 + bcc + + clc + rts ++ sec + rts + }} + } + + asmsub islower(ubyte character @A) -> bool @Pc { + %asm {{ + cmp #'a' + bcs + + rts ++ cmp #'z'+1 + bcc + + clc + rts ++ sec + rts + }} + } + + asmsub isletter(ubyte character @A) -> bool @Pc { + %asm {{ + jsr islower + bcs + + jmp isupper ++ rts + }} + } } diff --git a/compiler/res/prog8lib/virtual/string.p8 b/compiler/res/prog8lib/virtual/string.p8 index 6284cb780..d01155434 100644 --- a/compiler/res/prog8lib/virtual/string.p8 +++ b/compiler/res/prog8lib/virtual/string.p8 @@ -174,4 +174,20 @@ string { return hashcode } } -} + + sub isdigit(ubyte character) -> bool { + return character>='0' and character<='9' + } + + sub isupper(ubyte character) -> bool { + return character>='A' and character<='Z' + } + + sub islower(ubyte character) -> bool { + return character>='a' and character<='z' + } + + sub isletter(ubyte character) -> bool { + return islower(character) or isupper(character) + } + } diff --git a/docs/source/libraries.rst b/docs/source/libraries.rst index 5fec5672d..7b7ba7c8c 100644 --- a/docs/source/libraries.rst +++ b/docs/source/libraries.rst @@ -266,6 +266,9 @@ Provides string manipulation routines. ``upperchar (char)`` Returns uppercased character. +``isdigit (char)``, ``islower (char)``, ``isupper (char)``, ``isletter (char)`` + Returns boolean if the character is a numerical digit 0-0, lowercase letter, uppercase letter, or any letter. + ``startswith (string, prefix) -> bool`` Returns true if string starts with prefix, otherwise false