diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-01-11 22:01:23 -0800 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-01-11 22:01:23 -0800 |
| commit | 68986fe0410584c6934c835bb0ee784655f5f8c5 (patch) | |
| tree | d51bc2f3e09df35ef81b7a0c462ff555b4344701 /csc/strings.csc | |
| parent | 4fc8b3c1c9dc4aa730e471708dcab7aed68f5a4b (diff) | |
| download | chromatopelma-68986fe0410584c6934c835bb0ee784655f5f8c5.tar.zst | |
Move scheme compiler into a separate directory.
Diffstat (limited to 'csc/strings.csc')
| -rw-r--r-- | csc/strings.csc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/csc/strings.csc b/csc/strings.csc new file mode 100644 index 0000000..737c91b --- /dev/null +++ b/csc/strings.csc @@ -0,0 +1,46 @@ +(define-library (csc strings) + (export + find + join + not-found-error? + prefix? + str-quote) + (import (scheme base) + (only (scheme case-lambda) case-lambda) + (only (scheme write) write) + (only (csc list) intercalate)) + (begin + + + (define prefix? + (case-lambda + ((prefix str) (prefix? prefix str 0)) + ((prefix str start) + (and (<= (string-length prefix) (- (string-length str) start)) + (string=? prefix (substring str start (+ start (string-length prefix)))))))) + + + (define (str-quote s) + (let ((out (open-output-string))) + (write s out) + (get-output-string out))) + + + (define-record-type <not-found-error> + (make-not-found-error) + not-found-error?) + + + (define find + (case-lambda + ((match str) (find match str 0 (string-length str))) + ((match str start) (find match str start (string-length str))) + ((match str start end) + (let loop ((i start)) + (cond ((>= i end) (raise (make-not-found-error))) + ((prefix? match str i) i) + (else (loop (+ 1 i)))))))) + + + (define (join sep . strings) + (apply string-append (intercalate sep strings))))) |
