diff options
-rw-r--r-- | bs/re.scm | 23 | ||||
-rw-r--r-- | bs/string.scm | 10 |
2 files changed, 16 insertions, 17 deletions
@@ -27,30 +27,29 @@ ;; (define M regexp/newline) ;; (define MULTILINE regexp/newline) - ;; Compile `pattern` into a regular expression object. (define (compile pattern . flags) + "Compile `pattern` into a regular expression object." (apply make-regexp (cons pattern flags))) - ;; If zero or more characters at the beginning of `string` match the - ;; regular expression `pattern`, return a corresponding match object. + (define (match string pattern) + "If zero or more characters at the beginning of `string` match the regular +expression `pattern`, return a corresponding match object." (regexp-exec pattern string)) - ;; (define (group match-obj n) (if match-obj (match:substring match-obj n) #f)) - ;; Return the string obtained by replacing the leftmost - ;; non-overlapping occurrences of `pattern` in `string` by the - ;; replacement `repl`. If the pattern isn’t found, string is returned - ;; unchanged. (define (sub string pattern repl) + "Return the string obtained by replacing the leftmost non-overlapping +occurrences of `pattern` in `string` by the replacement `repl`. If the pattern +isn’t found, string is returned unchanged." (regexp-replace pattern string repl)) - ;; Scan through `string` looking for the first location where the - ;; regular expression `pattern` produces a match, and return a - ;; corresponding match object. Returns `#f` if no match is found. (define (search string pattern) - (regexp-exec pattern string))) + "Scan through `string` looking for the first location where the regular +expression `pattern` produces a match, and return a corresponding match +object. Returns `#f` if no match is found." + (string-match pattern string))) diff --git a/bs/string.scm b/bs/string.scm index 8839512..9fe794e 100644 --- a/bs/string.scm +++ b/bs/string.scm @@ -17,29 +17,29 @@ ;; TODO: remove or port ice-9 dependency (only (ice-9 ports) with-output-to-string)) - ;; Is `pre` a prefix of `s`? (define (prefix? s pre) + "Is PRE a prefix of S?" (string-prefix? pre s)) - ;; Is `suf` a suffix of `s`? (define (suffix? s suf) + "Is SUF a suffix of S?" (string-suffix? suf s)) - ;; Split `s` at `sep` (define (split s sep) + "Split S at SEP" ;; this is still wrong. it splits on any of the "sep" characters ;; instead of all of them (string-tokenize s (char-set-complement (apply char-set (string->list sep))))) - ;; Replace `match` in `s` with `char` (define (replace-char s match char) + "Replace MATCH in S with CHAR" (let ((f (lambda (a b) (let ((next-char (if (eq? a match) char a))) (string-concatenate (list b (string next-char))))))) (string-fold f "" s))) - ;; Replace `match` in `s` with `repl` (define (replace s match repl) + "Replace MATCH in S with REPL" ;; based on string-replace-substring By A. Wingo in ;; https://lists.gnu.org/archive/html/guile-devel/2014-03/msg00058.html ;; also in string-replace-substring guix:guix/utils.scm. |