From 08902541eb317d72aa1865edcf00263238c43eae Mon Sep 17 00:00:00 2001 From: vindarel Date: Tue, 29 Oct 2019 18:18:14 +0100 Subject: [PATCH] Add functions to change case + remove punctuation fixes #27 - Add functions to change case --- README.md | 36 ++++++++++++++++++++++++++++++++++++ str.asd | 5 +++-- str.lisp | 43 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 49f1ecb..4e20e6f 100644 --- a/README.md +++ b/README.md @@ -421,6 +421,32 @@ begins with `prefix` and ends with `suffix`. ### Case +#### Functions to change case: camel-case, snake-case,... (new in 0.15) + +We use +[cl-change-case](https://github.com/rudolfochrist/cl-change-case/) (go +thank him and star the repo!). + +The available functions are: + +``` +:no-case (s &key replacement) +:camel-case (s &key merge-numbers) +:dot-case +:header-case +:param-case +:pascal-case +:path-case +:sentence-case +:snake-case +:swap-case +:title-case +:constant-case +``` + +More documentation and examples are there. + + #### downcase, upcase, capitalize `(s)` fixing a built-in suprise. (new in 0.11) The functions `str:downcase`, `str:upcase` and `str:capitalize` return @@ -484,6 +510,14 @@ Uses [cl-ppcre:regex-replace-all](http://weitz.de/cl-ppcre/#regex-replace-all) but quotes the user input to not treat it as a regex. +#### remove-punctuation (s &key replacement) + +An alias to `str:no-case` (itself [`cl-change-case:no-case`](https://github.com/rudolfochrist/cl-change-case/#no-case)). + +~~~lisp +(str:remove-punctuation "I say: - 'hello, world?'") ;; => "i say hello world" +~~~ + #### prefix `(list-of-strings)` (renamed in 0.9) @@ -563,6 +597,8 @@ Now: ("a" "b" "c" "") ~~~ +* 0.15, october 2019: added functions to change case (based on cl-change-case). + added remove-punctuation. * august, 2019: deprecated `prune`, renamed to `shorten`. * added `:limit` to `split`. * 0.13 june, 2019 diff --git a/str.asd b/str.asd index 0fba219..1508b6f 100644 --- a/str.asd +++ b/str.asd @@ -4,13 +4,14 @@ :author "vindarel " :maintainer "vindarel " :license "MIT" - :version "0.14" + :version "0.15" :homepage "https://github.com/vindarel/cl-str" :bug-tracker "https://github.com/vindarel/cl-str/issues" :source-control (:git "git@github.com:vindarel/cl-str.git") :description "Modern, consistent and terse Common Lisp string manipulation library." :depends-on (:cl-ppcre - :cl-ppcre-unicode) + :cl-ppcre-unicode + :cl-change-case) :components ((:file "str")) :long-description diff --git a/str.lisp b/str.lisp index 796010b..58dabd7 100644 --- a/str.lisp +++ b/str.lisp @@ -1,7 +1,38 @@ (in-package :cl-user) + (defpackage str (:use :cl) + (:import-from :cl-change-case + :no-case + :camel-case + :dot-case + :header-case + :param-case + :pascal-case + :path-case + :sentence-case + :snake-case + :swap-case + :title-case + :constant-case) (:export + ;; cl-change-case functions: + ;; (we could use cl-reexport but we don't want Alexandria in the dependencies list) + :no-case + :camel-case + :dot-case + :header-case + :param-case + :pascal-case + :path-case + :sentence-case + :snake-case + :swap-case + :title-case + :constant-case + + ;; ours: + :remove-punctuation :contains? :containsp :trim-left @@ -13,7 +44,7 @@ :split-omit-nulls :substring :shorten - :prune ;; "deprecated" in favor of shorten + :prune ;; "deprecated" in favor of shorten :repeat :replace-all :concat @@ -76,18 +107,18 @@ :*ellipsis* :version :+version+ - :? - )) + :?)) (in-package :str) + (defparameter *ignore-case* nil) (defparameter *omit-nulls* nil) (defvar *whitespaces* '(#\Space #\Newline #\Backspace #\Tab #\Linefeed #\Page #\Return #\Rubout)) -(defvar +version+ "0.14") +(defvar +version+ "0.15") (defun version () (print +version+)) @@ -584,3 +615,7 @@ Returns the string written to file." (defun upcase? (s) "alias for `upcasep'." (upcasep s)) + +(defun remove-punctuation (s &key (replacement " ")) + "Extract the letters from `s'. Use `replacement' for other characters." + (cl-change-case:no-case s :replacement replacement))