226 |
common to work with @emph{strings}, which are sequences composed of |
common to work with @emph{strings}, which are sequences composed of |
227 |
characters. @xref{String Type}. |
characters. @xref{String Type}. |
228 |
|
|
229 |
Characters in strings, buffers, and files are currently limited to the |
Characters in strings, buffers, and files are currently limited to |
230 |
range of 0 to 524287---nineteen bits. But not all values in that range |
the range of 0 to 524287---nineteen bits. But not all values in that |
231 |
are valid character codes. Codes 0 through 127 are @acronym{ASCII} codes; the |
range are valid character codes. Codes 0 through 127 are |
232 |
rest are non-@acronym{ASCII} (@pxref{Non-ASCII Characters}). Characters that represent |
@acronym{ASCII} codes; the rest are non-@acronym{ASCII} |
233 |
keyboard input have a much wider range, to encode modifier keys such as |
(@pxref{Non-ASCII Characters}). Characters that represent keyboard |
234 |
|
input have a much wider range, to encode modifier keys such as |
235 |
Control, Meta and Shift. |
Control, Meta and Shift. |
236 |
|
|
237 |
@cindex read syntax for characters |
@cindex read syntax for characters |
376 |
@ifnottex |
@ifnottex |
377 |
2**7 |
2**7 |
378 |
@end ifnottex |
@end ifnottex |
379 |
bit attached to an @acronym{ASCII} character indicates a meta character; thus, the |
bit attached to an @acronym{ASCII} character indicates a meta |
380 |
meta characters that can fit in a string have codes in the range from |
character; thus, the meta characters that can fit in a string have |
381 |
128 to 255, and are the meta versions of the ordinary @acronym{ASCII} |
codes in the range from 128 to 255, and are the meta versions of the |
382 |
characters. (In Emacs versions 18 and older, this convention was used |
ordinary @acronym{ASCII} characters. (In Emacs versions 18 and older, |
383 |
for characters outside of strings as well.) |
this convention was used for characters outside of strings as well.) |
384 |
|
|
385 |
The read syntax for meta characters uses @samp{\M-}. For example, |
The read syntax for meta characters uses @samp{\M-}. For example, |
386 |
@samp{?\M-A} stands for @kbd{M-A}. You can use @samp{\M-} together with |
@samp{?\M-A} stands for @kbd{M-A}. You can use @samp{\M-} together with |
417 |
@kbd{Alt-Hyper-Meta-x}. (Note that @samp{\s} with no following @samp{-} |
@kbd{Alt-Hyper-Meta-x}. (Note that @samp{\s} with no following @samp{-} |
418 |
represents the space character.) |
represents the space character.) |
419 |
@tex |
@tex |
420 |
Numerically, the |
Numerically, the bit values are @math{2^{22}} for alt, @math{2^{23}} |
421 |
bit values are @math{2^{22}} for alt, @math{2^{23}} for super and @math{2^{24}} for hyper. |
for super and @math{2^{24}} for hyper. |
422 |
@end tex |
@end tex |
423 |
@ifnottex |
@ifnottex |
424 |
Numerically, the |
Numerically, the |
939 |
constant is just like backslash-newline; it does not contribute any |
constant is just like backslash-newline; it does not contribute any |
940 |
character to the string, but it does terminate the preceding hex escape. |
character to the string, but it does terminate the preceding hex escape. |
941 |
|
|
942 |
Using a multibyte hex escape forces the string to multibyte. You can |
You can represent a unibyte non-@acronym{ASCII} character with its |
943 |
represent a unibyte non-@acronym{ASCII} character with its character code, |
character code, which must be in the range from 128 (0200 octal) to |
944 |
which must be in the range from 128 (0200 octal) to 255 (0377 octal). |
255 (0377 octal). If you write all such character codes in octal and |
945 |
This forces a unibyte string. |
the string contains no other characters forcing it to be multibyte, |
946 |
|
this produces a unibyte string. However, using any hex escape in a |
947 |
|
string (even for an @acronym{ASCII} character) forces the string to be |
948 |
|
multibyte. |
949 |
|
|
950 |
@xref{Text Representations}, for more information about the two |
@xref{Text Representations}, for more information about the two |
951 |
text representations. |
text representations. |
967 |
|
|
968 |
Properly speaking, strings cannot hold meta characters; but when a |
Properly speaking, strings cannot hold meta characters; but when a |
969 |
string is to be used as a key sequence, there is a special convention |
string is to be used as a key sequence, there is a special convention |
970 |
that provides a way to represent meta versions of @acronym{ASCII} characters in a |
that provides a way to represent meta versions of @acronym{ASCII} |
971 |
string. If you use the @samp{\M-} syntax to indicate a meta character |
characters in a string. If you use the @samp{\M-} syntax to indicate |
972 |
in a string constant, this sets the |
a meta character in a string constant, this sets the |
973 |
@tex |
@tex |
974 |
@math{2^{7}} |
@math{2^{7}} |
975 |
@end tex |
@end tex |
1086 |
as a bitmap---each ``character'' in the string contains 8 bits, which |
as a bitmap---each ``character'' in the string contains 8 bits, which |
1087 |
specify the next 8 elements of the bool-vector (1 stands for @code{t}, |
specify the next 8 elements of the bool-vector (1 stands for @code{t}, |
1088 |
and 0 for @code{nil}). The least significant bits of the character |
and 0 for @code{nil}). The least significant bits of the character |
1089 |
correspond to the lowest indices in the bool-vector. If the length is not a |
correspond to the lowest indices in the bool-vector. |
|
multiple of 8, the printed representation shows extra elements, but |
|
|
these extras really make no difference. |
|
1090 |
|
|
1091 |
@example |
@example |
1092 |
(make-bool-vector 3 t) |
(make-bool-vector 3 t) |
1093 |
@result{} #&3"\007" |
@result{} #&3"^G" |
1094 |
(make-bool-vector 3 nil) |
(make-bool-vector 3 nil) |
1095 |
@result{} #&3"\0" |
@result{} #&3"^@@" |
1096 |
;; @r{These are equal since only the first 3 bits are used.} |
@end example |
1097 |
|
|
1098 |
|
@noindent |
1099 |
|
These results make sense, because the binary code for @samp{C-g} is |
1100 |
|
111 and @samp{C-@@} is the character with code 0. |
1101 |
|
|
1102 |
|
If the length is not a multiple of 8, the printed representation |
1103 |
|
shows extra elements, but these extras really make no difference. For |
1104 |
|
instance, in the next example, the two bool-vectors are equal, because |
1105 |
|
only the first 3 bits are used: |
1106 |
|
|
1107 |
|
@example |
1108 |
(equal #&3"\377" #&3"\007") |
(equal #&3"\377" #&3"\007") |
1109 |
@result{} t |
@result{} t |
1110 |
@end example |
@end example |
1888 |
@end example |
@end example |
1889 |
|
|
1890 |
Comparison of strings is case-sensitive, but does not take account of |
Comparison of strings is case-sensitive, but does not take account of |
1891 |
text properties---it compares only the characters in the strings. |
text properties---it compares only the characters in the strings. For |
1892 |
A unibyte string never equals a multibyte string unless the |
technical reasons, a unibyte string and a multibyte string are |
1893 |
contents are entirely @acronym{ASCII} (@pxref{Text Representations}). |
@code{equal} if and only if they contain the same sequence of |
1894 |
|
character codes and all these codes are either in the range 0 through |
1895 |
|
127 (@acronym{ASCII}) or 160 through 255 (@code{eight-bit-graphic}). |
1896 |
|
(@pxref{Text Representations}). |
1897 |
|
|
1898 |
@example |
@example |
1899 |
@group |
@group |