add string.isspace and string.isprint

This commit is contained in:
Irmen de Jong 2023-12-13 00:28:34 +01:00
parent 08a079a96e
commit 796add0ee2
4 changed files with 63 additions and 6 deletions

View File

@ -384,7 +384,7 @@ fail clc ; yes, no match found, return with c=0
}}
}
asmsub isdigit(ubyte character @A) -> bool @Pc {
asmsub isdigit(ubyte petsciichar @A) -> bool @Pc {
%asm {{
cmp #'0'
bcs +
@ -398,7 +398,7 @@ fail clc ; yes, no match found, return with c=0
}}
}
asmsub isupper(ubyte character @A) -> bool @Pc {
asmsub isupper(ubyte petsciichar @A) -> bool @Pc {
; shifted petscii has 2 ranges that contain the upper case letters...
%asm {{
cmp #97
@ -418,7 +418,7 @@ _yes sec
}}
}
asmsub islower(ubyte character @A) -> bool @Pc {
asmsub islower(ubyte petsciichar @A) -> bool @Pc {
%asm {{
cmp #'a'
bcs +
@ -432,7 +432,7 @@ _yes sec
}}
}
asmsub isletter(ubyte character @A) -> bool @Pc {
asmsub isletter(ubyte petsciichar @A) -> bool @Pc {
%asm {{
jsr islower
bcs +
@ -440,4 +440,42 @@ _yes sec
+ rts
}}
}
asmsub isspace(ubyte petsciichar @A) -> bool @Pc {
%asm {{
cmp #32
beq +
cmp #13
beq +
cmp #9
beq +
cmp #10
beq +
cmp #141
beq +
cmp #160
beq +
clc
rts
+ sec
rts
}}
}
asmsub isprint(ubyte petsciichar @A) -> bool @Pc {
%asm {{
cmp #160
bcc +
rts
+ cmp #32
bcs +
rts
+ cmp #128
bcc +
clc
rts
+ sec
rts
}}
}
}

View File

@ -190,4 +190,12 @@ string {
sub isletter(ubyte character) -> bool {
return islower(character) or isupper(character)
}
}
sub isspace(ubyte character) -> bool {
return character in [32, 13, 9, 10, 141, 160]
}
sub isprint(ubyte character) -> bool {
return character>=32 and character<=127 or character>=160
}
}

View File

@ -275,7 +275,13 @@ Provides string manipulation routines.
Returns boolean if the character is a numerical digit 0-9
``islower (char)``, ``isupper (char)``, ``isletter (char)``
Returns boolean if the character is a shifted-PETSCII lowercase letter, uppercase letter, or any letter.
Returns true if the character is a shifted-PETSCII lowercase letter, uppercase letter, or any letter, respectively.
``isspace (char)``
Returns true if the PETSCII character is a whitespace (tab, space, return, and shifted versions)
``isprint (char)``
Returns true if the PETSCII character is a "printable" character (space or any visible symbol)
``startswith (string, prefix) -> bool``
Returns true if string starts with prefix, otherwise false

View File

@ -2,6 +2,11 @@
TODO
====
- optimize if-else expressions whose condition returns the boolean status in a status register to use a branch opcode instead of a comparison against 0
- fix "can't use Z or N flags as return 'values'" in 6502 codegen?
- merge branch optimize-st for some optimizations regardign SymbolTable use
- [on branch: call-pointers] allow calling a subroutine via a pointer variable (indirect JSR, optimized form of callfar())
modify programs (shell, paint) that now use callfar