string-match-forward-ci
string-pad-left
string-pad-right
- string-replace
string-search-all
string-search-backward
string-search-forward
substring-match-backward-ci
substring-match-forward
substring-match-forward-ci
- substring-replace
substring-search-all
substring-search-backward
substring-search-forward
string-prefix-ci?
string-prefix?
string-ref
+ string-replace
string-set!
string-slice
string-splitter
(string-set! result j (string-ref string i)))
result)))
\f
-;;;; Replace
-
-(define (string-replace string char1 char2)
- (guarantee-string string 'STRING-REPLACE)
- (guarantee-char char1 'STRING-REPLACE)
- (guarantee-char char2 'STRING-REPLACE)
- (let ((string (string-copy string)))
- (%substring-replace! string 0 (string-length string) char1 char2)
- string))
-
-(define (substring-replace string start end char1 char2)
- (guarantee-substring string start end 'SUBSTRING-REPLACE)
- (guarantee-char char1 'SUBSTRING-REPLACE)
- (guarantee-char char2 'SUBSTRING-REPLACE)
- (let ((string (string-copy string)))
- (%substring-replace! string start end char1 char2)
- string))
-
-(define (%substring-replace! string start end char1 char2)
- (let loop ((start start))
- (let ((index (substring-find-next-char string start end char1)))
- (if index
- (begin
- (string-set! string index char2)
- (loop (fix:+ index 1)))))))
-\f
;;;; Compare
(define (string-compare string1 string2 if= if< if>)
(define (burst-string string delimiter allow-runs?)
((string-splitter delimiter allow-runs?) string))
+
+(define (string-replace string char1 char2)
+ (guarantee bitless-char? char1 'string-replace)
+ (guarantee bitless-char? char2 'string-replace)
+ (string-map (lambda (char)
+ (if (char=? char char1) char2 char))
+ string))
\f
(define (string-8-bit? string)
(receive (string start end) (translate-slice string 0 (string-length string))