summaryrefslogtreecommitdiff
path: root/Com/Simatime/String.scm
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2019-11-23 15:59:08 -0800
committerBen Sima <ben@bsima.me>2019-11-23 15:59:08 -0800
commitcc64fa01e9bae297915906a03f85fe50be384990 (patch)
tree0edce8775852170464cad7408c3c81dec8ad9bf6 /Com/Simatime/String.scm
parentcb6147436f5cdc42622e849cfd6612261704b839 (diff)
Capitalize all Scheme and Haskell modules
Diffstat (limited to 'Com/Simatime/String.scm')
-rw-r--r--Com/Simatime/String.scm24
1 files changed, 24 insertions, 0 deletions
diff --git a/Com/Simatime/String.scm b/Com/Simatime/String.scm
new file mode 100644
index 0000000..770b04b
--- /dev/null
+++ b/Com/Simatime/String.scm
@@ -0,0 +1,24 @@
+(define-module (Com Simatime String)
+ #:export (replace to-string str capitalize))
+
+(define (replace s match repl)
+ (let ((f (lambda (a b)
+ (let ((next-char (if (eq? a match) repl a)))
+ (string-concatenate (list b (string next-char)))))))
+ (string-fold f "" s)))
+
+(define (to-string x)
+ (format #f "~a" x))
+
+(define str
+ (case-lambda
+ (() "")
+ ((x) (to-string x))
+ ((x . rest) (string-concatenate (map str (cons x rest))))))
+
+(define (capitalize s)
+ (let ((s (to-string s)))
+ (if (< (string-length s) 2)
+ (string-upcase s)
+ (str (string-upcase (substring s 0 1))
+ (substring s 1 )))))