Skip to content

Commit

Permalink
remove-punctuation now respects the case.
Browse files Browse the repository at this point in the history
  • Loading branch information
vindarel committed Apr 13, 2020
1 parent ae99faf commit eb480f2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,15 @@ 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)).
Remove the punctuation characters from `s`, replace them with
`replacement` (defaults to a space) and strip continuous whitespace.

~~~lisp
(str:remove-punctuation "I say: - 'hello, world?'") ;; => "i say hello world"
(str:remove-punctuation "I say: - 'Hello, world?'") ;; => "I say Hello world"
~~~

Use `str:no-case` to remove punctuation and return the string as lower-case.


#### prefix `(list-of-strings)` (renamed in 0.9)

Expand Down Expand Up @@ -701,6 +704,7 @@ Now:
("a" "b" "c" "")
~~~

* 0.17, april 2020: fixed `remove-punctuation` that did not respect the case. Use `no-case` for this.
* 0.16, november 2019: added `pad`, `pad-[left, right, center]`.
* 0.15, october 2019: added functions to change case (based on cl-change-case).
added remove-punctuation.
Expand Down
2 changes: 1 addition & 1 deletion str.asd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:author "vindarel <[email protected]>"
:maintainer "vindarel <[email protected]>"
:license "MIT"
:version "0.16"
:version "0.17"
: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")
Expand Down
20 changes: 17 additions & 3 deletions str.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
(defvar *whitespaces* '(#\Space #\Newline #\Backspace #\Tab
#\Linefeed #\Page #\Return #\Rubout))

(defvar +version+ "0.16")
(defvar +version+ "0.17")

(defun version ()
(print +version+))
Expand Down Expand Up @@ -698,5 +698,19 @@ with `string='.
(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))
"Remove the punctuation characters from `s', replace them with `replacement' (defaults to a space) and strip continuous whitespace."
(flet ((replace-non-word (string)
(ppcre:regex-replace-all
"[^\\p{L}\\p{N}]+"
string
(lambda (target start end match-start match-end reg-starts reg-ends)
(declare (ignore target start reg-starts reg-ends))
;; completely remove trailing and leading non-word chars
(if (or (zerop match-start)
(= match-start (- end (- match-end match-start))))
""
;; use replacement kwarg for non-space chars inbetween
replacement)))))
(if (null s)
""
(replace-non-word s))))

0 comments on commit eb480f2

Please sign in to comment.