aboutsummaryrefslogtreecommitdiffstats
path: root/lib/csc/strings.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-08-07 15:54:30 -0700
committerRose Hogenson <rhogenson@posteo.net>2022-08-07 15:54:30 -0700
commit49e0ce47d4fdd3f41dde1e376977d545fc8c542e (patch)
tree372a9c0fe4eb2049670c19da98d7643229f3bce3 /lib/csc/strings.csc
parent3f41d1ada092029d99aae980823eb6014a22a191 (diff)
downloadchromatopelma-49e0ce47d4fdd3f41dde1e376977d545fc8c542e.tar.zst
Define last-index.
Diffstat (limited to 'lib/csc/strings.csc')
-rw-r--r--lib/csc/strings.csc8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/csc/strings.csc b/lib/csc/strings.csc
index 255a2fd..373f9be 100644
--- a/lib/csc/strings.csc
+++ b/lib/csc/strings.csc
@@ -4,6 +4,7 @@
has-prefix?
index
join
+ last-index
split
str-quote)
(import (scheme base)
@@ -36,6 +37,13 @@
finally (return -1)))
+ (define (last-index s substr)
+ (loop for i downfrom (- (string-length s) (string-length substr)) to 0
+ if (has-prefix? (string-copy s i) substr)
+ return i
+ finally (return -1)))
+
+
(define (contains? s substr)
(if (string=? "" substr)
#t