The functions on this page implement tests for the standard POSIX character classes, where all functions return the tested character if the test succeeds, or NIL if the test fails.
The
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
The main difference is:
> (char:alnum-p 'nonsense-value) error: bad argument type - NONSENSE-VALUE > (alnum-character-p 'nonsense-value) NIL
The internal functions are based on
;; alphanumeric characters = a-z, A-z, 0-9 (defun char:alnum-p (char) (and (alphanumericp char) char)) ;; alphabetic characters = a-z, A-Z (defun char:alpha-p (char) (and (both-char-p char) char)) ;; blanks = space and horizontal-tab (defun char:blank-p (char) (and (or (char= char #\Space) (char= char #\Tab)) char)) ;; control characters = code-chars 0-31 and 127 (defun char:cntrl-p (char) (let ((code (char-code char))) (and (or (<= 0 code 31) (= code 127)) char))) ;; decimal digits = 0-9 (defun char:digit-p (char) (and (digit-char-p char) char)) ;; graphical characters = alnum + punct (defun char:graph-p (char) (and (<= 33 (char-code char) 126) char)) ;; lowercase characters = a-z (defun char:lower-p (char) (and (lower-case-p char) char)) ;; printable characters = alnum + punct + space (defun char:print-p (char) (and (<= 32 (char-code char) 126) char)) ;; punctuation marks (defun char:punct-p (char) (let ((code (char-code char))) (and (or (<= 33 code 47) ; ! " # $ % & ' ( ) * + , - . / (<= 58 code 64) ; : ; < = > ? @ (<= 91 code 96) ; [ \ ] ^ _ ` (<= 123 code 126)) ; { | } ~ char))) ;; characters producing whitespace ;; ;; 9 = horizontal tab 10 = line feed 11 = vertical tab ;; 12 = form feed 13 = carriage return 32 = space (defun char:space-p (char) (and (member (char-code char) '(9 10 11 12 13 32)) char)) ;; uppercase characters = A-Z (defun char:upper-p (char) (and (upper-case-p char) char)) ;; hexadecimal digits = 0-9, a-f, A-F (defun char:xdigit-p (char) (and (or (digit-char-p char) (let ((code (char-code char))) (or (<= 65 code 70) ; A-Z (<= 97 code 102)))) ; a-z char))
The user functions are based on the
;; alphanumeric characters = a-z, A-z, 0-9 (defun alnum-character-p (char) (and (characterp char) (char:alnum-p char))) ;; alphabetic characters = a-z, A-Z (defun alpha-character-p (char) (and (characterp char) (char:alpha-p char))) ;; blanks = space and horizontal-tab (defun blank-character-p (char) (and (characterp char) (char:blank-p char))) ;; control characters = code-chars 0-31 and 127 (defun cntrl-character-p (char) (and (characterp char) (char:cntrl-p char))) ;; decimal digits = 0-9 (defun digit-character-p (char) (and (characterp char) (char:digit-p char))) ;; graphical characters = alnum + punct (defun graph-character-p (char) (and (characterp char) (char:graph-p char))) ;; lowercase characters = a-z (defun lower-character-p (char) (and (characterp char) (char:lower-p char))) ;; printable characters = alnum + punct + space (defun print-character-p (char) (and (characterp char) (char:print-p char))) ;; punctuation marks (defun punct-character-p (char) (and (characterp char) (char:punct-p char))) ;; characters producing whitespace (defun space-character-p (char) (and (characterp char) (char:space-p char))) ;; uppercase characters = A-Z (defun upper-character-p (char) (and (characterp char) (char:upper-p char))) ;; hexadecimal digits = 0-9, a-f, A-F (defun xdigit-character-p (char) (and (characterp char) (char:xdigit-p char)))