STRSUB and CHARSUB allow zero or negative positions

These are offsets from the end of the string, as if the
STRLEN or CHARLEN respectively were added to the position.

Fixes #812
This commit is contained in:
Rangi
2021-04-18 21:40:38 -04:00
committed by Eldred Habert
parent 459773b3f0
commit b1e6c73197
6 changed files with 35 additions and 23 deletions

View File

@@ -11,6 +11,7 @@ S EQUS "XBold<NULL>ABC"
assert CHARLEN("{S}") == 6
println CHARSUB("{S}", 2)
assert !STRCMP(CHARSUB("{S}", 2), "Bold")
assert CHARSUB("{S}", -4) == CHARSUB("{S}", CHARLEN("{S}") - 4)
assert CHARSUB("{S}", 2) == "Bold" && "Bold" == $88
assert CHARSUB("{S}", 1) == $58 ; ASCII "X"
db "{S}"
@@ -20,6 +21,7 @@ S EQUS "XBold<NULL>ABC"
assert CHARLEN("{S}") == 14
println CHARSUB("{S}", 2)
assert !STRCMP(CHARSUB("{S}", 2), "B")
assert CHARSUB("{S}", -4) == CHARSUB("{S}", CHARLEN("{S}") - 4)
assert CHARSUB("{S}", 2) == "B" && "B" == $42 ; ASCII "B"
assert CHARSUB("{S}", 1) == $58 ; ASCII "X"
db "{S}"