mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-30 14:57:50 +00:00
Implement new string functions (#1655)
`STRFIND`, `STRRFIND`, `STRCHAR`, `STRSLICE`, `CHARCMP`, `CHARSIZE`, and `REVCHAR`
This commit is contained in:
34
test/asm/charlen-strchar.asm
Normal file
34
test/asm/charlen-strchar.asm
Normal file
@@ -0,0 +1,34 @@
|
||||
opt Wno-unmapped-char
|
||||
charmap "<NULL>", $00
|
||||
charmap "A", $10
|
||||
charmap "B", $20
|
||||
charmap "C", $30
|
||||
charmap "Bold", $88
|
||||
|
||||
SECTION "test", ROM0
|
||||
|
||||
DEF S EQUS "XBold<NULL>ABC"
|
||||
|
||||
assert CHARLEN("{S}") == 6
|
||||
println STRCHAR("{S}", 1)
|
||||
|
||||
assert !STRCMP(STRCHAR("{S}", 1), "Bold")
|
||||
assert STRCHAR("{S}", -5) == STRCHAR("{S}", CHARLEN("{S}") - 5)
|
||||
assert STRCHAR("{S}", 1) == "Bold" && "Bold" == $88
|
||||
assert STRCHAR("{S}", 0) == $58 ; ASCII "X"
|
||||
db "{S}"
|
||||
|
||||
for n, CHARLEN("{S}")
|
||||
assert STRCHAR("{S}", n) == CHARSUB("{S}", n + 1)
|
||||
assert STRCHAR("{S}", -n - 1) == CHARSUB("{S}", -n - 1)
|
||||
endr
|
||||
|
||||
newcharmap ascii
|
||||
|
||||
assert CHARLEN("{S}") == 14
|
||||
println STRCHAR("{S}", 1)
|
||||
assert !STRCMP(STRCHAR("{S}", 1), "B")
|
||||
assert STRCHAR("{S}", -5) == STRCHAR("{S}", CHARLEN("{S}") - 5)
|
||||
assert STRCHAR("{S}", 1) == "B" && "B" == $42 ; ASCII "B"
|
||||
assert STRCHAR("{S}", 0) == $58 ; ASCII "X"
|
||||
db "{S}"
|
||||
Reference in New Issue
Block a user