Move capitalize to util-string.

This commit is contained in:
Dominik Pantůček 2023-11-16 19:08:47 +01:00
parent fb47d60550
commit 27a1a3522b
2 changed files with 22 additions and 9 deletions

View file

@ -37,6 +37,8 @@
string-upcase
string-capitalize
string-tests!
)
@ -100,6 +102,18 @@ using ```char-upcase```. Does not work with UTF-8.")
(map char-upcase
(string->list str))))
(define/doc (string-capitalize str)
("* ```str``` - arbitrary string
Returns the ```str``` with the first character converted to upper case
using ```char-upcase``` and the remainder converted to lower case
using ```char-downcase```. Does not work with UTF-8.")
(let ((l (string->list str)))
(list->string
(cons
(char-upcase (car l))
(map char-downcase (cdr l))))))
;; Performs utils module self-tests.
(define (string-tests!)
(run-tests
@ -122,6 +136,12 @@ using ```char-upcase```. Does not work with UTF-8.")
(test-equal? string-upcase
(string-upcase "asdFGH")
"ASDFGH")
(test-equal? string-capitalize
(string-capitalize "asdf")
"Asdf")
(test-equal? string-capitalize
(string-capitalize "ASDF")
"Asdf")
))
)