added string.lowerchar() and string.upperchar()

This commit is contained in:
Irmen de Jong 2022-09-25 20:20:38 +02:00
parent 1d65d63bd9
commit 387a4b7c35
3 changed files with 41 additions and 0 deletions

View File

@ -224,6 +224,29 @@ _done rts
}}
}
asmsub lowerchar(ubyte char @A) -> ubyte @A {
%asm {{
and #$7f
cmp #97
bcc +
cmp #123
bcs +
and #%11011111
+ rts
}}
}
asmsub upperchar(ubyte char @A) -> ubyte @A {
%asm {{
cmp #65
bcc +
cmp #91
bcs +
ora #%00100000
+ rts
}}
}
sub startswith(str st, str prefix) -> bool {
ubyte prefix_len = length(prefix)
ubyte str_len = length(st)

View File

@ -114,6 +114,18 @@ string {
}
}
sub lowerchar(ubyte char) -> ubyte {
if char >= 'A' and char <= 'Z'
char |= %00100000
return char
}
sub upperchar(ubyte char) -> ubyte {
if char >= 'a' and char <= 'z'
char &= %11011111
return char
}
sub startswith(str st, str prefix) -> bool {
ubyte prefix_len = length(prefix)
ubyte str_len = length(st)

View File

@ -191,6 +191,12 @@ Provides string manipulation routines.
``upper(string)``
Uppercases the petscii-string in place.
``lowerchar(char)``
Returns lowercased character.
``upperchar(char)``
Returns uppercased character.
``startswith(string, prefix) -> bool``
Returns true if string starts with prefix, otherwise false