1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<h3 class="section">Case Conversion in Lisp</h3> <p>The character case functions change the case of single characters or of the contents of strings. The functions normally convert only alphabetic characters (the letters ‘<samp>A</samp>’ through ‘<samp>Z</samp>’ and ‘<samp>a</samp>’ through ‘<samp>z</samp>’, as well as non-<acronym>ASCII</acronym> letters); other characters are not altered. You can specify a different case conversion mapping by specifying a case table (see <a href="case-tables">Case Tables</a>). </p> <p>These functions do not modify the strings that are passed to them as arguments. </p> <p>The examples below use the characters ‘<samp>X</samp>’ and ‘<samp>x</samp>’ which have <acronym>ASCII</acronym> codes 88 and 120 respectively. </p> <dl> <dt id="downcase">Function: <strong>downcase</strong> <em>string-or-char</em>
</dt> <dd>
<p>This function converts <var>string-or-char</var>, which should be either a character or a string, to lower case. </p> <p>When <var>string-or-char</var> is a string, this function returns a new string in which each letter in the argument that is upper case is converted to lower case. When <var>string-or-char</var> is a character, this function returns the corresponding lower case character (an integer); if the original character is lower case, or is not a letter, the return value is equal to the original character. </p> <div class="example"> <pre class="example">(downcase "The cat in the hat")
⇒ "the cat in the hat"
(downcase ?X)
⇒ 120
</pre>
</div> </dd>
</dl> <dl> <dt id="upcase">Function: <strong>upcase</strong> <em>string-or-char</em>
</dt> <dd>
<p>This function converts <var>string-or-char</var>, which should be either a character or a string, to upper case. </p> <p>When <var>string-or-char</var> is a string, this function returns a new string in which each letter in the argument that is lower case is converted to upper case. When <var>string-or-char</var> is a character, this function returns the corresponding upper case character (an integer); if the original character is upper case, or is not a letter, the return value is equal to the original character. </p> <div class="example"> <pre class="example">(upcase "The cat in the hat")
⇒ "THE CAT IN THE HAT"
(upcase ?x)
⇒ 88
</pre>
</div> </dd>
</dl> <dl> <dt id="capitalize">Function: <strong>capitalize</strong> <em>string-or-char</em>
</dt> <dd>
<p>This function capitalizes strings or characters. If <var>string-or-char</var> is a string, the function returns a new string whose contents are a copy of <var>string-or-char</var> in which each word has been capitalized. This means that the first character of each word is converted to upper case, and the rest are converted to lower case. </p> <p>The definition of a word is any sequence of consecutive characters that are assigned to the word constituent syntax class in the current syntax table (see <a href="syntax-class-table">Syntax Class Table</a>). </p> <p>When <var>string-or-char</var> is a character, this function does the same thing as <code>upcase</code>. </p> <div class="example"> <pre class="example">(capitalize "The cat in the hat")
⇒ "The Cat In The Hat"
</pre>
<pre class="example">(capitalize "THE 77TH-HATTED CAT")
⇒ "The 77th-Hatted Cat"
</pre>
<pre class="example">(capitalize ?x)
⇒ 88
</pre>
</div> </dd>
</dl> <dl> <dt id="upcase-initials">Function: <strong>upcase-initials</strong> <em>string-or-char</em>
</dt> <dd>
<p>If <var>string-or-char</var> is a string, this function capitalizes the initials of the words in <var>string-or-char</var>, without altering any letters other than the initials. It returns a new string whose contents are a copy of <var>string-or-char</var>, in which each word has had its initial letter converted to upper case. </p> <p>The definition of a word is any sequence of consecutive characters that are assigned to the word constituent syntax class in the current syntax table (see <a href="syntax-class-table">Syntax Class Table</a>). </p> <p>When the argument to <code>upcase-initials</code> is a character, <code>upcase-initials</code> has the same result as <code>upcase</code>. </p> <div class="example"> <pre class="example">(upcase-initials "The CAT in the hAt")
⇒ "The CAT In The HAt"
</pre>
</div> </dd>
</dl> <p>Note that case conversion is not a one-to-one mapping of codepoints and length of the result may differ from length of the argument. Furthermore, because passing a character forces return type to be a character, functions are unable to perform proper substitution and result may differ compared to treating a one-character string. For example: </p> <div class="example"> <pre class="example">(upcase "fi") ; note: single character, ligature "fi"
⇒ "FI"
</pre>
<pre class="example">(upcase ?fi)
⇒ 64257 ; i.e. ?fi
</pre>
</div> <p>To avoid this, a character must first be converted into a string, using <code>string</code> function, before being passed to one of the casing functions. Of course, no assumptions on the length of the result may be made. </p> <p>Mapping for such special cases are taken from <code>special-uppercase</code>, <code>special-lowercase</code> and <code>special-titlecase</code> See <a href="character-properties">Character Properties</a>. </p> <p>See <a href="text-comparison">Text Comparison</a>, for functions that compare strings; some of them ignore case differences, or can optionally ignore case differences. </p><div class="_attribution">
<p class="_attribution-p">
Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
<a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Case-Conversion.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Case-Conversion.html</a>
</p>
</div>
|