1234567891011121314151617181920212223242526272829303132333435363738 |
- (define-module (string-utils)
- #:export (char->string
- string->char
- has-prefix?))
- (use-modules
- (ice-9 exceptions))
- (define char->string
- (λ (c)
- (list->string
- (list c))))
- (define string->char
- (λ (str)
- "Convert a string, which has only one single character
- into a character. This is useful, because some functions
- expect a characters as input instead of a string."
- (cond
- [(= (string-length str) 1)
- (car (string->list str))]
- [else
- (raise-exception
- (make-exception
- (make-non-continuable-error)
- (make-exception-with-message "trying to convert string of more than 1 character to char")
- (make-exception-with-irritants (list str))
- (make-exception-with-origin 'string->char)))])))
- (define has-prefix?
- (λ (str prefix)
- (= (string-prefix-length str prefix)
- (string-length prefix))))
|