ECL is fully ANSI Common-Lisp compliant in all aspects of the character data type, with the following peculiarities.
|• Characters - Unicode vs. POSIX locale|
|• Characters - Newline characters|
|• Characters - C Reference|
There are two ways of building ECL: with C or with Unicode character codes. These build modes are accessed using the
--enable-unicode configuration options, the last one being the default.
When using C characters we are actually relying on the char type of the C language, using the C library functions for tasks such as character conversions, comparison, etc. In this case characters are typically 8 bit wide and the character order and collation are determines by the current POSIX or C locale. This is not very accurate, leaves out many languages and character encodings but it is sufficient for small applications that do not need multilingual support.
When no option is specified ECL builds with support for a larger character set, the Unicode 6.0 standard. This uses 24 bit large character codes, also known as codepoints, with a large database of character properties which include their nature (alphanumeric, numeric, etc), their case, their collation properties, whether they are standalone or composing characters, etc.
If ECL is compiled without Unicode support, all characters are implemented using 8-bit codes and the type
extended-char is empty. If compiled with Unicode support, characters are implemented using 24 bits and the
extended-char type covers characters above code 255.
|Type||With Unicode||Without Unicode|
All characters have a name. For non-printing characters between 0 and 32, and for 127 we use the ordinary ASCII names. Characters above 127 are printed and read using hexadecimal Unicode notation, with a U followed by 24 bit hexadecimal number, as in
#\Linefeed is synonymous with
#\Newline and thus is a member of
Internally, ECL represents the
#\Newline character by a single code. However, when using external formats, ECL may parse character pairs as a single
#\Newline, and vice versa, use multiple characters to represent a single
#\Newline, see Streams - External formats.
C character types
ECL defines two C types to hold its characters:
unsigned char, to cover the 256 codes that are needed.
For your code to be portable and future proof, use both types to really express what you intend to do.
Creating and extracting characters from Lisp objects
These functions and macros convert back and forth from C character types to Lisp. The macros
ECL_CODE_CHAR perform this coercion without checking the arguments. The functions
ecl_base_char_code, on the other hand, verify that the argument has the right type and signal an error otherwise.
C predicates for Lisp characters
These functions are equivalent to their Lisp equivalents but return C booleans.
C functions related to the character case
These functions check or change the case of a character. Note that in a Unicode context, the output of these functions might not be accurate (for instance when the uppercase character has two or more codepoints).
Common Lisp and C equivalence
|Lisp symbol||C function|
|char=||cl_object cl_charE(cl_narg narg, ...)|
|char/=||cl_object cl_charNE(cl_narg narg, ...)|
|char<||cl_object cl_charL(cl_narg narg, ...)|
|char>||cl_object cl_charG(cl_narg narg, ...)|
|char<=||cl_object cl_charLE(cl_narg narg, ...)|
|char>=||cl_object cl_charGE(cl_narg narg, ...)|
|char-equal||cl_object cl_char_equal(cl_narg narg, ...)|
|char-not-equal||cl_object cl_char_not_equal(cl_narg narg, ...)|
|char-lessp||cl_object cl_char_lessp(cl_narg narg, ...)|
|char-greaterp||cl_object cl_char_greaterp(cl_narg narg, ...)|
|char-not-greaterp||cl_object cl_char_not_greaterp(cl_narg narg, ...)|
|char-not-lessp||cl_object cl_char_not_lessp(cl_narg narg, ...)|
|character||cl_object cl_character(cl_object char_designator)|
|characterp||cl_object cl_characterp(cl_object object)|
|alpha-char-p||cl_object cl_alpha_char_p(cl_object character)|
|alphanumericp||cl_object cl_alphanumericp(cl_object character)|
|digit-char||cl_object cl_digit_char(cl_narg narg, cl_object character, ...)|
|digit-char-p||cl_object cl_digit_char_p(cl_narg narg, cl_object character, ...)|
|graphic-char-p||cl_object cl_graphic_char_p(cl_object character)|
|standard-char-p||cl_object cl_standard_char_p(cl_object character)|
|char_upcase||cl_object cl_char_upcase(cl_object character)|
|char-downcase||cl_object cl_char_downcase(cl_object character)|
|upper-case-p||cl_object cl_upper_case_p(cl_object character)|
|lower-case-p||cl_object cl_lower_case_p(cl_object character)|
|both-case-p||cl_object cl_both_case_p(cl_object character)|
|char-code||cl_object cl_char_code(cl_object character)|
|char-int||cl_object cl_char_int(cl_object character)|
|code-char||cl_object cl_code_char(cl_object code)|
|char-name||cl_object cl_char_name(cl_object character)|
|name-char||cl_object cl_name_char(cl_object name)|