Skip to main content

standard-char-p

standard-char-p Function

Syntax:

standard-char-p character → generalized-boolean

Arguments and Values:

character—a character .

generalized-boolean—a generalized boolean.

Description:

Returns true if character is of type standard-char; otherwise, returns false.

Examples:

(standard-char-p #\Space) → true 
(standard-char-p #\~) → true
;; This next example presupposes an implementation
;; in which #\Bell is a defined character.
(standard-char-p #\Bell) → false

Exceptional Situations:

Should signal an error of type type-error if character is not a character .

char-upcase, char-downcase

Expanded Reference: standard-char-p

Basic standard character tests

standard-char-p returns true if the character is one of the 96 standard characters: the 26 uppercase letters, 26 lowercase letters, 10 digits, space, newline, and the standard punctuation characters.

(standard-char-p #\A)
=> T
(standard-char-p #\a)
=> T
(standard-char-p #\5)
=> T
(standard-char-p #\Space)
=> T
(standard-char-p #\Newline)
=> T

Standard punctuation characters

All the standard punctuation and special characters are standard characters.

(standard-char-p #\!)
=> T
(standard-char-p #\@)
=> T
(standard-char-p #\+)
=> T
(standard-char-p #\~)
=> T
(standard-char-p #\()
=> T
(standard-char-p #\/)
=> T

Non-standard characters

Tab, Return, and other control characters are not standard characters, even though some implementations support them.

;; These semi-standard characters are not standard characters:
(standard-char-p #\Tab)
=> NIL
(standard-char-p #\Return)
=> NIL

Checking all characters in a string

You can verify that a string consists entirely of standard characters.

(every #'standard-char-p "Hello, World!")
=> T
(every #'standard-char-p (format nil "Hello~%World"))
=> T
;; (Newline is a standard character)

Counting standard characters

The standard defines exactly 96 standard characters.

(count-if #'standard-char-p
(loop for i from 0 below char-code-limit
for ch = (code-char i)
when ch collect ch))
=> 96