Jump to content

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

m
spelling corrections
m (spelling corrections)
Line 274:
 
 
/* check a character
return 1 for true
0 for false
Line 280:
int ascii (const unsigned char c)
{
unsigned char min = 32; /* <space> */
unsigned char max = 126; /* ~ tilde */
 
if ( c>=min && c<=max ) return 1;
Line 289:
 
 
/* check iif extended character
return 1 for true
0 for false
Line 295:
int ascii_ext (const unsigned char c)
{
unsigned char min_ext = 128;
unsigned char max_ext = 255;
 
Line 305:
 
 
/* fill buffer omly with only ASCII valid characters
then rewrite string from buffer
limit to n < MAX chars
Line 580:
=={{header|Common Lisp}}==
<pre>
(defun stripcontrol-specialchar-charsp (string &key strip-extendedch)
(let*or ((127-operator< (if stripchar-extendedcode #'>=ch) #'=))32)
(remove-if (lambda= (char-code ch) 127)))
(or (< (char-code ch) 32)
(funcall 127-operator (char-code ch) 127)))
string)))
 
(defun extended-char-p (ch)
(defvar *the-string* (format nil "Hello~aWørld~a" #\Page #\Nul))
(> (char-code ch) 127))
 
(formatdefun t "Without controls: ~a~%" (strip-special-chars *the(string &key strip-string*)extended)
(format t "Without extended characters: ~a~%"(let (strip(needs-specialremoving-charsp *the-string*(if :strip-extended t))
(lambda (ch)
</pre>
(or (< (control-char-codep ch) 32)
 
(funcall 127-operator (extended-char-codep ch) 127)))
Output:
#'control-char-p)))
 
(remove-if needs-removing-p string)))
<pre>
Without controls: HelloWørld
Without extended chars: HelloWrld
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.