Duck util-string.
This commit is contained in:
parent
3833196533
commit
722ac4830c
5 changed files with 58 additions and 56 deletions
|
@ -25,8 +25,11 @@
|
|||
|
||||
(declare (unit util-string))
|
||||
|
||||
(module
|
||||
(import duck)
|
||||
|
||||
(module*
|
||||
util-string
|
||||
#:doc ("String manipulation functions which are used throughout other modules.")
|
||||
(
|
||||
string-first+rest
|
||||
|
||||
|
@ -45,7 +48,12 @@
|
|||
util-utf8)
|
||||
|
||||
;; Extracts first token and the rest as separate string
|
||||
(define (string-first+rest str)
|
||||
(define/doc (string-first+rest str)
|
||||
("* ```str``` - a string to split
|
||||
|
||||
Returns a pair of strings where the ```car``` of the pair is the first
|
||||
token in the ```str``` given and ```cdr``` is a string with the
|
||||
remainder with leading whitespace removed.")
|
||||
(let ((dm (irregex-search (irregex "[ \\t]" 'u) str)))
|
||||
(if dm
|
||||
(let* ((sep-idx (irregex-match-start-index dm))
|
||||
|
@ -56,7 +64,11 @@
|
|||
(cons str ""))))
|
||||
|
||||
;; Encodes given UTF-8 string as quoted-printable
|
||||
(define (string->qp str)
|
||||
(define/doc (string->qp str)
|
||||
("* ```str``` - arbitrary string
|
||||
|
||||
Returns a new string with all non-ASCII characters encoded as
|
||||
quoted-printable sequences.")
|
||||
(let loop ((lst (utf8-string->list str))
|
||||
(res '()))
|
||||
(if (null? lst)
|
||||
|
@ -82,7 +94,11 @@
|
|||
res)))))
|
||||
|
||||
;; Returns upper-case version of the string
|
||||
(define (string-upcase str)
|
||||
(define/doc (string-upcase str)
|
||||
("* ```str``` - arbitrary string
|
||||
|
||||
Returns the ```str``` with all characters converted to upper case
|
||||
using ```char-upcase```. Does not work with UTF-8.")
|
||||
(list->string
|
||||
(map char-upcase
|
||||
(string->list str))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue