added string.isdigit, islower, isupper, isletter

This commit is contained in:
Irmen de Jong 2023-12-05 22:50:20 +01:00
parent f998888d6d
commit afbc91d1fc
3 changed files with 71 additions and 1 deletions

View File

@ -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
}}
}
}

View File

@ -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)
}
}

View File

@ -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