Skip to content

Commit

Permalink
Add functions to change case + remove punctuation
Browse files Browse the repository at this point in the history
fixes #27 - Add functions to change case
  • Loading branch information
vindarel committed Oct 29, 2019
1 parent 1d00ea3 commit 0890254
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions str.asd
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
:author "vindarel <[email protected]>"
:maintainer "vindarel <[email protected]>"
: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 "[email protected]: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
Expand Down
43 changes: 39 additions & 4 deletions str.lisp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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+))
Expand Down Expand Up @@ -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))

0 comments on commit 0890254

Please sign in to comment.