annotate man/lispref/strings.texi @ 5791:9fae6227ede5

Silence texinfo 5.2 warnings, primarily by adding next, prev, and up pointers to all nodes. See xemacs-patches message with ID <5315f7bf.sHpFD7lXYR05GH6E%james@xemacs.org>.
author Jerry James <james@xemacs.org>
date Thu, 27 Mar 2014 08:59:03 -0600
parents 3889ef128488
children 15041705c196
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 @c -*-texinfo-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 @c This is part of the XEmacs Lisp Reference Manual.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 @c See the file lispref.texi for copying conditions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 @setfilename ../../info/strings.info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 @node Strings and Characters, Lists, Numbers, Top
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 @chapter Strings and Characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 @cindex strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 @cindex character arrays
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 @cindex characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 @cindex bytes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 A string in XEmacs Lisp is an array that contains an ordered sequence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 of characters. Strings are used as names of symbols, buffers, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 files, to send messages to users, to hold text being copied between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 buffers, and for many other purposes. Because strings are so important,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 XEmacs Lisp has many functions expressly for manipulating them. XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 Lisp programs use strings more often than individual characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 @menu
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
21 * String Basics:: Basic properties of strings and characters.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 * Predicates for Strings:: Testing whether an object is a string or char.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 * Creating Strings:: Functions to allocate new strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 * Predicates for Characters:: Testing whether an object is a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 * Character Codes:: Each character has an equivalent integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 * Text Comparison:: Comparing characters or strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 * String Conversion:: Converting characters or strings and vice versa.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 * Modifying Strings:: Changing characters in a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 * String Properties:: Additional information attached to strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 * Formatting Strings:: @code{format}: XEmacs's analog of @code{printf}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 * Character Case:: Case conversion functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 * Case Tables:: Customizing case conversion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 * Char Tables:: Mapping from characters to Lisp objects.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
36 @node String Basics, Predicates for Strings, Strings and Characters, Strings and Characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 @section String and Character Basics
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 Strings in XEmacs Lisp are arrays that contain an ordered sequence of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 characters. Characters are their own primitive object type in XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 20. However, in XEmacs 19, characters are represented in XEmacs Lisp as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 integers; whether an integer was intended as a character or not is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 determined only by how it is used. @xref{Character Type}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 The length of a string (like any array) is fixed and independent of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 the string contents, and cannot be altered. Strings in Lisp are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 @emph{not} terminated by a distinguished character code. (By contrast,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 strings in C are terminated by a character with @sc{ascii} code 0.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 This means that any character, including the null character (@sc{ascii}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 code 0), is a valid element of a string.@refill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 Since strings are considered arrays, you can operate on them with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 general array functions. (@xref{Sequences Arrays Vectors}.) For
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 example, you can access or change individual characters in a string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 using the functions @code{aref} and @code{aset} (@pxref{Array
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 Functions}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 Strings use an efficient representation for storing the characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 in them, and thus take up much less memory than a vector of the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 length.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 Sometimes you will see strings used to hold key sequences. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 exists for backward compatibility with Emacs 18, but should @emph{not}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 be used in new code, since many key chords can't be represented at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 all and others (in particular meta key chords) are confused with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 accented characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 @ignore @c Not accurate any more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 Each character in a string is stored in a single byte. Therefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 numbers not in the range 0 to 255 are truncated when stored into a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 string. This means that a string takes up much less memory than a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 vector of the same length.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 Sometimes key sequences are represented as strings. When a string is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 a key sequence, string elements in the range 128 to 255 represent meta
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 characters (which are extremely large integers) rather than keyboard
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 events in the range 128 to 255.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 Strings cannot hold characters that have the hyper, super or alt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 modifiers; they can hold @sc{ASCII} control characters, but no other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 control characters. They do not distinguish case in @sc{ASCII} control
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 characters. @xref{Character Type}, for more information about
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 representation of meta and other modifiers for keyboard input
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 @end ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 Strings are useful for holding regular expressions. You can also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 match regular expressions against strings (@pxref{Regexp Search}). The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 functions @code{match-string} (@pxref{Simple Match Data}) and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 @code{replace-match} (@pxref{Replacing Match}) are useful for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 decomposing and modifying strings based on regular expression matching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 Like a buffer, a string can contain extents in it. These extents are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 created when a function such as @code{buffer-substring} is called on a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 region with duplicable extents in it. When the string is inserted into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 a buffer, the extents are inserted along with it. @xref{Duplicable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 Extents}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 @xref{Text}, for information about functions that display strings or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 copy them into buffers. @xref{Character Type}, and @ref{String Type},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 for information about the syntax of characters and strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
103 @node Predicates for Strings, Creating Strings, String Basics, Strings and Characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 @section The Predicates for Strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 For more information about general sequence and array predicates,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 see @ref{Sequences Arrays Vectors}, and @ref{Arrays}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 @defun stringp object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 This function returns @code{t} if @var{object} is a string, @code{nil}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 @defun char-or-string-p object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 This function returns @code{t} if @var{object} is a string or a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 character, @code{nil} otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 In XEmacs addition, this function also returns @code{t} if @var{object}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 is an integer that can be represented as a character. This is because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 of compatibility with previous XEmacs and should not be depended on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
123 @node Creating Strings, Predicates for Characters, Predicates for Strings, Strings and Characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 @section Creating Strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 The following functions create strings, either from scratch, or by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 putting strings together, or by taking them apart.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 @defun string &rest characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 This function returns a new string made up of @var{characters}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 (string ?X ?E ?m ?a ?c ?s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 @result{} "XEmacs"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 (string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 @result{} ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 Analogous functions operating on other data types include @code{list},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 @code{cons} (@pxref{Building Lists}), @code{vector} (@pxref{Vectors})
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
141 and @code{bit-vector} (@pxref{Bit Vectors}). This function has not been
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 available in XEmacs prior to 21.0 and FSF Emacs prior to 20.3.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
145 @defun make-string length character
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
146 This function returns a new string consisting entirely of @var{length}
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
147 successive copies of @var{character}. @var{length} must be a
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4329
diff changeset
148 non-negative fixnum.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 (make-string 5 ?x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 @result{} "xxxxx"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 (make-string 0 ?x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 @result{} ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 Other functions to compare with this one include @code{char-to-string}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 (@pxref{String Conversion}), @code{make-vector} (@pxref{Vectors}), and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 @code{make-list} (@pxref{Building Lists}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 @defun substring string start &optional end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 This function returns a new string which consists of those characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 from @var{string} in the range from (and including) the character at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 index @var{start} up to (but excluding) the character at the index
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 @var{end}. The first character is at index zero.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
5089
99f8ebc082d9 Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
168 In this implementation, @code{substring} is an alias for @code{subseq},
99f8ebc082d9 Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
169 so @var{string} can be any sequence. In GNU Emacs, @var{string} can be
99f8ebc082d9 Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
170 a string or a vector, and in older XEmacs it can only be a string.
99f8ebc082d9 Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
171
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 (substring "abcdefg" 0 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 @result{} "abc"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 Here the index for @samp{a} is 0, the index for @samp{b} is 1, and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 index for @samp{c} is 2. Thus, three letters, @samp{abc}, are copied
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 from the string @code{"abcdefg"}. The index 3 marks the character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 position up to which the substring is copied. The character whose index
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 is 3 is actually the fourth character in the string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 A negative number counts from the end of the string, so that @minus{}1
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
187 signifies the index of the last character of the string. For example:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 (substring "abcdefg" -3 -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 @result{} "ef"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 In this example, the index for @samp{e} is @minus{}3, the index for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 @samp{f} is @minus{}2, and the index for @samp{g} is @minus{}1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 Therefore, @samp{e} and @samp{f} are included, and @samp{g} is excluded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 When @code{nil} is used as an index, it stands for the length of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 string. Thus,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (substring "abcdefg" -3 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 @result{} "efg"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 Omitting the argument @var{end} is equivalent to specifying @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 It follows that @code{(substring @var{string} 0)} returns a copy of all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 of @var{string}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 (substring "abcdefg" 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 @result{} "abcdefg"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 But we recommend @code{copy-sequence} for this purpose (@pxref{Sequence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 Functions}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 If the characters copied from @var{string} have duplicable extents or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 text properties, those are copied into the new string also.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 @xref{Duplicable Extents}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 A @code{wrong-type-argument} error is signaled if either @var{start} or
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4329
diff changeset
231 @var{end} is not a fixnum or @code{nil}. An @code{args-out-of-range}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 error is signaled if @var{start} indicates a character following
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 @var{end}, or if either integer is out of range for @var{string}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 Contrast this function with @code{buffer-substring} (@pxref{Buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 Contents}), which returns a string containing a portion of the text in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 the current buffer. The beginning of a string is at index 0, but the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 beginning of a buffer is at index 1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 @defun concat &rest sequences
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 @cindex copying strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 @cindex concatenating strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 This function returns a new string consisting of the characters in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 arguments passed to it (along with their text properties, if any). The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 arguments may be strings, lists of numbers, or vectors of numbers; they
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 are not themselves changed. If @code{concat} receives no arguments, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 returns an empty string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (concat "abc" "-def")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 @result{} "abc-def"
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4329
diff changeset
253 (equal (concat "abc" (list 120 (+ 256 121)) [122]) (format "abcx%cz" 377))
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4329
diff changeset
254 @result{} t
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 ;; @r{@code{nil} is an empty sequence.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 (concat "abc" nil "-def")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 @result{} "abc-def"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (concat "The " "quick brown " "fox.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 @result{} "The quick brown fox."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (concat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 @result{} ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 The @code{concat} function always constructs a new string that is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 not @code{eq} to any existing string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 For information about other concatenation functions, see the description
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 of @code{mapconcat} in @ref{Mapping Functions}, @code{vconcat} in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 @ref{Vectors}, @code{bvconcat} in @ref{Bit Vectors}, and @code{append}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 in @ref{Building Lists}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
1495
c3cf7db99b98 [xemacs-hg @ 2003-05-22 07:41:20 by stephent]
stephent
parents: 444
diff changeset
274 The function @code{split-string}, in @ref{Regexp Search}, generates a
5384
3889ef128488 Fix misspelled words, and some grammar, across the entire source tree.
Jerry James <james@xemacs.org>
parents: 5089
diff changeset
275 list of strings by splitting a string on occurrences of a regular
1495
c3cf7db99b98 [xemacs-hg @ 2003-05-22 07:41:20 by stephent]
stephent
parents: 444
diff changeset
276 expression.
c3cf7db99b98 [xemacs-hg @ 2003-05-22 07:41:20 by stephent]
stephent
parents: 444
diff changeset
277
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
278 @node Predicates for Characters, Character Codes, Creating Strings, Strings and Characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 @section The Predicates for Characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 @defun characterp object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 This function returns @code{t} if @var{object} is a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 Some functions that work on integers (e.g. the comparison functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 <, <=, =, /=, etc. and the arithmetic functions +, -, *, etc.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 accept characters and implicitly convert them into integers. In
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 general, functions that work on characters also accept char-ints and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 implicitly convert them into characters. WARNING: Neither of these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 behaviors is very desirable, and they are maintained for backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 compatibility with old E-Lisp programs that confounded characters and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 integers willy-nilly. These behaviors may change in the future; therefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 do not rely on them. Instead, convert the characters explicitly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 using @code{char-int}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 @defun integer-or-char-p object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 This function returns @code{t} if @var{object} is an integer or character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
300 @node Character Codes, Text Comparison, Predicates for Characters, Strings and Characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 @section Character Codes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
303 @defun char-int character
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 This function converts a character into an equivalent integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 The resulting integer will always be non-negative. The integers in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 the range 0 - 255 map to characters as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 @table @asis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 @item 0 - 31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 Control set 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 @item 32 - 127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 @sc{ascii}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 @item 128 - 159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 Control set 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 @item 160 - 255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 Right half of ISO-8859-1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 If support for @sc{mule} does not exist, these are the only valid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 character values. When @sc{mule} support exists, the values assigned to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 other characters may vary depending on the particular version of XEmacs,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 the order in which character sets were loaded, etc., and you should not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 depend on them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 @defun int-char integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 This function converts an integer into the equivalent character. Not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 all integers correspond to valid characters; use @code{char-int-p} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 determine whether this is the case. If the integer cannot be converted,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 @code{nil} is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 @defun char-int-p object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 This function returns @code{t} if @var{object} is an integer that can be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 converted into a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 @defun char-or-char-int-p object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 This function returns @code{t} if @var{object} is a character or an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 integer that can be converted into one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 @need 2000
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
344 @node Text Comparison, String Conversion, Character Codes, Strings and Characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 @section Comparison of Characters and Strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 @cindex string equality
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
348 @defun char-equal character1 character2 &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 This function returns @code{t} if the arguments represent the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 character, @code{nil} otherwise. This function ignores differences
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
351 in case if the value of @code{case-fold-search} is non-@code{nil} in
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
352 @var{buffer}, which defaults to the current buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (char-equal ?x ?x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (let ((case-fold-search t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 (char-equal ?x ?X))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (let ((case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (char-equal ?x ?X))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 @defun char= character1 character2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 This function returns @code{t} if the arguments represent the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 character, @code{nil} otherwise. Case is significant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (char= ?x ?x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (char= ?x ?X)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 (let ((case-fold-search t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (char-equal ?x ?X))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 (let ((case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (char-equal ?x ?X))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 @defun string= string1 string2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 This function returns @code{t} if the characters of the two strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 match exactly; case is significant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 (string= "abc" "abc")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 (string= "abc" "ABC")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (string= "ab" "ABC")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 @ignore @c `equal' in XEmacs does not compare text properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 The function @code{string=} ignores the text properties of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 two strings. To compare strings in a way that compares their text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 properties also, use @code{equal} (@pxref{Equality Predicates}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 @end ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 @defun string-equal string1 string2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 @code{string-equal} is another name for @code{string=}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 @cindex lexical comparison
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 @defun string< string1 string2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 @c (findex string< causes problems for permuted index!!)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 This function compares two strings a character at a time. First it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 scans both the strings at once to find the first pair of corresponding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 characters that do not match. If the lesser character of those two is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 the character from @var{string1}, then @var{string1} is less, and this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 function returns @code{t}. If the lesser character is the one from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 @var{string2}, then @var{string1} is greater, and this function returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 @code{nil}. If the two strings match entirely, the value is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 Pairs of characters are compared by their @sc{ascii} codes. Keep in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 mind that lower case letters have higher numeric values in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 @sc{ascii} character set than their upper case counterparts; numbers and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 many punctuation characters have a lower numeric value than upper case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 letters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 (string< "abc" "abd")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 (string< "abd" "abc")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 (string< "123" "abc")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 When the strings have different lengths, and they match up to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 length of @var{string1}, then the result is @code{t}. If they match up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 to the length of @var{string2}, the result is @code{nil}. A string of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 no characters is less than any other string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 (string< "" "abc")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 (string< "ab" "abc")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 (string< "abc" "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 (string< "abc" "ab")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 (string< "" "")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
452 @result{} nil
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 @defun string-lessp string1 string2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 @code{string-lessp} is another name for @code{string<}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 See also @code{compare-buffer-substrings} in @ref{Comparing Text}, for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 a way to compare text in buffers. The function @code{string-match},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 which matches a regular expression against a string, can be used
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 for a kind of string comparison; see @ref{Regexp Search}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
466 @node String Conversion, Modifying Strings, Text Comparison, Strings and Characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 @section Conversion of Characters and Strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 @cindex conversion of strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 This section describes functions for conversions between characters,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 strings and integers. @code{format} and @code{prin1-to-string}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 (@pxref{Output Functions}) can also convert Lisp objects into strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 @code{read-from-string} (@pxref{Input Functions}) can ``convert'' a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 string representation of a Lisp object into an object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 @xref{Documentation}, for functions that produce textual descriptions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 of text characters and general input events
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 (@code{single-key-description} and @code{text-char-description}). These
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 functions are used primarily for making help messages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 @defun char-to-string character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 @cindex character to string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 This function returns a new string with a length of one character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 The value of @var{character}, modulo 256, is used to initialize the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 element of the string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 This function is similar to @code{make-string} with an integer argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 of 1. (@xref{Creating Strings}.) This conversion can also be done with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 @code{format} using the @samp{%c} format specification.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (@xref{Formatting Strings}.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 (char-to-string ?x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 @result{} "x"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 (char-to-string (+ 256 ?x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 @result{} "x"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 (make-string 1 ?x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 @result{} "x"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 @defun string-to-char string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 @cindex string to character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 This function returns the first character in @var{string}. If the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 string is empty, the function returns 0. (Under XEmacs 19, the value is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 also 0 when the first character of @var{string} is the null character,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 @sc{ascii} code 0.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 (string-to-char "ABC")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 @result{} ?A ;; @r{Under XEmacs 20.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 @result{} 65 ;; @r{Under XEmacs 19.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 (string-to-char "xyz")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 @result{} ?x ;; @r{Under XEmacs 20.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 @result{} 120 ;; @r{Under XEmacs 19.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 (string-to-char "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 @result{} 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (string-to-char "\000")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 @result{} ?\^@ ;; @r{Under XEmacs 20.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 @result{} 0 ;; @r{Under XEmacs 20.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 This function may be eliminated in the future if it does not seem useful
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 enough to retain.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 @defun number-to-string number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 @cindex integer to string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 @cindex integer to decimal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 This function returns a string consisting of the printed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 representation of @var{number}, which may be an integer or a floating
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 point number. The value starts with a sign if the argument is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 negative.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 (number-to-string 256)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 @result{} "256"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 (number-to-string -23)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 @result{} "-23"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 (number-to-string -23.5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 @result{} "-23.5"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 @cindex int-to-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 @code{int-to-string} is a semi-obsolete alias for this function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 See also the function @code{format} in @ref{Formatting Strings}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 @defun string-to-number string &optional base
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 @cindex string to number
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
552 This function returns the numeric value represented by @var{string},
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
553 read in @var{base}. It skips spaces and tabs at the beginning of
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
554 @var{string}, then reads as much of @var{string} as it can interpret as
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
555 a number. (On some systems it ignores other whitespace at the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
556 beginning, not just spaces and tabs.) If the first character after the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
557 ignored whitespace is not a digit or a minus sign, this function returns
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
558 0.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 If @var{base} is not specified, it defaults to ten. With @var{base}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 other than ten, only integers can be read.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 (string-to-number "256")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 @result{} 256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 (string-to-number "25 is a perfect square.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 @result{} 25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 (string-to-number "X256")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 @result{} 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 (string-to-number "-4.5")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 @result{} -4.5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 (string-to-number "ffff" 16)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 @result{} 65535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 @findex string-to-int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 @code{string-to-int} is an obsolete alias for this function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
580 @node Modifying Strings, String Properties, String Conversion, Strings and Characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 @section Modifying Strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 @cindex strings, modifying
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 You can modify a string using the general array-modifying primitives.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 @xref{Arrays}. The function @code{aset} modifies a single character;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 the function @code{fillarray} sets all characters in the string to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 a specified character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 Each string has a tick counter that starts out at zero (when the string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 is created) and is incremented each time a change is made to that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 @defun string-modified-tick string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 This function returns the tick counter for @samp{string}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
597 @node String Properties, Formatting Strings, Modifying Strings, Strings and Characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 @section String Properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 @cindex string properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 @cindex properties of strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
602 Just as with symbols, extents, faces, and glyphs, you can attach
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 additional information to strings in the form of @dfn{string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 properties}. These differ from text properties, which are logically
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 attached to particular characters in the string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 To attach a property to a string, use @code{put}. To retrieve a property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 from a string, use @code{get}. You can also use @code{remprop} to remove
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
609 a property from a string and @code{object-plist} to retrieve a list of
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 all the properties in a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
612 @node Formatting Strings, Character Case, String Properties, Strings and Characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 @section Formatting Strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 @cindex formatting strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 @cindex strings, formatting them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 @dfn{Formatting} means constructing a string by substitution of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 computed values at various places in a constant string. This string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 controls how the other values are printed as well as where they appear;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 it is called a @dfn{format string}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 Formatting is often useful for computing messages to be displayed. In
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 fact, the functions @code{message} and @code{error} provide the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 formatting feature described here; they differ from @code{format} only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 in how they use the result of formatting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 @defun format string &rest objects
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 This function returns a new string that is made by copying
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
629 @var{string} and then replacing any format specification
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 in the copy with encodings of the corresponding @var{objects}. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 arguments @var{objects} are the computed values to be formatted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 @cindex @samp{%} in format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 @cindex format specification
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 A format specification is a sequence of characters beginning with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 @samp{%}. Thus, if there is a @samp{%d} in @var{string}, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 @code{format} function replaces it with the printed representation of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 one of the values to be formatted (one of the arguments @var{objects}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 For example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 (format "The value of fill-column is %d." fill-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 @result{} "The value of fill-column is 72."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 If @var{string} contains more than one format specification, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 format specifications correspond with successive values from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 @var{objects}. Thus, the first format specification in @var{string}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 uses the first such value, the second format specification uses the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 second such value, and so on. Any extra format specifications (those
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 for which there are no corresponding values) cause unpredictable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 behavior. Any extra values to be formatted are ignored.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 Certain format specifications require values of particular types.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 However, no error is signaled if the value actually supplied fails to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 have the expected type. Instead, the output is likely to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 meaningless.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 Here is a table of valid format specifications:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 @table @samp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 @item %s
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 Replace the specification with the printed representation of the object,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 made without quoting. Thus, strings are represented by their contents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 alone, with no @samp{"} characters, and symbols appear without @samp{\}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 characters. This is equivalent to printing the object with @code{princ}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 If there is no corresponding object, the empty string is used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 @item %S
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 Replace the specification with the printed representation of the object,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 made with quoting. Thus, strings are enclosed in @samp{"} characters,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 and @samp{\} characters appear where necessary before special characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 This is equivalent to printing the object with @code{prin1}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 If there is no corresponding object, the empty string is used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 @item %o
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 @cindex integer to octal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 Replace the specification with the base-eight representation of an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 @item %d
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 @itemx %i
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 Replace the specification with the base-ten representation of an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 @item %x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 @cindex integer to hexadecimal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 Replace the specification with the base-sixteen representation of an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 integer, using lowercase letters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 @item %X
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 @cindex integer to hexadecimal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 Replace the specification with the base-sixteen representation of an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 integer, using uppercase letters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700
4329
d9eb5ea14f65 Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1495
diff changeset
701 @item %b
d9eb5ea14f65 Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1495
diff changeset
702 @cindex integer to binary
d9eb5ea14f65 Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1495
diff changeset
703 Replace the specification with the base-two representation of an
d9eb5ea14f65 Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1495
diff changeset
704 integer.
d9eb5ea14f65 Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents: 1495
diff changeset
705
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 @item %c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 Replace the specification with the character which is the value given.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 @item %e
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 Replace the specification with the exponential notation for a floating
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 point number (e.g. @samp{7.85200e+03}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 @item %f
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 Replace the specification with the decimal-point notation for a floating
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 point number.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 @item %g
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 Replace the specification with notation for a floating point number,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 using a ``pretty format''. Either exponential notation or decimal-point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 notation will be used (usually whichever is shorter), and trailing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 zeroes are removed from the fractional part.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 @item %%
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 A single @samp{%} is placed in the string. This format specification is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 unusual in that it does not use a value. For example, @code{(format "%%
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 %d" 30)} returns @code{"% 30"}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 Any other format character results in an @samp{Invalid format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 operation} error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 Here are several examples:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 (format "The name of this buffer is %s." (buffer-name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 @result{} "The name of this buffer is strings.texi."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 (format "The buffer object prints as %s." (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 @result{} "The buffer object prints as #<buffer strings.texi>."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
742 (format "The octal value of %d is %o,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 and the hex value is %x." 18 18 18)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
744 @result{} "The octal value of 18 is 22,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 and the hex value is 12."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 There are many additional flags and specifications that can occur
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 between the @samp{%} and the format character, in the following order:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 @enumerate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 An optional repositioning specification, which is a positive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 integer followed by a @samp{$}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 Zero or more of the optional flag characters @samp{-}, @samp{+},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 @samp{ }, @samp{0}, and @samp{#}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 An asterisk (@samp{*}, meaning that the field width is now assumed to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 have been specified as an argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 An optional minimum field width.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 An optional precision, preceded by a @samp{.} character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 @end enumerate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 @cindex repositioning format arguments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 @cindex multilingual string formatting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 A @dfn{repositioning} specification changes which argument to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 @code{format} is used by the current and all following format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 specifications. Normally the first specification uses the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 argument, the second specification uses the second argument, etc. Using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 a repositioning specification, you can change this. By placing a number
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
779 @var{n} followed by a @samp{$} between the @samp{%} and the format
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
780 character, you cause the specification to use the @var{n}th argument.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
781 The next specification will use the @var{n}+1'th argument, etc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 For example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 (format "Can't find file `%s' in directory `%s'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 "ignatius.c" "loyola/")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 @result{} "Can't find file `ignatius.c' in directory `loyola/'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 (format "In directory `%2$s', the file `%1$s' was not found."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 "ignatius.c" "loyola/")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 @result{} "In directory `loyola/', the file `ignatius.c' was not found."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 (format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 "The numbers %d and %d are %1$x and %x in hex and %1$o and %o in octal."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 37 12)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 @result{} "The numbers 37 and 12 are 25 and c in hex and 45 and 14 in octal."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 As you can see, this lets you reprocess arguments more than once or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 reword a format specification (thereby moving the arguments around)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 without having to actually reorder the arguments. This is especially
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 useful in translating messages from one language to another: Different
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 languages use different word orders, and this sometimes entails changing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 the order of the arguments. By using repositioning specifications,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 this can be accomplished without having to embed knowledge of particular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 languages into the location in the program's code where the message is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 @cindex numeric prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 @cindex field width
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 @cindex padding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 All the specification characters allow an optional numeric prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 between the @samp{%} and the character, and following any repositioning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 specification or flag. The optional numeric prefix defines the minimum
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 width for the object. If the printed representation of the object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 contains fewer characters than this, then it is padded. The padding is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 normally on the left, but will be on the right if the @samp{-} flag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 character is given. The padding character is normally a space, but if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 the @samp{0} flag character is given, zeros are used for padding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 (format "%06d is padded on the left with zeros" 123)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 @result{} "000123 is padded on the left with zeros"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 (format "%-6d is padded on the right" 123)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 @result{} "123 is padded on the right"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 @code{format} never truncates an object's printed representation, no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 matter what width you specify. Thus, you can use a numeric prefix to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 specify a minimum spacing between columns with no risk of losing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 information.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 In the following three examples, @samp{%7s} specifies a minimum width
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 of 7. In the first case, the string inserted in place of @samp{%7s} has
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 only 3 letters, so 4 blank spaces are inserted for padding. In the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 second case, the string @code{"specification"} is 13 letters wide but is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 not truncated. In the third case, the padding is on the right.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
843 @smallexample
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 (format "The word `%7s' actually has %d letters in it."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 "foo" (length "foo"))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
847 @result{} "The word ` foo' actually has 3 letters in it."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 (format "The word `%7s' actually has %d letters in it."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
852 "specification" (length "specification"))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
853 @result{} "The word `specification' actually has 13 letters in it."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 (format "The word `%-7s' actually has %d letters in it."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 "foo" (length "foo"))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
859 @result{} "The word `foo ' actually has 3 letters in it."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 @cindex format precision
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 @cindex precision of formatted numbers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 After any minimum field width, a precision may be specified by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 preceding it with a @samp{.} character. The precision specifies the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 minimum number of digits to appear in @samp{%d}, @samp{%i}, @samp{%o},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 @samp{%x}, and @samp{%X} conversions (the number is padded on the left
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 with zeroes as necessary); the number of digits printed after the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 decimal point for @samp{%f}, @samp{%e}, and @samp{%E} conversions; the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 number of significant digits printed in @samp{%g} and @samp{%G}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 conversions; and the maximum number of non-padding characters printed in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 @samp{%s} and @samp{%S} conversions. The default precision for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 floating-point conversions is six.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 The other flag characters have the following meanings:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 The @samp{ } flag means prefix non-negative numbers with a space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 The @samp{+} flag means prefix non-negative numbers with a plus sign.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 The @samp{#} flag means print numbers in an alternate, more verbose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 format: octal numbers begin with zero; hex numbers begin with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 @samp{0x} or @samp{0X}; a decimal point is printed in @samp{%f},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 @samp{%e}, and @samp{%E} conversions even if no numbers are printed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 after it; and trailing zeroes are not omitted in @samp{%g} and @samp{%G}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 conversions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
894 @node Character Case, Case Tables, Formatting Strings, Strings and Characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 @section Character Case
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
896 @cindex upper case
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
897 @cindex lower case
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
898 @cindex character case
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 The character case functions change the case of single characters or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 of the contents of strings. The functions convert only alphabetic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 characters (the letters @samp{A} through @samp{Z} and @samp{a} through
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 @samp{z}); other characters are not altered. The functions do not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 modify the strings that are passed to them as arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 The examples below use the characters @samp{X} and @samp{x} which have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 @sc{ascii} codes 88 and 120 respectively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
909 @defun downcase string-or-char &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 This function converts a character or a string to lower case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 When the argument to @code{downcase} is a string, the function creates
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 and returns a new string in which each letter in the argument that is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 upper case is converted to lower case. When the argument to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 @code{downcase} is a character, @code{downcase} returns the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 corresponding lower case character. (This value is actually an integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 under XEmacs 19.) If the original character is lower case, or is not a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 letter, then the value equals the original character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
920 Optional second arg @var{buffer} specifies which buffer's case tables to
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
921 use, and defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
922
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 (downcase "The cat in the hat")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 @result{} "the cat in the hat"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 (downcase ?X)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 @result{} ?x ;; @r{Under XEmacs 20.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 @result{} 120 ;; @r{Under XEmacs 19.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
934 @defun upcase string-or-char &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 This function converts a character or a string to upper case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 When the argument to @code{upcase} is a string, the function creates
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 and returns a new string in which each letter in the argument that is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 lower case is converted to upper case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 When the argument to @code{upcase} is a character, @code{upcase} returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 the corresponding upper case character. (This value is actually an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 integer under XEmacs 19.) If the original character is upper case, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 is not a letter, then the value equals the original character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
946 Optional second arg @var{buffer} specifies which buffer's case tables to
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
947 use, and defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
948
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 (upcase "The cat in the hat")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 @result{} "THE CAT IN THE HAT"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 (upcase ?x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 @result{} ?X ;; @r{Under XEmacs 20.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 @result{} 88 ;; @r{Under XEmacs 19.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
959 @defun capitalize string-or-char &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 @cindex capitalization
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 This function capitalizes strings or characters. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 @var{string-or-char} is a string, the function creates and returns a new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 string, whose contents are a copy of @var{string-or-char} in which each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 word has been capitalized. This means that the first character of each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 word is converted to upper case, and the rest are converted to lower
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 The definition of a word is any sequence of consecutive characters that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 are assigned to the word constituent syntax class in the current syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 table (@pxref{Syntax Class Table}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 When the argument to @code{capitalize} is a character, @code{capitalize}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 has the same result as @code{upcase}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
975 Optional second arg @var{buffer} specifies which buffer's case tables to
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
976 use, and defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
977
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 (capitalize "The cat in the hat")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 @result{} "The Cat In The Hat"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 (capitalize "THE 77TH-HATTED CAT")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 @result{} "The 77th-Hatted Cat"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 (capitalize ?x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 @result{} ?X ;; @r{Under XEmacs 20.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 @result{} 88 ;; @r{Under XEmacs 19.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
993 @node Case Tables, Char Tables, Character Case, Strings and Characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 @section The Case Table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 You can customize case conversion by installing a special @dfn{case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 table}. A case table specifies the mapping between upper case and lower
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 case letters. It affects both the string and character case conversion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 functions (see the previous section) and those that apply to text in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 buffer (@pxref{Case Changes}). You need a case table if you are using a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 language which has letters other than the standard @sc{ascii} letters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 A case table is a list of this form:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 (@var{downcase} @var{upcase} @var{canonicalize} @var{equivalences})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 where each element is either @code{nil} or a string of length 256. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 element @var{downcase} says how to map each character to its lower-case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 equivalent. The element @var{upcase} maps each character to its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 upper-case equivalent. If lower and upper case characters are in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 one-to-one correspondence, use @code{nil} for @var{upcase}; then XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 deduces the upcase table from @var{downcase}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 For some languages, upper and lower case letters are not in one-to-one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 correspondence. There may be two different lower case letters with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 same upper case equivalent. In these cases, you need to specify the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 maps for both directions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 The element @var{canonicalize} maps each character to a canonical
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 equivalent; any two characters that are related by case-conversion have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 the same canonical equivalent character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 The element @var{equivalences} is a map that cyclicly permutes each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 equivalence class (of characters with the same canonical equivalent).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 (For ordinary @sc{ascii}, this would map @samp{a} into @samp{A} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 @samp{A} into @samp{a}, and likewise for each set of equivalent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 characters.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 When you construct a case table, you can provide @code{nil} for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 @var{canonicalize}; then Emacs fills in this string from @var{upcase}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 and @var{downcase}. You can also provide @code{nil} for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 @var{equivalences}; then Emacs fills in this string from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 @var{canonicalize}. In a case table that is actually in use, those
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 components are non-@code{nil}. Do not try to specify @var{equivalences}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 without also specifying @var{canonicalize}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 Each buffer has a case table. XEmacs also has a @dfn{standard case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 table} which is copied into each buffer when you create the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 Changing the standard case table doesn't affect any existing buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 Here are the functions for working with case tables:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 @defun case-table-p object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 This predicate returns non-@code{nil} if @var{object} is a valid case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1051 @defun set-standard-case-table case-table
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1052 This function makes @var{case-table} the standard case table, so that it
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1053 will apply to any buffers created subsequently.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 @defun standard-case-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 This returns the standard case table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1060 @defun current-case-table &optional buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1061 This function returns the case table of @var{buffer}, which defaults to
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1062 the current buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1065 @defun set-case-table case-table
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1066 This sets the current buffer's case table to @var{case-table}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 The following three functions are convenient subroutines for packages
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 that define non-@sc{ascii} character sets. They modify a string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 @var{downcase-table} provided as an argument; this should be a string to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 be used as the @var{downcase} part of a case table. They also modify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 the standard syntax table. @xref{Syntax Tables}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 @defun set-case-syntax-pair uc lc downcase-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 This function specifies a pair of corresponding letters, one upper case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 and one lower case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 @defun set-case-syntax-delims l r downcase-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 This function makes characters @var{l} and @var{r} a matching pair of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 case-invariant delimiters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 @defun set-case-syntax char syntax downcase-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 This function makes @var{char} case-invariant, with syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 @var{syntax}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 @deffn Command describe-buffer-case-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 This command displays a description of the contents of the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 buffer's case table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 @cindex ISO Latin 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 @pindex iso-syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 You can load the library @file{iso-syntax} to set up the standard syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 table and define a case table for the 8-bit ISO Latin 1 character set.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
1100 @node Char Tables, , Case Tables, Strings and Characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 @section The Char Table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 A char table is a table that maps characters (or ranges of characters)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 to values. Char tables are specialized for characters, only allowing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 particular sorts of ranges to be assigned values. Although this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 loses in generality, it makes for extremely fast (constant-time)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 lookups, and thus is feasible for applications that do an extremely
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 large number of lookups (e.g. scanning a buffer for a character in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 a particular syntax, where a lookup in the syntax table must occur
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 once per character).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 Note that char tables as a primitive type, and all of the functions in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 this section, exist only in XEmacs 20. In XEmacs 19, char tables are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 generally implemented using a vector of 256 elements.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 When @sc{mule} support exists, the types of ranges that can be assigned
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 values are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 all characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 an entire charset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 a single row in a two-octet charset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 a single character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 When @sc{mule} support is not present, the types of ranges that can be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 assigned values are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 all characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 a single character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 @defun char-table-p object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 This function returns non-@code{nil} if @var{object} is a char table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 * Char Table Types:: Char tables have different uses.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 * Working With Char Tables:: Creating and working with char tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
1149 @node Char Table Types, Working With Char Tables, Char Tables, Char Tables
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 @subsection Char Table Types
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 Each char table type is used for a different purpose and allows different
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 sorts of values. The different char table types are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 @table @code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 @item category
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 Used for category tables, which specify the regexp categories
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 that a character is in. The valid values are @code{nil} or a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 bit vector of 95 elements. Higher-level Lisp functions are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 provided for working with category tables. Currently categories
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 and category tables only exist when @sc{mule} support is present.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 @item char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 A generalized char table, for mapping from one character to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 another. Used for case tables, syntax matching tables,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 @code{keyboard-translate-table}, etc. The valid values are characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 @item generic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 An even more generalized char table, for mapping from a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 character to anything.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 @item display
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 Used for display tables, which specify how a particular character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 is to appear when displayed. #### Not yet implemented.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 @item syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 Used for syntax tables, which specify the syntax of a particular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 character. Higher-level Lisp functions are provided for
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4329
diff changeset
1175 working with syntax tables. The valid values are fixnums.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1178 @defun char-table-type char-table
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1179 This function returns the type of char table @var{char-table}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 @defun char-table-type-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 This function returns a list of the recognized char table types.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 @defun valid-char-table-type-p type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 This function returns @code{t} if @var{type} if a recognized char table type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5384
diff changeset
1190 @node Working With Char Tables, , Char Table Types, Char Tables
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 @subsection Working With Char Tables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 @defun make-char-table type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 This function makes a new, empty char table of type @var{type}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 @var{type} should be a symbol, one of @code{char}, @code{category},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 @code{display}, @code{generic}, or @code{syntax}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1199 @defun put-char-table range value char-table
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1200 This function sets the value for chars in @var{range} to be @var{value} in
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1201 @var{char-table}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 @var{range} specifies one or more characters to be affected and should be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 one of the following:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 @code{t} (all characters are affected)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 A charset (only allowed when @sc{mule} support is present)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 A vector of two elements: a two-octet charset and a row number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 (only allowed when @sc{mule} support is present)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 A single character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1218 @var{value} must be a value appropriate for the type of @var{char-table}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1221 @defun get-char-table character char-table
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1222 This function finds the value for @var{character} in @var{char-table}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1225 @defun get-range-char-table range char-table &optional multi
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1226 This function finds the value for a range in @var{char-table}. If there is
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 more than one value, @var{multi} is returned (defaults to @code{nil}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1230 @defun reset-char-table char-table
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1231 This function resets @var{char-table} to its default state.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1234 @defun map-char-table function char-table &optional range
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1235 This function maps @var{function} over entries in @var{char-table}, calling
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 it with two args, each key and value in the table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 @var{range} specifies a subrange to map over and is in the same format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 as the @var{range} argument to @code{put-range-table}. If omitted or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 @code{t}, it defaults to the entire table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 @defun valid-char-table-value-p value char-table-type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 This function returns non-@code{nil} if @var{value} is a valid value for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 @var{char-table-type}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 @defun check-valid-char-table-value value char-table-type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 This function signals an error if @var{value} is not a valid value for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 @var{char-table-type}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 @end defun