diff options
Diffstat (limited to 'src/strings.lisp')
| -rw-r--r-- | src/strings.lisp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/strings.lisp b/src/strings.lisp index 68289aa..b11c31c 100644 --- a/src/strings.lisp +++ b/src/strings.lisp | |||
| @@ -3,11 +3,23 @@ | |||
| 3 | (defpackage :ukkoclot/strings | 3 | (defpackage :ukkoclot/strings |
| 4 | (:use :c2cl :iterate) | 4 | (:use :c2cl :iterate) |
| 5 | (:import-from :cl-unicode :general-category) | 5 | (:import-from :cl-unicode :general-category) |
| 6 | (:export :escape-xml :is-tg-whitespace-str :lisp->snake-case :snake->lisp-case :starts-with :starts-with-ignore-case)) | 6 | (:export |
| 7 | :ends-with | ||
| 8 | :escape-xml | ||
| 9 | :is-tg-whitespace-str | ||
| 10 | :lisp->camel-case | ||
| 11 | :lisp->snake-case | ||
| 12 | :snake->lisp-case | ||
| 13 | :starts-with | ||
| 14 | :starts-with-ignore-case)) | ||
| 7 | (in-package :ukkoclot/strings) | 15 | (in-package :ukkoclot/strings) |
| 8 | 16 | ||
| 9 | ;; These are very inefficient but I don't care until I profile | 17 | ;; These are very inefficient but I don't care until I profile |
| 10 | 18 | ||
| 19 | (defun ends-with (str suffix) | ||
| 20 | (and (> (length str) (length suffix)) | ||
| 21 | (string= str suffix :start1 (- (length str) (length suffix))))) | ||
| 22 | |||
| 11 | (defun escape-xml (str &optional out) | 23 | (defun escape-xml (str &optional out) |
| 12 | (if out | 24 | (if out |
| 13 | (escape-xml% str out) | 25 | (escape-xml% str out) |
| @@ -36,6 +48,18 @@ | |||
| 36 | (iter (for ch in-string str) | 48 | (iter (for ch in-string str) |
| 37 | (always (is-tg-whitespace ch)))) | 49 | (always (is-tg-whitespace ch)))) |
| 38 | 50 | ||
| 51 | (defun lisp->camel-case (str) | ||
| 52 | (with-output-to-string (out) | ||
| 53 | (let ((should-caps nil)) | ||
| 54 | (iter (for ch in-string str) | ||
| 55 | (cond ((char= ch #\-) | ||
| 56 | (setf should-caps t)) | ||
| 57 | (should-caps | ||
| 58 | (write-char (char-upcase ch) out) | ||
| 59 | (setf should-caps nil)) | ||
| 60 | (t | ||
| 61 | (write-char (char-downcase ch) out))))))) | ||
| 62 | |||
| 39 | (defun lisp->snake-case (str) | 63 | (defun lisp->snake-case (str) |
| 40 | (with-output-to-string (out) | 64 | (with-output-to-string (out) |
| 41 | (loop for ch across str do | 65 | (loop for ch across str do |