diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-08-01 19:35:19 -0700 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-08-01 19:35:19 -0700 |
| commit | acc561366f3fe6ec0377103f52ef0f7e923711c9 (patch) | |
| tree | d7a19cfbad78a69ebea71b27302e708c0655863d /csc/strings.csc | |
| parent | 99ce19a8053a93457885f32ec54c1c5b7c1961c1 (diff) | |
| download | chromatopelma-acc561366f3fe6ec0377103f52ef0f7e923711c9.tar.zst | |
Modify the project structure.
Now the lib directory contains what will eventually end up on the
user's /usr/lib/csc. When I write make install, it will copy all of
the .csc files from lib into the destination lib directory. This means I
can start working on the standard library in lib/scheme.
Diffstat (limited to 'csc/strings.csc')
| -rw-r--r-- | csc/strings.csc | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/csc/strings.csc b/csc/strings.csc deleted file mode 100644 index 255a2fd..0000000 --- a/csc/strings.csc +++ /dev/null @@ -1,64 +0,0 @@ -(define-library (csc strings) - (export - contains? - has-prefix? - index - join - split - str-quote) - (import (scheme base) - (only (scheme case-lambda) case-lambda) - (only (scheme write) write) - (only (csc list) intercalate) - (only (csc loop) - loop - return)) - (begin - - - (define (has-prefix? str prefix) - (and (<= (string-length prefix) (string-length str)) - (string=? prefix (substring str 0 (string-length prefix))))) - - - (define (str-quote s) - (let ((out (open-output-string))) - (write s out) - (get-output-string out))) - - - (define (index s substr) - (loop for i from 0 - for s = s then (string-copy s 1) - until (string=? "" s) - if (has-prefix? s substr) - return i - finally (return -1))) - - - (define (contains? s substr) - (if (string=? "" substr) - #t - (not (negative? (index s substr))))) - - - (define (join sep strings) - (apply string-append (intercalate sep strings))) - - - (define split - (case-lambda - ((s sep n) - (if (= 0 n) - '() - (loop for n = n then (- n 1) - for s = s then (string-copy s (+ i (string-length sep))) - for i = (let ((i (index s sep))) - (if (or (negative? i) - (= 1 n)) - (string-length s) - i)) - collect (substring s 0 i) - while (< i (string-length s))))) - ((s sep) - (split s sep -1)))))) |
