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
(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!)
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!
string-suffix?
string-tail
string-titlecase
+ string-trimmer
string-upcase
string-upper-case?
string<=?
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)
(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