fix: 100-sed-fooRbar.

This commit is contained in:
Jan Nieuwenhuizen 2018-12-02 07:35:50 +01:00
parent 9115b9fbb6
commit 632295fa18
3 changed files with 13 additions and 7 deletions

View File

@ -29,6 +29,7 @@
#:use-module (gash config)
#:use-module (gash guix-utils)
#:use-module (gash shell-utils)
#:use-module (gash util)
#:export (
sed
@ -114,6 +115,9 @@ Usage: sed [OPTION]... [SCRIPT] [FILE]...
(cond ((string-prefix? "s" o)
(let* ((command (substring o 1))
(string (substring command 1))
(string (string-replace-string string "\\n" "\n"))
(string (string-replace-string string "\\r" "\r"))
(string (string-replace-string string "\\t" "\t"))
(separator (string-ref command 0)))
(receive (search replace modifier-string)
(apply values (string-split string separator))

View File

@ -24,17 +24,11 @@
#:use-module (ice-9 getopt-long)
#:use-module (ice-9 rdelim)
#:use-module (gash config)
#:use-module (gash util)
#:export (
tr
))
(define (string-replace-string string from to)
(cond ((string-contains string from)
=>
(lambda (i)
(string-replace string to i (+ i (string-length from)))))
(else string)))
(define (tr . args)
(let* ((option-spec
'((delete (single-char #\d))

View File

@ -27,6 +27,7 @@
wrap-command
char->string
string->string-list
string-replace-string
))
(define (disjoin . predicates)
@ -42,3 +43,10 @@
(define (char->string c)
(make-string 1 c))
(define (string-replace-string string from to)
(cond ((string-contains string from)
=>
(lambda (i)
(string-replace string to i (+ i (string-length from)))))
(else string)))