Strip control codes and extended characters from a string: Difference between revisions

Content added Content deleted
(→‎{{header|Common Lisp}}: Better implementation)
(→‎{{header|Common Lisp}}: Optimize the implementation)
Line 580:
=={{header|Common Lisp}}==
<pre>
(defun control-char-p (ch)
(or (< (char-code ch) 32)
(= (char-code ch) 127)))
 
(defun extended-char-p (ch)
(> (char-code ch) 127))
 
(defun strip-special-chars (string &key strip-extended)
(let* ((needs127-removing-poperator (if strip-extended #'> #'=)))
(remove-if (lambda (ch)
(or (control-< char-pcode ch 32)
(funcall 127-operator (extended-char-pcode ch) 127)))
#'control-char-pstring)))
(remove-if needs-removing-p string)))
</pre>