Debian Codegraph @

src/doc/manual/standards/characters.txi

raw
1 @node Characters
2 @section Characters
3
4 ECL is fully ANSI Common-Lisp compliant in all aspects of the character data type, with the following peculiarities.
5
6 @menu
7 * Characters - Unicode vs. POSIX locale::
8 * Characters - Newline characters::
9 * Characters - C Reference::
10 @end menu
11
12 @node Characters - Unicode vs. POSIX locale
13 @subsection Unicode vs. POSIX locale
14 @cfindex --enable-unicode [32|16|no]
15
16 There are two ways of building ECL: with C or with Unicode character codes. These build modes are accessed using the @code{--disable-unicode} and @code{--enable-unicode} configuration options, the last one being the default.
17
18 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.
19
20 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 @dfn{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.
21
22 @subsubsection Character types
23 @lspindex extended-char
24 If ECL is compiled without Unicode support, all characters are implemented using 8-bit codes and the type @code{extended-char} is empty. If compiled with Unicode support, characters are implemented using 24 bits and the @code{extended-char} type covers characters above code 255.
25 @multitable @columnfractions .33 .33 .33
26 @headitem Type @tab Without Unicode @tab With Unicode
27 @item standard-char @tab #\Newline,32-126 @tab #\Newline,32-126
28 @item base-char @tab 0-255 @tab 0-255
29 @item extended-char @tab - @tab 256-16777215
30 @end multitable
31
32 @subsubsection Character names
33 @lspindex standard-char
34 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 @code{U0126}.
35
36 @float Table, tab:example-char-names
37 @multitable {aaaaaaaaaaa} {aaa}
38 @headitem Character @tab Code
39 @item #\Null @tab 0
40 @item #\Ack @tab 1
41 @item #\Bell @tab 7
42 @item #\Backspace @tab 8
43 @item #\Tab @tab 9
44 @item #\Newline @tab 10
45 @item #\Linefeed @tab 10
46 @item #\Page @tab 12
47 @item #\Esc @tab 27
48 @item #\Escape @tab 27
49 @item #\Space @tab 32
50 @item #\Rubout @tab 127
51 @item #\U0080 @tab 128
52 @end multitable
53 @end float
54
55 Note that @code{#\Linefeed} is synonymous with @code{#\Newline} and thus is a member of @code{standard-char}.
56
57
58 @node Characters - Newline characters
59 @subsection @code{#\Newline} characters
60 Internally, ECL represents the @code{#\Newline} character by a single code. However, when using external formats, ECL may parse character pairs as a single @code{#\Newline}, and vice versa, use multiple characters to represent a single @code{#\Newline}, @pxref{Streams - External formats}.
61
62
63 @node Characters - C Reference
64 @subsection C Reference
65
66 @subsubsection C types
67 @cppdef ecl_base_char
68 @cppdef ecl_character
69 C character types
70
71 @paragraph Type names
72 @multitable {aaaaaaaaaaaaa} {aaaaaaaaa}
73 @item ecl_character @tab character
74 @item ecl_base_char @tab base-char
75 @end multitable
76
77 @paragraph Description
78 ECL defines two C types to hold its characters: @coderef{ecl_base_char} and @coderef{ecl_character}.
79
80 @itemize
81 @item When ECL is built without Unicode, they both coincide and typically match @code{unsigned char}, to cover the 256 codes that are needed.
82 @item When ECL is built with Unicode, the two types are no longer equivalent, with @coderef{ecl_character} being larger.
83 @end itemize
84
85 For your code to be portable and future proof, use both types to really express what you intend to do.
86
87 @subsubsection Constructors
88 @cppdef ECL_CODE_CHAR
89 @cppdef ECL_CHAR_CODE
90 @cppdef ecl_char_code
91 @cppdef ecl_base_char_code
92 Creating and extracting characters from Lisp objects
93
94 @subsubheading Functions
95 @deftypefn Macro cl_object ECL_CODE_CHAR (ecl_character code);
96 @deftypefnx Macro ecl_character ECL_CHAR_CODE (cl_object o);
97 @end deftypefn
98 @deftypefun ecl_character ecl_char_code (cl_object o);
99 @deftypefunx ecl_base_char ecl_base_char_code (cl_object o);
100
101 @paragraph Description
102 These functions and macros convert back and forth from C character types to Lisp. The macros @coderef{ECL_CHAR_CODE} and @coderef{ECL_CODE_CHAR} perform this coercion without checking the arguments. The functions @coderef{ecl_char_code} and @coderef{ecl_base_char_code}, on the other hand, verify that the argument has the right type and signal an error otherwise.
103 @end deftypefun
104
105 @subsubsection Predicates
106 @cppdef ecl_base_char_p
107 @cppdef ecl_alpha_char_p
108 @cppdef ecl_alphanumeric_p
109 @cppdef ecl_graphic_char_p
110 @cppdef ecl_digit_p
111 @cppdef ecl_standard_char_p
112 C predicates for Lisp characters
113
114 @subsubheading Functions
115 @deftypefun bool ecl_base_char_p (ecl_character c);
116 @deftypefunx bool ecl_alpha_char_p (ecl_character c);
117 @deftypefunx bool ecl_alphanumericp (ecl_character c);
118 @deftypefunx bool ecl_graphic_char_p (ecl_character c);
119 @deftypefunx bool ecl_digitp (ecl_character c);
120 @deftypefunx bool ecl_standard_char_p (ecl_character c);
121
122 @paragraph Description
123 These functions are equivalent to their Lisp equivalents but return C booleans.
124 @end deftypefun
125
126 @subsubsection Character case
127 @cppdef ecl_upper_case_p
128 @cppdef ecl_lower_case_p
129 @cppdef ecl_both_case_p
130 @cppdef ecl_char_downcase
131 @cppdef ecl_char_upcase
132 C functions related to the character case
133
134 @subsubheading Functions
135 @deftypefun bool ecl_upper_case_p (ecl_character c);
136 @deftypefunx bool ecl_lower_case_p (ecl_character c);
137 @deftypefunx bool ecl_both_case_p (ecl_character c);
138 @deftypefunx ecl_character ecl_char_downcase (ecl_character c);
139 @deftypefunx ecl_character ecl_char_upcase (ecl_character c);
140
141 @paragraph Description
142 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).
143 @end deftypefun
144
145 @subsubsection ANSI Dictionary
146 Common Lisp and C equivalence
147
148 @multitable {aaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
149 @headitem Lisp symbol @tab C function
150 @item @clhs{f_chareq.htm,char=} @tab cl_object cl_charE(cl_narg narg, ...)
151 @item @clhs{f_chareq.htm,char/=} @tab cl_object cl_charNE(cl_narg narg, ...)
152 @item @clhs{f_chareq.htm,char<} @tab cl_object cl_charL(cl_narg narg, ...)
153 @item @clhs{f_chareq.htm,char>} @tab cl_object cl_charG(cl_narg narg, ...)
154 @item @clhs{f_chareq.htm,char<=} @tab cl_object cl_charLE(cl_narg narg, ...)
155 @item @clhs{f_chareq.htm,char>=} @tab cl_object cl_charGE(cl_narg narg, ...)
156 @item @clhs{f_chareq.htm,char-equal} @tab cl_object cl_char_equal(cl_narg narg, ...)
157 @item @clhs{f_chareq.htm,char-not-equal} @tab cl_object cl_char_not_equal(cl_narg narg, ...)
158 @item @clhs{f_chareq.htm,char-lessp} @tab cl_object cl_char_lessp(cl_narg narg, ...)
159 @item @clhs{f_chareq.htm,char-greaterp} @tab cl_object cl_char_greaterp(cl_narg narg, ...)
160 @item @clhs{f_chareq.htm,char-not-greaterp} @tab cl_object cl_char_not_greaterp(cl_narg narg, ...)
161 @item @clhs{f_chareq.htm,char-not-lessp} @tab cl_object cl_char_not_lessp(cl_narg narg, ...)
162 @item @clhs{f_ch.htm,character} @tab cl_object cl_character(cl_object char_designator)
163 @item @clhs{f_chp.htm,characterp} @tab cl_object cl_characterp(cl_object object)
164 @item @clhs{f_alpha_.htm,alpha-char-p} @tab cl_object cl_alpha_char_p(cl_object character)
165 @item @clhs{f_alphan.htm,alphanumericp} @tab cl_object cl_alphanumericp(cl_object character)
166 @item @clhs{f_digit_.htm,digit-char} @tab cl_object cl_digit_char(cl_narg narg, cl_object character, ...)
167 @item @clhs{f_digi_1.htm,digit-char-p} @tab cl_object cl_digit_char_p(cl_narg narg, cl_object character, ...)
168 @item @clhs{f_graphi.htm,graphic-char-p} @tab cl_object cl_graphic_char_p(cl_object character)
169 @item @clhs{f_std_ch.htm,standard-char-p} @tab cl_object cl_standard_char_p(cl_object character)
170 @item @clhs{f_char_u.htm,char_upcase} @tab cl_object cl_char_upcase(cl_object character)
171 @item @clhs{f_char_u.htm,char-downcase} @tab cl_object cl_char_downcase(cl_object character)
172 @item @clhs{f_upper_.htm,upper-case-p} @tab cl_object cl_upper_case_p(cl_object character)
173 @item @clhs{f_upper_.htm,lower-case-p} @tab cl_object cl_lower_case_p(cl_object character)
174 @item @clhs{f_upper_.htm,both-case-p} @tab cl_object cl_both_case_p(cl_object character)
175 @item @clhs{f_char_c.htm,char-code} @tab cl_object cl_char_code(cl_object character)
176 @item @clhs{f_char_i.htm,char-int} @tab cl_object cl_char_int(cl_object character)
177 @item @clhs{f_code_c.htm,code-char} @tab cl_object cl_code_char(cl_object code)
178 @item @clhs{f_char_n.htm,char-name} @tab cl_object cl_char_name(cl_object character)
179 @item @clhs{f_name_c.htm,name-char} @tab cl_object cl_name_char(cl_object name)
180 @item @clhs{v_char_c.htm,char-code-limit} @tab ECL_CHAR_CODE_LIMIT
181 @end multitable