annotate lispref/strings.texi @ 15723:d2cee951f37e

(w32_read_socket): Need to erase background immediately before repainting exposed region.
author Karl Heuer <kwzh@gnu.org>
date Tue, 16 Jul 1996 23:25:18 +0000
parents a4a1d7df2e7f
children 66d807bdc5b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6550
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 @c -*-texinfo-*-
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 @c This is part of the GNU Emacs Lisp Reference Manual.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 @c See the file elisp.texi for copying conditions.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 @setfilename ../info/strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 @node Strings and Characters, Lists, Numbers, Top
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 @comment node-name, next, previous, up
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 @chapter Strings and Characters
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 @cindex strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 @cindex character arrays
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 @cindex characters
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 @cindex bytes
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 A string in Emacs Lisp is an array that contains an ordered sequence
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 of characters. Strings are used as names of symbols, buffers, and
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 files, to send messages to users, to hold text being copied between
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 buffers, and for many other purposes. Because strings are so important,
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 Emacs Lisp has many functions expressly for manipulating them. Emacs
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 Lisp programs use strings more often than individual characters.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 @xref{Strings of Events}, for special considerations for strings of
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 keyboard character events.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 @menu
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 * Basics: String Basics. Basic properties of strings and characters.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 * Predicates for Strings:: Testing whether an object is a string or char.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 * Creating Strings:: Functions to allocate new strings.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 * Text Comparison:: Comparing characters or strings.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 * String Conversion:: Converting characters or strings and vice versa.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 * Formatting Strings:: @code{format}: Emacs's analog of @code{printf}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 * Character Case:: Case conversion functions.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 * Case Table:: Customizing case conversion.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 @end menu
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 @node String Basics
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 @section String and Character Basics
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 Strings in Emacs Lisp are arrays that contain an ordered sequence of
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 characters. Characters are represented in Emacs Lisp as integers;
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 whether an integer was intended as a character or not is determined only
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 by how it is used. Thus, strings really contain integers.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 The length of a string (like any array) is fixed and independent of
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 the string contents, and cannot be altered. Strings in Lisp are
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 @emph{not} terminated by a distinguished character code. (By contrast,
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 strings in C are terminated by a character with @sc{ASCII} code 0.)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 This means that any character, including the null character (@sc{ASCII}
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 code 0), is a valid element of a string.@refill
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 Since strings are considered arrays, you can operate on them with the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 general array functions. (@xref{Sequences Arrays Vectors}.) For
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 example, you can access or change individual characters in a string
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 using the functions @code{aref} and @code{aset} (@pxref{Array
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 Functions}).
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 Each character in a string is stored in a single byte. Therefore,
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 numbers not in the range 0 to 255 are truncated when stored into a
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 string. This means that a string takes up much less memory than a
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 vector of the same length.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 Sometimes key sequences are represented as strings. When a string is
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 a key sequence, string elements in the range 128 to 255 represent meta
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 characters (which are extremely large integers) rather than keyboard
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 events in the range 128 to 255.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 Strings cannot hold characters that have the hyper, super or alt
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 modifiers; they can hold @sc{ASCII} control characters, but no other
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 control characters. They do not distinguish case in @sc{ASCII} control
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 characters. @xref{Character Type}, for more information about
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 representation of meta and other modifiers for keyboard input
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 characters.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
12098
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
73 Strings are useful for holding regular expressions. You can also
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
74 match regular expressions against strings (@pxref{Regexp Search}). The
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
75 functions @code{match-string} (@pxref{Simple Match Data}) and
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
76 @code{replace-match} (@pxref{Replacing Match}) are useful for
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
77 decomposing and modifying strings based on regular expression matching.
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
78
6550
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 Like a buffer, a string can contain text properties for the characters
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 in it, as well as the characters themselves. @xref{Text Properties}.
12098
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
81 All the Lisp primitives that copy text from strings to buffers or other
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
82 strings also copy the properties of the characters being copied.
6550
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 @xref{Text}, for information about functions that display strings or
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 copy them into buffers. @xref{Character Type}, and @ref{String Type},
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 for information about the syntax of characters and strings.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 @node Predicates for Strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 @section The Predicates for Strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 For more information about general sequence and array predicates,
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 see @ref{Sequences Arrays Vectors}, and @ref{Arrays}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 @defun stringp object
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 This function returns @code{t} if @var{object} is a string, @code{nil}
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 otherwise.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 @defun char-or-string-p object
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 This function returns @code{t} if @var{object} is a string or a
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 character (i.e., an integer), @code{nil} otherwise.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 @node Creating Strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 @section Creating Strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 The following functions create strings, either from scratch, or by
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 putting strings together, or by taking them apart.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 @defun make-string count character
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 This function returns a string made up of @var{count} repetitions of
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 @var{character}. If @var{count} is negative, an error is signaled.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (make-string 5 ?x)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 @result{} "xxxxx"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (make-string 0 ?x)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 @result{} ""
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 Other functions to compare with this one include @code{char-to-string}
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (@pxref{String Conversion}), @code{make-vector} (@pxref{Vectors}), and
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 @code{make-list} (@pxref{Building Lists}).
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 @defun substring string start &optional end
12098
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
127 This function returns a new string which consists of those characters
6550
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 from @var{string} in the range from (and including) the character at the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 index @var{start} up to (but excluding) the character at the index
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 @var{end}. The first character is at index zero.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 @group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (substring "abcdefg" 0 3)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 @result{} "abc"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 @end group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 @noindent
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 Here the index for @samp{a} is 0, the index for @samp{b} is 1, and the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 index for @samp{c} is 2. Thus, three letters, @samp{abc}, are copied
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 from the string @code{"abcdefg"}. The index 3 marks the character
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 position up to which the substring is copied. The character whose index
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 is 3 is actually the fourth character in the string.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 A negative number counts from the end of the string, so that @minus{}1
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 signifies the index of the last character of the string. For example:
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 @group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (substring "abcdefg" -3 -1)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 @result{} "ef"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 @end group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 @noindent
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 In this example, the index for @samp{e} is @minus{}3, the index for
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 @samp{f} is @minus{}2, and the index for @samp{g} is @minus{}1.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 Therefore, @samp{e} and @samp{f} are included, and @samp{g} is excluded.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 When @code{nil} is used as an index, it stands for the length of the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 string. Thus,
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 @group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (substring "abcdefg" -3 nil)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 @result{} "efg"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 @end group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 Omitting the argument @var{end} is equivalent to specifying @code{nil}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 It follows that @code{(substring @var{string} 0)} returns a copy of all
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 of @var{string}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 @group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (substring "abcdefg" 0)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 @result{} "abcdefg"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 @end group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 @noindent
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 But we recommend @code{copy-sequence} for this purpose (@pxref{Sequence
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 Functions}).
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
12098
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
186 If the characters copied from @var{string} have text properties, the
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
187 properties are copied into the new string also. @xref{Text Properties}.
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
188
6550
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 A @code{wrong-type-argument} error is signaled if either @var{start} or
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 @var{end} is not an integer or @code{nil}. An @code{args-out-of-range}
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 error is signaled if @var{start} indicates a character following
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 @var{end}, or if either integer is out of range for @var{string}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 Contrast this function with @code{buffer-substring} (@pxref{Buffer
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 Contents}), which returns a string containing a portion of the text in
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 the current buffer. The beginning of a string is at index 0, but the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 beginning of a buffer is at index 1.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 @defun concat &rest sequences
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 @cindex copying strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 @cindex concatenating strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 This function returns a new string consisting of the characters in the
12098
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
204 arguments passed to it (along with their text properties, if any). The
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
205 arguments may be strings, lists of numbers, or vectors of numbers; they
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
206 are not themselves changed. If @code{concat} receives no arguments, it
a6eb5f12b0f3 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 12067
diff changeset
207 returns an empty string.
6550
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (concat "abc" "-def")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 @result{} "abc-def"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (concat "abc" (list 120 (+ 256 121)) [122])
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 @result{} "abcxyz"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 ;; @r{@code{nil} is an empty sequence.}
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (concat "abc" nil "-def")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 @result{} "abc-def"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (concat "The " "quick brown " "fox.")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 @result{} "The quick brown fox."
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (concat)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 @result{} ""
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 @noindent
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 The second example above shows how characters stored in strings are
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 taken modulo 256. In other words, each character in the string is
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 stored in one byte.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 The @code{concat} function always constructs a new string that is
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 not @code{eq} to any existing string.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 When an argument is an integer (not a sequence of integers), it is
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 converted to a string of digits making up the decimal printed
12067
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 11141
diff changeset
233 representation of the integer. @strong{Don't use this feature; we plan
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 11141
diff changeset
234 to eliminate it. If you already use this feature, change your programs
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 11141
diff changeset
235 now!} The proper way to convert an integer to a decimal number in this
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 11141
diff changeset
236 way is with @code{format} (@pxref{Formatting Strings}) or
11141
6f6c571ad0c0 Say not to use concat for integers.
Richard M. Stallman <rms@gnu.org>
parents: 8590
diff changeset
237 @code{number-to-string} (@pxref{String Conversion}).
6550
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 @group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (concat 137)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 @result{} "137"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (concat 54 321)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 @result{} "54321"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 @end group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 For information about other concatenation functions, see the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 description of @code{mapconcat} in @ref{Mapping Functions},
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 @code{vconcat} in @ref{Vectors}, and @code{append} in @ref{Building
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 Lists}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253
12282
586e3ea81792 updates for version 19.29 made by melissa; also needed to check out files
Melissa Weisshaus <melissa@gnu.org>
parents: 12098
diff changeset
254 @need 2000
6550
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 @node Text Comparison
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 @section Comparison of Characters and Strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 @cindex string equality
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 @defun char-equal character1 character2
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 This function returns @code{t} if the arguments represent the same
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 character, @code{nil} otherwise. This function ignores differences
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 in case if @code{case-fold-search} is non-@code{nil}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (char-equal ?x ?x)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 @result{} t
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (char-to-string (+ 256 ?x))
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 @result{} "x"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (char-equal ?x (+ 256 ?x))
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 @result{} t
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 @defun string= string1 string2
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 This function returns @code{t} if the characters of the two strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 match exactly; case is significant.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (string= "abc" "abc")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 @result{} t
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (string= "abc" "ABC")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 @result{} nil
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (string= "ab" "ABC")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 @result{} nil
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 @end example
12067
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 11141
diff changeset
286
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 11141
diff changeset
287 The function @code{string=} ignores the text properties of the
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 11141
diff changeset
288 two strings. To compare strings in a way that compares their text
73dc8205d259 *** empty log message ***
Karl Heuer <kwzh@gnu.org>
parents: 11141
diff changeset
289 properties also, use @code{equal} (@pxref{Equality Predicates}).
6550
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 @defun string-equal string1 string2
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 @code{string-equal} is another name for @code{string=}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 @cindex lexical comparison
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 @defun string< string1 string2
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 @c (findex string< causes problems for permuted index!!)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 This function compares two strings a character at a time. First it
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 scans both the strings at once to find the first pair of corresponding
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 characters that do not match. If the lesser character of those two is
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 the character from @var{string1}, then @var{string1} is less, and this
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 function returns @code{t}. If the lesser character is the one from
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 @var{string2}, then @var{string1} is greater, and this function returns
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 @code{nil}. If the two strings match entirely, the value is @code{nil}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 Pairs of characters are compared by their @sc{ASCII} codes. Keep in
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 mind that lower case letters have higher numeric values in the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 @sc{ASCII} character set than their upper case counterparts; numbers and
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 many punctuation characters have a lower numeric value than upper case
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 letters.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 @group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (string< "abc" "abd")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 @result{} t
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (string< "abd" "abc")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 @result{} nil
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (string< "123" "abc")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 @result{} t
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 @end group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 When the strings have different lengths, and they match up to the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 length of @var{string1}, then the result is @code{t}. If they match up
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 to the length of @var{string2}, the result is @code{nil}. A string of
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 no characters is less than any other string.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 @group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (string< "" "abc")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 @result{} t
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (string< "ab" "abc")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 @result{} t
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (string< "abc" "")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 @result{} nil
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (string< "abc" "ab")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 @result{} nil
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (string< "" "")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 @result{} nil
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 @end group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 @defun string-lessp string1 string2
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 @code{string-lessp} is another name for @code{string<}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 See also @code{compare-buffer-substrings} in @ref{Comparing Text}, for
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 a way to compare text in buffers. The function @code{string-match},
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 which matches a regular expression against a string, can be used
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 for a kind of string comparison; see @ref{Regexp Search}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 @node String Conversion
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 @comment node-name, next, previous, up
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 @section Conversion of Characters and Strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 @cindex conversion of strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 This section describes functions for conversions between characters,
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 strings and integers. @code{format} and @code{prin1-to-string}
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (@pxref{Output Functions}) can also convert Lisp objects into strings.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 @code{read-from-string} (@pxref{Input Functions}) can ``convert'' a
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 string representation of a Lisp object into an object.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 @xref{Documentation}, for functions that produce textual descriptions
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 of text characters and general input events
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (@code{single-key-description} and @code{text-char-description}). These
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 functions are used primarily for making help messages.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 @defun char-to-string character
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 @cindex character to string
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 This function returns a new string with a length of one character.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 The value of @var{character}, modulo 256, is used to initialize the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 element of the string.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 This function is similar to @code{make-string} with an integer argument
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 of 1. (@xref{Creating Strings}.) This conversion can also be done with
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 @code{format} using the @samp{%c} format specification.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (@xref{Formatting Strings}.)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (char-to-string ?x)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 @result{} "x"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (char-to-string (+ 256 ?x))
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 @result{} "x"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (make-string 1 ?x)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 @result{} "x"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 @defun string-to-char string
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 @cindex string to character
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 This function returns the first character in @var{string}. If the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 string is empty, the function returns 0. The value is also 0 when the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 first character of @var{string} is the null character, @sc{ASCII} code
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 0.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (string-to-char "ABC")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 @result{} 65
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (string-to-char "xyz")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 @result{} 120
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (string-to-char "")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 @result{} 0
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (string-to-char "\000")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 @result{} 0
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 This function may be eliminated in the future if it does not seem useful
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 enough to retain.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 @defun number-to-string number
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 @cindex integer to string
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 @cindex integer to decimal
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 This function returns a string consisting of the printed
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 representation of @var{number}, which may be an integer or a floating
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 point number. The value starts with a sign if the argument is
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 negative.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (number-to-string 256)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 @result{} "256"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (number-to-string -23)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 @result{} "-23"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (number-to-string -23.5)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 @result{} "-23.5"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 @cindex int-to-string
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 @code{int-to-string} is a semi-obsolete alias for this function.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 See also the function @code{format} in @ref{Formatting Strings}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 @defun string-to-number string
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 @cindex string to number
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 This function returns the numeric value of the characters in
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 @var{string}, read in base ten. It skips spaces and tabs at the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 beginning of @var{string}, then reads as much of @var{string} as it can
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 interpret as a number. (On some systems it ignores other whitespace at
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 the beginning, not just spaces and tabs.) If the first character after
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 the ignored whitespace is not a digit or a minus sign, this function
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 returns 0.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (string-to-number "256")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 @result{} 256
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (string-to-number "25 is a perfect square.")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 @result{} 25
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (string-to-number "X256")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 @result{} 0
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (string-to-number "-4.5")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 @result{} -4.5
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 @findex string-to-int
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 @code{string-to-int} is an obsolete alias for this function.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 @node Formatting Strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 @comment node-name, next, previous, up
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 @section Formatting Strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 @cindex formatting strings
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 @cindex strings, formatting them
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 @dfn{Formatting} means constructing a string by substitution of
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 computed values at various places in a constant string. This string
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 controls how the other values are printed as well as where they appear;
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 it is called a @dfn{format string}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 Formatting is often useful for computing messages to be displayed. In
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 fact, the functions @code{message} and @code{error} provide the same
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 formatting feature described here; they differ from @code{format} only
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 in how they use the result of formatting.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 @defun format string &rest objects
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 This function returns a new string that is made by copying
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 @var{string} and then replacing any format specification
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 in the copy with encodings of the corresponding @var{objects}. The
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 arguments @var{objects} are the computed values to be formatted.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 @cindex @samp{%} in format
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 @cindex format specification
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 A format specification is a sequence of characters beginning with a
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 @samp{%}. Thus, if there is a @samp{%d} in @var{string}, the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 @code{format} function replaces it with the printed representation of
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 one of the values to be formatted (one of the arguments @var{objects}).
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 For example:
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 @group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (format "The value of fill-column is %d." fill-column)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 @result{} "The value of fill-column is 72."
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 @end group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 If @var{string} contains more than one format specification, the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 format specifications correspond with successive values from
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 @var{objects}. Thus, the first format specification in @var{string}
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 uses the first such value, the second format specification uses the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 second such value, and so on. Any extra format specifications (those
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 for which there are no corresponding values) cause unpredictable
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 behavior. Any extra values to be formatted are ignored.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 Certain format specifications require values of particular types.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 However, no error is signaled if the value actually supplied fails to
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 have the expected type. Instead, the output is likely to be
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 meaningless.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 Here is a table of valid format specifications:
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 @table @samp
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 @item %s
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 Replace the specification with the printed representation of the object,
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 made without quoting. Thus, strings are represented by their contents
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 alone, with no @samp{"} characters, and symbols appear without @samp{\}
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 characters.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 If there is no corresponding object, the empty string is used.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 @item %S
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 Replace the specification with the printed representation of the object,
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 made with quoting. Thus, strings are enclosed in @samp{"} characters,
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 and @samp{\} characters appear where necessary before special characters.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 If there is no corresponding object, the empty string is used.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 @item %o
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 @cindex integer to octal
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 Replace the specification with the base-eight representation of an
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 integer.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 @item %d
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 Replace the specification with the base-ten representation of an
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 integer.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 @item %x
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 @cindex integer to hexadecimal
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 Replace the specification with the base-sixteen representation of an
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 integer.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 @item %c
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 Replace the specification with the character which is the value given.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 @item %e
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 Replace the specification with the exponential notation for a floating
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 point number.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 @item %f
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 Replace the specification with the decimal-point notation for a floating
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 point number.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 @item %g
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 Replace the specification with notation for a floating point number,
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 using either exponential notation or decimal-point notation whichever
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 is shorter.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 @item %%
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 A single @samp{%} is placed in the string. This format specification is
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 unusual in that it does not use a value. For example, @code{(format "%%
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 %d" 30)} returns @code{"% 30"}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 @end table
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 Any other format character results in an @samp{Invalid format
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 operation} error.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 Here are several examples:
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 @group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (format "The name of this buffer is %s." (buffer-name))
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 @result{} "The name of this buffer is strings.texi."
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 (format "The buffer object prints as %s." (current-buffer))
13228
a4a1d7df2e7f Fix format example.
Richard M. Stallman <rms@gnu.org>
parents: 12282
diff changeset
577 @result{} "The buffer object prints as strings.texi."
6550
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (format "The octal value of %d is %o,
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 and the hex value is %x." 18 18 18)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 @result{} "The octal value of 18 is 22,
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 and the hex value is 12."
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 @end group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 @cindex numeric prefix
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 @cindex field width
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 @cindex padding
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 All the specification characters allow an optional numeric prefix
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 between the @samp{%} and the character. The optional numeric prefix
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 defines the minimum width for the object. If the printed representation
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 of the object contains fewer characters than this, then it is padded.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 The padding is on the left if the prefix is positive (or starts with
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 zero) and on the right if the prefix is negative. The padding character
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 is normally a space, but if the numeric prefix starts with a zero, zeros
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 are used for padding.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 (format "%06d is padded on the left with zeros" 123)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 @result{} "000123 is padded on the left with zeros"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 (format "%-6d is padded on the right" 123)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 @result{} "123 is padded on the right"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 @code{format} never truncates an object's printed representation, no
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 matter what width you specify. Thus, you can use a numeric prefix to
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 specify a minimum spacing between columns with no risk of losing
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 information.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 In the following three examples, @samp{%7s} specifies a minimum width
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 of 7. In the first case, the string inserted in place of @samp{%7s} has
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 only 3 letters, so 4 blank spaces are inserted for padding. In the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 second case, the string @code{"specification"} is 13 letters wide but is
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 not truncated. In the third case, the padding is on the right.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 @smallexample
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 @group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 (format "The word `%7s' actually has %d letters in it."
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 "foo" (length "foo"))
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 @result{} "The word ` foo' actually has 3 letters in it."
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 @end group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 @group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 (format "The word `%7s' actually has %d letters in it."
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 "specification" (length "specification"))
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 @result{} "The word `specification' actually has 13 letters in it."
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 @end group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 @group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 (format "The word `%-7s' actually has %d letters in it."
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 "foo" (length "foo"))
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 @result{} "The word `foo ' actually has 3 letters in it."
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 @end group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 @end smallexample
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 @node Character Case
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 @comment node-name, next, previous, up
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 @section Character Case
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 @cindex upper case
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 @cindex lower case
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 @cindex character case
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 The character case functions change the case of single characters or
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 of the contents of strings. The functions convert only alphabetic
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 characters (the letters @samp{A} through @samp{Z} and @samp{a} through
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 @samp{z}); other characters are not altered. The functions do not
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 modify the strings that are passed to them as arguments.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 The examples below use the characters @samp{X} and @samp{x} which have
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 @sc{ASCII} codes 88 and 120 respectively.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 @defun downcase string-or-char
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 This function converts a character or a string to lower case.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 When the argument to @code{downcase} is a string, the function creates
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 and returns a new string in which each letter in the argument that is
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 upper case is converted to lower case. When the argument to
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 @code{downcase} is a character, @code{downcase} returns the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 corresponding lower case character. This value is an integer. If the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 original character is lower case, or is not a letter, then the value
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 equals the original character.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 (downcase "The cat in the hat")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 @result{} "the cat in the hat"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 (downcase ?X)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 @result{} 120
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 @defun upcase string-or-char
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 This function converts a character or a string to upper case.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 When the argument to @code{upcase} is a string, the function creates
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 and returns a new string in which each letter in the argument that is
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 lower case is converted to upper case.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 When the argument to @code{upcase} is a character, @code{upcase}
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 returns the corresponding upper case character. This value is an integer.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 If the original character is upper case, or is not a letter, then the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 value equals the original character.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 (upcase "The cat in the hat")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 @result{} "THE CAT IN THE HAT"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 (upcase ?x)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 @result{} 88
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 @defun capitalize string-or-char
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 @cindex capitalization
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696 This function capitalizes strings or characters. If
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 @var{string-or-char} is a string, the function creates and returns a new
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 string, whose contents are a copy of @var{string-or-char} in which each
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 word has been capitalized. This means that the first character of each
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 word is converted to upper case, and the rest are converted to lower
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701 case.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 The definition of a word is any sequence of consecutive characters that
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 are assigned to the word constituent syntax class in the current syntax
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 table (@xref{Syntax Class Table}).
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 When the argument to @code{capitalize} is a character, @code{capitalize}
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 has the same result as @code{upcase}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 (capitalize "The cat in the hat")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 @result{} "The Cat In The Hat"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 (capitalize "THE 77TH-HATTED CAT")
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 @result{} "The 77th-Hatted Cat"
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 @group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 (capitalize ?x)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 @result{} 88
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 @end group
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 @node Case Table
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 @section The Case Table
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 You can customize case conversion by installing a special @dfn{case
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 table}. A case table specifies the mapping between upper case and lower
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 case letters. It affects both the string and character case conversion
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 functions (see the previous section) and those that apply to text in the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 buffer (@pxref{Case Changes}). You need a case table if you are using a
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 language which has letters other than the standard @sc{ASCII} letters.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 A case table is a list of this form:
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 @example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 (@var{downcase} @var{upcase} @var{canonicalize} @var{equivalences})
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 @end example
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 @noindent
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 where each element is either @code{nil} or a string of length 256. The
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 element @var{downcase} says how to map each character to its lower-case
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 equivalent. The element @var{upcase} maps each character to its
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 upper-case equivalent. If lower and upper case characters are in
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 one-to-one correspondence, use @code{nil} for @var{upcase}; then Emacs
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 deduces the upcase table from @var{downcase}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 For some languages, upper and lower case letters are not in one-to-one
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 correspondence. There may be two different lower case letters with the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 same upper case equivalent. In these cases, you need to specify the
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 maps for both directions.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 The element @var{canonicalize} maps each character to a canonical
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 equivalent; any two characters that are related by case-conversion have
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 the same canonical equivalent character.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 The element @var{equivalences} is a map that cyclicly permutes each
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 equivalence class (of characters with the same canonical equivalent).
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 (For ordinary @sc{ASCII}, this would map @samp{a} into @samp{A} and
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 @samp{A} into @samp{a}, and likewise for each set of equivalent
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 characters.)
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762
6938
782646fc7505 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6550
diff changeset
763 When you construct a case table, you can provide @code{nil} for
782646fc7505 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6550
diff changeset
764 @var{canonicalize}; then Emacs fills in this string from @var{upcase}
782646fc7505 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6550
diff changeset
765 and @var{downcase}. You can also provide @code{nil} for
782646fc7505 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6550
diff changeset
766 @var{equivalences}; then Emacs fills in this string from
782646fc7505 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6550
diff changeset
767 @var{canonicalize}. In a case table that is actually in use, those
782646fc7505 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6550
diff changeset
768 components are non-@code{nil}. Do not try to specify @var{equivalences}
782646fc7505 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6550
diff changeset
769 without also specifying @var{canonicalize}.
6550
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
770
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 Each buffer has a case table. Emacs also has a @dfn{standard case
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 table} which is copied into each buffer when you create the buffer.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 Changing the standard case table doesn't affect any existing buffers.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 Here are the functions for working with case tables:
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 @defun case-table-p object
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 This predicate returns non-@code{nil} if @var{object} is a valid case
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 table.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 @defun set-standard-case-table table
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 This function makes @var{table} the standard case table, so that it will
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 apply to any buffers created subsequently.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 @defun standard-case-table
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788 This returns the standard case table.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791 @defun current-case-table
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 This function returns the current buffer's case table.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 @defun set-case-table table
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 This sets the current buffer's case table to @var{table}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 The following three functions are convenient subroutines for packages
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 that define non-@sc{ASCII} character sets. They modify a string
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801 @var{downcase-table} provided as an argument; this should be a string to
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802 be used as the @var{downcase} part of a case table. They also modify
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 the standard syntax table. @xref{Syntax Tables}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 @defun set-case-syntax-pair uc lc downcase-table
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806 This function specifies a pair of corresponding letters, one upper case
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
807 and one lower case.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
810 @defun set-case-syntax-delims l r downcase-table
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 This function makes characters @var{l} and @var{r} a matching pair of
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 case-invariant delimiters.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815 @defun set-case-syntax char syntax downcase-table
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 This function makes @var{char} case-invariant, with syntax
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817 @var{syntax}.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
818 @end defun
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820 @deffn Command describe-buffer-case-table
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821 This command displays a description of the contents of the current
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822 buffer's case table.
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 @end deffn
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825 @cindex ISO Latin 1
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826 @pindex iso-syntax
e3f5cba23198 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827 You can load the library @file{iso-syntax} to set up the standard syntax
8590
c8fc8ea87b8b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 6938
diff changeset
828 table and define a case table for the 8-bit ISO Latin 1 character set.