Card alias parsing.
This commit is contained in:
parent
2d0ff00ffb
commit
4d43ce29d8
4 changed files with 28 additions and 4 deletions
14
utils.scm
14
utils.scm
|
@ -30,12 +30,14 @@
|
|||
(
|
||||
filter
|
||||
string-repeat
|
||||
string-first+rest
|
||||
utils-tests!
|
||||
)
|
||||
|
||||
(import scheme
|
||||
(chicken base)
|
||||
(chicken string)
|
||||
(chicken irregex)
|
||||
testing)
|
||||
|
||||
;; Returns a list with elements matching pred? predicate.
|
||||
|
@ -59,6 +61,18 @@
|
|||
(cons str res))
|
||||
(string-intersperse res ""))))
|
||||
|
||||
;; Extracts first token and the rest as separate string
|
||||
(define (string-first+rest str)
|
||||
(let ((dm (irregex-search (irregex "[ \\t]" 'u) str)))
|
||||
(if dm
|
||||
(let* ((sep-idx (irregex-match-start-index dm))
|
||||
(key-str (substring str 0 sep-idx))
|
||||
(sep+val (substring str sep-idx))
|
||||
(val (irregex-replace (irregex "^[ \\t]*" 'u) sep+val "")))
|
||||
(cons key-str val))
|
||||
(cons str ""))))
|
||||
|
||||
|
||||
;; Performs utils module self-tests.
|
||||
(define (utils-tests!)
|
||||
(run-tests
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue