Implement string-trim-X using string-trimmer.
authorChris Hanson <org/chris-hanson/cph>
Tue, 28 Feb 2017 06:20:05 +0000 (22:20 -0800)
committerChris Hanson <org/chris-hanson/cph>
Tue, 28 Feb 2017 06:20:05 +0000 (22:20 -0800)
src/runtime/runtime.pkg
src/runtime/string.scm
src/runtime/ustring.scm

index 3f100ce9ccfba54f4fcba2fc9c9785380ae83c79..b4c23e9557bc379bfe4290bd4ec00210fa258d93 100644 (file)
@@ -982,9 +982,6 @@ USA.
          string-search-all
          string-search-backward
          string-search-forward
-         string-trim
-         string-trim-left
-         string-trim-right
          substring-search-all
          substring-search-backward
          substring-search-forward
@@ -994,7 +991,7 @@ USA.
 (define-package (runtime ustring)
   (files "ustring")
   (parent (runtime))
-  (export ()                           ;export-deprecated
+  (export () deprecated:ustring
          (string-hash-mod string-hash)
          (substring->list string->list)
          (substring-move-left! substring-move!)
@@ -1009,6 +1006,9 @@ USA.
          string-find-previous-char-ci
          string-find-previous-char-in-set
          string-move!
+         string-trim
+         string-trim-left
+         string-trim-right
          substring-ci<?
          substring-ci=?
          substring-fill!
@@ -1082,6 +1082,7 @@ USA.
          string-suffix?
          string-tail
          string-titlecase
+         string-trimmer
          string-upcase
          string-upper-case?
          string<=?
index 350ec683d4e86dde8c7e05a2c82e51ad4fb2ee5e..e732548c4eea673b3ee48dfd61af3d4bd3cdb369 100644 (file)
@@ -72,41 +72,6 @@ USA.
                          ascii
                          (integer->char ascii))))
 \f
-;;;; Trim
-
-(define (string-trim-left string #!optional char-set)
-  (let ((index
-        (string-find-next-char-in-set string
-                                      (if (default-object? char-set)
-                                          char-set:not-whitespace
-                                          char-set))))
-    (if index
-       (substring string index (string-length string))
-       "")))
-
-(define (string-trim-right string #!optional char-set)
-  (let ((index
-        (string-find-previous-char-in-set string
-                                          (if (default-object? char-set)
-                                              char-set:not-whitespace
-                                              char-set))))
-    (if index
-       (substring string 0 (fix:+ index 1))
-       "")))
-
-(define (string-trim string #!optional char-set)
-  (let* ((char-set
-        (if (default-object? char-set)
-            char-set:not-whitespace
-            char-set))
-        (index (string-find-next-char-in-set string char-set)))
-    (if index
-       (substring string
-                  index
-                  (fix:+ (string-find-previous-char-in-set string char-set)
-                         1))
-       "")))
-
 ;;;; Pad
 
 (define (string-pad-right string n #!optional char)
index 4a5ebed926b7be73efdb0992b718981187a750c6..fc4198a5d1d0d915aac749dab68fad961a58c7c3 100644 (file)
@@ -1358,4 +1358,18 @@ USA.
             (legacy-string-allocate 1)
             (full-string-allocate 1))))
     (string-set! s 0 char)
-    s))
\ No newline at end of file
+    s))
+
+(define (legacy-string-trimmer where)
+  (lambda (string #!optional char-set)
+    ((string-trimmer 'where where
+                    'trim-char?
+                    (char-set-predicate
+                     (if (default-object? char-set)
+                         char-set:whitespace
+                         (char-set-invert char-set))))
+     string)))
+
+(define string-trim-left (legacy-string-trimmer 'leading))
+(define string-trim-right (legacy-string-trimmer 'trailing))
+(define string-trim (legacy-string-trimmer 'both))
\ No newline at end of file