/usr/share/doc/glibc-doc/html/libc_4.html is in glibc-doc 2.15-0ubuntu10.18.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- This file documents the GNU C library.
This is Edition 0.13, last updated 2011-07-19,
of The GNU C Library Reference Manual, for version
2.14 (Ubuntu EGLIBC 2.15-0ubuntu10.18) .
Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002,
2003, 2007, 2008, 2010, 2011 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Free Software Needs Free Documentation"
and "GNU Lesser General Public License", the Front-Cover texts being
"A GNU Manual", and with the Back-Cover Texts as in (a) below. A
copy of the license is included in the section entitled "GNU Free
Documentation License".
(a) The FSF's Back-Cover Text is: "You have the freedom to
copy and modify this GNU manual. Buying copies from the FSF
supports it in developing GNU and promoting software freedom."
-->
<!-- Created on March 23, 2017 by texi2html 1.82
texi2html was written by:
Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Many creative people.
Send bugs and suggestions to <texi2html-bug@nongnu.org>
-->
<head>
<title>The GNU C Library: 4. Character Handling</title>
<meta name="description" content="The GNU C Library: 4. Character Handling">
<meta name="keywords" content="The GNU C Library: 4. Character Handling">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.82">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.roman {font-family:serif; font-weight:normal;}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Character-Handling"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="libc_3.html#Page-Lock-Functions" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Classification-of-Characters" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc_3.html#Memory" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_5.html#String-and-Array-Utilities" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Character-Handling-1"></a>
<h1 class="chapter">4. Character Handling</h1>
<p>Programs that work with characters and strings often need to classify a
character—is it alphabetic, is it a digit, is it whitespace, and so
on—and perform case conversion operations on characters. The
functions in the header file ‘<tt>ctype.h</tt>’ are provided for this
purpose.
<a name="index-ctype_002eh"></a>
</p>
<p>Since the choice of locale and character set can alter the
classifications of particular character codes, all of these functions
are affected by the current locale. (More precisely, they are affected
by the locale currently selected for character classification—the
<code>LC_CTYPE</code> category; see <a href="libc_7.html#Locale-Categories">Categories of Activities that Locales Affect</a>.)
</p>
<p>The ISO C standard specifies two different sets of functions. The
one set works on <code>char</code> type characters, the other one on
<code>wchar_t</code> wide characters (see section <a href="libc_6.html#Extended-Char-Intro">Introduction to Extended Characters</a>).
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Classification-of-Characters">4.1 Classification of Characters</a></td><td> </td><td align="left" valign="top"> Testing whether characters are
letters, digits, punctuation, etc.
</td></tr>
<tr><td align="left" valign="top"><a href="#Case-Conversion">4.2 Case Conversion</a></td><td> </td><td align="left" valign="top"> Case mapping, and the like.
</td></tr>
<tr><td align="left" valign="top"><a href="#Classification-of-Wide-Characters">4.3 Character class determination for wide characters</a></td><td> </td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Using-Wide-Char-Classes">4.4 Notes on using the wide character classes</a></td><td> </td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Wide-Character-Case-Conversion">4.5 Mapping of wide characters.</a></td><td> </td><td align="left" valign="top"></td></tr>
</table>
<hr size="6">
<a name="Classification-of-Characters"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Character-Handling" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Case-Conversion" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Character-Handling" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Character-Handling" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_5.html#String-and-Array-Utilities" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Classification-of-Characters-1"></a>
<h2 class="section">4.1 Classification of Characters</h2>
<a name="index-character-testing"></a>
<a name="index-classification-of-characters"></a>
<a name="index-predicates-on-characters"></a>
<a name="index-character-predicates"></a>
<p>This section explains the library functions for classifying characters.
For example, <code>isalpha</code> is the function to test for an alphabetic
character. It takes one argument, the character to test, and returns a
nonzero integer if the character is alphabetic, and zero otherwise. You
would use it like this:
</p>
<table><tr><td> </td><td><pre class="smallexample">if (isalpha (c))
printf ("The character `%c' is alphabetic.\n", c);
</pre></td></tr></table>
<p>Each of the functions in this section tests for membership in a
particular class of characters; each has a name starting with ‘<samp>is</samp>’.
Each of them takes one argument, which is a character to test, and
returns an <code>int</code> which is treated as a boolean value. The
character argument is passed as an <code>int</code>, and it may be the
constant value <code>EOF</code> instead of a real character.
</p>
<p>The attributes of any given character can vary between locales.
See section <a href="libc_7.html#Locales">Locales and Internationalization</a>, for more information on locales.
</p>
<p>These functions are declared in the header file ‘<tt>ctype.h</tt>’.
<a name="index-ctype_002eh-1"></a>
</p>
<a name="index-lower_002dcase-character"></a>
<dl>
<dt><a name="index-islower"></a><u>Function:</u> int <b>islower</b><i> (int <var>c</var>)</i></dt>
<dd><p>Returns true if <var>c</var> is a lower-case letter. The letter need not be
from the Latin alphabet, any alphabet representable is valid.
</p></dd></dl>
<a name="index-upper_002dcase-character"></a>
<dl>
<dt><a name="index-isupper"></a><u>Function:</u> int <b>isupper</b><i> (int <var>c</var>)</i></dt>
<dd><p>Returns true if <var>c</var> is an upper-case letter. The letter need not be
from the Latin alphabet, any alphabet representable is valid.
</p></dd></dl>
<a name="index-alphabetic-character"></a>
<dl>
<dt><a name="index-isalpha"></a><u>Function:</u> int <b>isalpha</b><i> (int <var>c</var>)</i></dt>
<dd><p>Returns true if <var>c</var> is an alphabetic character (a letter). If
<code>islower</code> or <code>isupper</code> is true of a character, then
<code>isalpha</code> is also true.
</p>
<p>In some locales, there may be additional characters for which
<code>isalpha</code> is true—letters which are neither upper case nor lower
case. But in the standard <code>"C"</code> locale, there are no such
additional characters.
</p></dd></dl>
<a name="index-digit-character"></a>
<a name="index-decimal-digit-character"></a>
<dl>
<dt><a name="index-isdigit"></a><u>Function:</u> int <b>isdigit</b><i> (int <var>c</var>)</i></dt>
<dd><p>Returns true if <var>c</var> is a decimal digit (‘<samp>0</samp>’ through ‘<samp>9</samp>’).
</p></dd></dl>
<a name="index-alphanumeric-character"></a>
<dl>
<dt><a name="index-isalnum"></a><u>Function:</u> int <b>isalnum</b><i> (int <var>c</var>)</i></dt>
<dd><p>Returns true if <var>c</var> is an alphanumeric character (a letter or
number); in other words, if either <code>isalpha</code> or <code>isdigit</code> is
true of a character, then <code>isalnum</code> is also true.
</p></dd></dl>
<a name="index-hexadecimal-digit-character"></a>
<dl>
<dt><a name="index-isxdigit"></a><u>Function:</u> int <b>isxdigit</b><i> (int <var>c</var>)</i></dt>
<dd><p>Returns true if <var>c</var> is a hexadecimal digit.
Hexadecimal digits include the normal decimal digits ‘<samp>0</samp>’ through
‘<samp>9</samp>’ and the letters ‘<samp>A</samp>’ through ‘<samp>F</samp>’ and
‘<samp>a</samp>’ through ‘<samp>f</samp>’.
</p></dd></dl>
<a name="index-punctuation-character"></a>
<dl>
<dt><a name="index-ispunct"></a><u>Function:</u> int <b>ispunct</b><i> (int <var>c</var>)</i></dt>
<dd><p>Returns true if <var>c</var> is a punctuation character.
This means any printing character that is not alphanumeric or a space
character.
</p></dd></dl>
<a name="index-whitespace-character"></a>
<dl>
<dt><a name="index-isspace"></a><u>Function:</u> int <b>isspace</b><i> (int <var>c</var>)</i></dt>
<dd><p>Returns true if <var>c</var> is a <em>whitespace</em> character. In the standard
<code>"C"</code> locale, <code>isspace</code> returns true for only the standard
whitespace characters:
</p>
<dl compact="compact">
<dt> <code>' '</code></dt>
<dd><p>space
</p>
</dd>
<dt> <code>'\f'</code></dt>
<dd><p>formfeed
</p>
</dd>
<dt> <code>'\n'</code></dt>
<dd><p>newline
</p>
</dd>
<dt> <code>'\r'</code></dt>
<dd><p>carriage return
</p>
</dd>
<dt> <code>'\t'</code></dt>
<dd><p>horizontal tab
</p>
</dd>
<dt> <code>'\v'</code></dt>
<dd><p>vertical tab
</p></dd>
</dl>
</dd></dl>
<a name="index-blank-character"></a>
<dl>
<dt><a name="index-isblank"></a><u>Function:</u> int <b>isblank</b><i> (int <var>c</var>)</i></dt>
<dd><p>Returns true if <var>c</var> is a blank character; that is, a space or a tab.
This function was originally a GNU extension, but was added in ISO C99.
</p></dd></dl>
<a name="index-graphic-character"></a>
<dl>
<dt><a name="index-isgraph"></a><u>Function:</u> int <b>isgraph</b><i> (int <var>c</var>)</i></dt>
<dd><p>Returns true if <var>c</var> is a graphic character; that is, a character
that has a glyph associated with it. The whitespace characters are not
considered graphic.
</p></dd></dl>
<a name="index-printing-character"></a>
<dl>
<dt><a name="index-isprint"></a><u>Function:</u> int <b>isprint</b><i> (int <var>c</var>)</i></dt>
<dd><p>Returns true if <var>c</var> is a printing character. Printing characters
include all the graphic characters, plus the space (‘<samp> </samp>’) character.
</p></dd></dl>
<a name="index-control-character"></a>
<dl>
<dt><a name="index-iscntrl"></a><u>Function:</u> int <b>iscntrl</b><i> (int <var>c</var>)</i></dt>
<dd><p>Returns true if <var>c</var> is a control character (that is, a character that
is not a printing character).
</p></dd></dl>
<a name="index-ASCII-character"></a>
<dl>
<dt><a name="index-isascii"></a><u>Function:</u> int <b>isascii</b><i> (int <var>c</var>)</i></dt>
<dd><p>Returns true if <var>c</var> is a 7-bit <code>unsigned char</code> value that fits
into the US/UK ASCII character set. This function is a BSD extension
and is also an SVID extension.
</p></dd></dl>
<hr size="6">
<a name="Case-Conversion"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Classification-of-Characters" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Classification-of-Wide-Characters" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Character-Handling" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Character-Handling" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_5.html#String-and-Array-Utilities" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Case-Conversion-1"></a>
<h2 class="section">4.2 Case Conversion</h2>
<a name="index-character-case-conversion"></a>
<a name="index-case-conversion-of-characters"></a>
<a name="index-converting-case-of-characters"></a>
<p>This section explains the library functions for performing conversions
such as case mappings on characters. For example, <code>toupper</code>
converts any character to upper case if possible. If the character
can’t be converted, <code>toupper</code> returns it unchanged.
</p>
<p>These functions take one argument of type <code>int</code>, which is the
character to convert, and return the converted character as an
<code>int</code>. If the conversion is not applicable to the argument given,
the argument is returned unchanged.
</p>
<p><strong>Compatibility Note:</strong> In pre-ISO C dialects, instead of
returning the argument unchanged, these functions may fail when the
argument is not suitable for the conversion. Thus for portability, you
may need to write <code>islower(c) ? toupper(c) : c</code> rather than just
<code>toupper(c)</code>.
</p>
<p>These functions are declared in the header file ‘<tt>ctype.h</tt>’.
<a name="index-ctype_002eh-2"></a>
</p>
<dl>
<dt><a name="index-tolower"></a><u>Function:</u> int <b>tolower</b><i> (int <var>c</var>)</i></dt>
<dd><p>If <var>c</var> is an upper-case letter, <code>tolower</code> returns the corresponding
lower-case letter. If <var>c</var> is not an upper-case letter,
<var>c</var> is returned unchanged.
</p></dd></dl>
<dl>
<dt><a name="index-toupper"></a><u>Function:</u> int <b>toupper</b><i> (int <var>c</var>)</i></dt>
<dd><p>If <var>c</var> is a lower-case letter, <code>toupper</code> returns the corresponding
upper-case letter. Otherwise <var>c</var> is returned unchanged.
</p></dd></dl>
<dl>
<dt><a name="index-toascii"></a><u>Function:</u> int <b>toascii</b><i> (int <var>c</var>)</i></dt>
<dd><p>This function converts <var>c</var> to a 7-bit <code>unsigned char</code> value
that fits into the US/UK ASCII character set, by clearing the high-order
bits. This function is a BSD extension and is also an SVID extension.
</p></dd></dl>
<dl>
<dt><a name="index-_005ftolower"></a><u>Function:</u> int <b>_tolower</b><i> (int <var>c</var>)</i></dt>
<dd><p>This is identical to <code>tolower</code>, and is provided for compatibility
with the SVID. See section <a href="libc_1.html#SVID">SVID (The System V Interface Description)</a>.
</p></dd></dl>
<dl>
<dt><a name="index-_005ftoupper"></a><u>Function:</u> int <b>_toupper</b><i> (int <var>c</var>)</i></dt>
<dd><p>This is identical to <code>toupper</code>, and is provided for compatibility
with the SVID.
</p></dd></dl>
<hr size="6">
<a name="Classification-of-Wide-Characters"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Case-Conversion" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Using-Wide-Char-Classes" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Character-Handling" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Character-Handling" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_5.html#String-and-Array-Utilities" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Character-class-determination-for-wide-characters"></a>
<h2 class="section">4.3 Character class determination for wide characters</h2>
<p>Amendment 1 to ISO C90 defines functions to classify wide
characters. Although the original ISO C90 standard already defined
the type <code>wchar_t</code>, no functions operating on them were defined.
</p>
<p>The general design of the classification functions for wide characters
is more general. It allows extensions to the set of available
classifications, beyond those which are always available. The POSIX
standard specifies how extensions can be made, and this is already
implemented in the GNU C library implementation of the <code>localedef</code>
program.
</p>
<p>The character class functions are normally implemented with bitsets,
with a bitset per character. For a given character, the appropriate
bitset is read from a table and a test is performed as to whether a
certain bit is set. Which bit is tested for is determined by the
class.
</p>
<p>For the wide character classification functions this is made visible.
There is a type classification type defined, a function to retrieve this
value for a given class, and a function to test whether a given
character is in this class, using the classification value. On top of
this the normal character classification functions as used for
<code>char</code> objects can be defined.
</p>
<dl>
<dt><a name="index-wctype_005ft"></a><u>Data type:</u> <b>wctype_t</b></dt>
<dd><p>The <code>wctype_t</code> can hold a value which represents a character class.
The only defined way to generate such a value is by using the
<code>wctype</code> function.
</p>
<a name="index-wctype_002eh"></a>
<p>This type is defined in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<dl>
<dt><a name="index-wctype"></a><u>Function:</u> wctype_t <b>wctype</b><i> (const char *<var>property</var>)</i></dt>
<dd><p>The <code>wctype</code> returns a value representing a class of wide
characters which is identified by the string <var>property</var>. Beside
some standard properties each locale can define its own ones. In case
no property with the given name is known for the current locale
selected for the <code>LC_CTYPE</code> category, the function returns zero.
</p>
<p>The properties known in every locale are:
</p>
<table>
<tr><td width="25%"><code>"alnum"</code></td><td width="25%"><code>"alpha"</code></td><td width="25%"><code>"cntrl"</code></td><td width="25%"><code>"digit"</code></td></tr>
<tr><td width="25%"><code>"graph"</code></td><td width="25%"><code>"lower"</code></td><td width="25%"><code>"print"</code></td><td width="25%"><code>"punct"</code></td></tr>
<tr><td width="25%"><code>"space"</code></td><td width="25%"><code>"upper"</code></td><td width="25%"><code>"xdigit"</code></td></tr>
</table>
<a name="index-wctype_002eh-1"></a>
<p>This function is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<p>To test the membership of a character to one of the non-standard classes
the ISO C standard defines a completely new function.
</p>
<dl>
<dt><a name="index-iswctype"></a><u>Function:</u> int <b>iswctype</b><i> (wint_t <var>wc</var>, wctype_t <var>desc</var>)</i></dt>
<dd><p>This function returns a nonzero value if <var>wc</var> is in the character
class specified by <var>desc</var>. <var>desc</var> must previously be returned
by a successful call to <code>wctype</code>.
</p>
<a name="index-wctype_002eh-2"></a>
<p>This function is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<p>To make it easier to use the commonly-used classification functions,
they are defined in the C library. There is no need to use
<code>wctype</code> if the property string is one of the known character
classes. In some situations it is desirable to construct the property
strings, and then it is important that <code>wctype</code> can also handle the
standard classes.
</p>
<a name="index-alphanumeric-character-1"></a>
<dl>
<dt><a name="index-iswalnum"></a><u>Function:</u> int <b>iswalnum</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>This function returns a nonzero value if <var>wc</var> is an alphanumeric
character (a letter or number); in other words, if either <code>iswalpha</code>
or <code>iswdigit</code> is true of a character, then <code>iswalnum</code> is also
true.
</p>
<p>This function can be implemented using
</p>
<table><tr><td> </td><td><pre class="smallexample">iswctype (wc, wctype ("alnum"))
</pre></td></tr></table>
<a name="index-wctype_002eh-3"></a>
<p>It is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<a name="index-alphabetic-character-1"></a>
<dl>
<dt><a name="index-iswalpha"></a><u>Function:</u> int <b>iswalpha</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>Returns true if <var>wc</var> is an alphabetic character (a letter). If
<code>iswlower</code> or <code>iswupper</code> is true of a character, then
<code>iswalpha</code> is also true.
</p>
<p>In some locales, there may be additional characters for which
<code>iswalpha</code> is true—letters which are neither upper case nor lower
case. But in the standard <code>"C"</code> locale, there are no such
additional characters.
</p>
<p>This function can be implemented using
</p>
<table><tr><td> </td><td><pre class="smallexample">iswctype (wc, wctype ("alpha"))
</pre></td></tr></table>
<a name="index-wctype_002eh-4"></a>
<p>It is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<a name="index-control-character-1"></a>
<dl>
<dt><a name="index-iswcntrl"></a><u>Function:</u> int <b>iswcntrl</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>Returns true if <var>wc</var> is a control character (that is, a character that
is not a printing character).
</p>
<p>This function can be implemented using
</p>
<table><tr><td> </td><td><pre class="smallexample">iswctype (wc, wctype ("cntrl"))
</pre></td></tr></table>
<a name="index-wctype_002eh-5"></a>
<p>It is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<a name="index-digit-character-1"></a>
<dl>
<dt><a name="index-iswdigit"></a><u>Function:</u> int <b>iswdigit</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>Returns true if <var>wc</var> is a digit (e.g., ‘<samp>0</samp>’ through ‘<samp>9</samp>’).
Please note that this function does not only return a nonzero value for
<em>decimal</em> digits, but for all kinds of digits. A consequence is
that code like the following will <strong>not</strong> work unconditionally for
wide characters:
</p>
<table><tr><td> </td><td><pre class="smallexample">n = 0;
while (iswdigit (*wc))
{
n *= 10;
n += *wc++ - L'0';
}
</pre></td></tr></table>
<p>This function can be implemented using
</p>
<table><tr><td> </td><td><pre class="smallexample">iswctype (wc, wctype ("digit"))
</pre></td></tr></table>
<a name="index-wctype_002eh-6"></a>
<p>It is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<a name="index-graphic-character-1"></a>
<dl>
<dt><a name="index-iswgraph"></a><u>Function:</u> int <b>iswgraph</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>Returns true if <var>wc</var> is a graphic character; that is, a character
that has a glyph associated with it. The whitespace characters are not
considered graphic.
</p>
<p>This function can be implemented using
</p>
<table><tr><td> </td><td><pre class="smallexample">iswctype (wc, wctype ("graph"))
</pre></td></tr></table>
<a name="index-wctype_002eh-7"></a>
<p>It is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<a name="index-lower_002dcase-character-1"></a>
<dl>
<dt><a name="index-iswlower"></a><u>Function:</u> int <b>iswlower</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>Returns true if <var>wc</var> is a lower-case letter. The letter need not be
from the Latin alphabet, any alphabet representable is valid.
</p>
<p>This function can be implemented using
</p>
<table><tr><td> </td><td><pre class="smallexample">iswctype (wc, wctype ("lower"))
</pre></td></tr></table>
<a name="index-wctype_002eh-8"></a>
<p>It is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<a name="index-printing-character-1"></a>
<dl>
<dt><a name="index-iswprint"></a><u>Function:</u> int <b>iswprint</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>Returns true if <var>wc</var> is a printing character. Printing characters
include all the graphic characters, plus the space (‘<samp> </samp>’) character.
</p>
<p>This function can be implemented using
</p>
<table><tr><td> </td><td><pre class="smallexample">iswctype (wc, wctype ("print"))
</pre></td></tr></table>
<a name="index-wctype_002eh-9"></a>
<p>It is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<a name="index-punctuation-character-1"></a>
<dl>
<dt><a name="index-iswpunct"></a><u>Function:</u> int <b>iswpunct</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>Returns true if <var>wc</var> is a punctuation character.
This means any printing character that is not alphanumeric or a space
character.
</p>
<p>This function can be implemented using
</p>
<table><tr><td> </td><td><pre class="smallexample">iswctype (wc, wctype ("punct"))
</pre></td></tr></table>
<a name="index-wctype_002eh-10"></a>
<p>It is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<a name="index-whitespace-character-1"></a>
<dl>
<dt><a name="index-iswspace"></a><u>Function:</u> int <b>iswspace</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>Returns true if <var>wc</var> is a <em>whitespace</em> character. In the standard
<code>"C"</code> locale, <code>iswspace</code> returns true for only the standard
whitespace characters:
</p>
<dl compact="compact">
<dt> <code>L' '</code></dt>
<dd><p>space
</p>
</dd>
<dt> <code>L'\f'</code></dt>
<dd><p>formfeed
</p>
</dd>
<dt> <code>L'\n'</code></dt>
<dd><p>newline
</p>
</dd>
<dt> <code>L'\r'</code></dt>
<dd><p>carriage return
</p>
</dd>
<dt> <code>L'\t'</code></dt>
<dd><p>horizontal tab
</p>
</dd>
<dt> <code>L'\v'</code></dt>
<dd><p>vertical tab
</p></dd>
</dl>
<p>This function can be implemented using
</p>
<table><tr><td> </td><td><pre class="smallexample">iswctype (wc, wctype ("space"))
</pre></td></tr></table>
<a name="index-wctype_002eh-11"></a>
<p>It is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<a name="index-upper_002dcase-character-1"></a>
<dl>
<dt><a name="index-iswupper"></a><u>Function:</u> int <b>iswupper</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>Returns true if <var>wc</var> is an upper-case letter. The letter need not be
from the Latin alphabet, any alphabet representable is valid.
</p>
<p>This function can be implemented using
</p>
<table><tr><td> </td><td><pre class="smallexample">iswctype (wc, wctype ("upper"))
</pre></td></tr></table>
<a name="index-wctype_002eh-12"></a>
<p>It is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<a name="index-hexadecimal-digit-character-1"></a>
<dl>
<dt><a name="index-iswxdigit"></a><u>Function:</u> int <b>iswxdigit</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>Returns true if <var>wc</var> is a hexadecimal digit.
Hexadecimal digits include the normal decimal digits ‘<samp>0</samp>’ through
‘<samp>9</samp>’ and the letters ‘<samp>A</samp>’ through ‘<samp>F</samp>’ and
‘<samp>a</samp>’ through ‘<samp>f</samp>’.
</p>
<p>This function can be implemented using
</p>
<table><tr><td> </td><td><pre class="smallexample">iswctype (wc, wctype ("xdigit"))
</pre></td></tr></table>
<a name="index-wctype_002eh-13"></a>
<p>It is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<p>The GNU C library also provides a function which is not defined in the
ISO C standard but which is available as a version for single byte
characters as well.
</p>
<a name="index-blank-character-1"></a>
<dl>
<dt><a name="index-iswblank"></a><u>Function:</u> int <b>iswblank</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>Returns true if <var>wc</var> is a blank character; that is, a space or a tab.
This function was originally a GNU extension, but was added in ISO C99.
It is declared in ‘<tt>wchar.h</tt>’.
</p></dd></dl>
<hr size="6">
<a name="Using-Wide-Char-Classes"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Classification-of-Wide-Characters" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Wide-Character-Case-Conversion" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Character-Handling" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Character-Handling" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_5.html#String-and-Array-Utilities" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Notes-on-using-the-wide-character-classes"></a>
<h2 class="section">4.4 Notes on using the wide character classes</h2>
<p>The first note is probably not astonishing but still occasionally a
cause of problems. The <code>isw<var>XXX</var></code> functions can be implemented
using macros and in fact, the GNU C library does this. They are still
available as real functions but when the ‘<tt>wctype.h</tt>’ header is
included the macros will be used. This is the same as the
<code>char</code> type versions of these functions.
</p>
<p>The second note covers something new. It can be best illustrated by a
(real-world) example. The first piece of code is an excerpt from the
original code. It is truncated a bit but the intention should be clear.
</p>
<table><tr><td> </td><td><pre class="smallexample">int
is_in_class (int c, const char *class)
{
if (strcmp (class, "alnum") == 0)
return isalnum (c);
if (strcmp (class, "alpha") == 0)
return isalpha (c);
if (strcmp (class, "cntrl") == 0)
return iscntrl (c);
…
return 0;
}
</pre></td></tr></table>
<p>Now, with the <code>wctype</code> and <code>iswctype</code> you can avoid the
<code>if</code> cascades, but rewriting the code as follows is wrong:
</p>
<table><tr><td> </td><td><pre class="smallexample">int
is_in_class (int c, const char *class)
{
wctype_t desc = wctype (class);
return desc ? iswctype ((wint_t) c, desc) : 0;
}
</pre></td></tr></table>
<p>The problem is that it is not guaranteed that the wide character
representation of a single-byte character can be found using casting.
In fact, usually this fails miserably. The correct solution to this
problem is to write the code as follows:
</p>
<table><tr><td> </td><td><pre class="smallexample">int
is_in_class (int c, const char *class)
{
wctype_t desc = wctype (class);
return desc ? iswctype (btowc (c), desc) : 0;
}
</pre></td></tr></table>
<p>See section <a href="libc_6.html#Converting-a-Character">Converting Single Characters</a>, for more information on <code>btowc</code>.
Note that this change probably does not improve the performance
of the program a lot since the <code>wctype</code> function still has to make
the string comparisons. It gets really interesting if the
<code>is_in_class</code> function is called more than once for the
same class name. In this case the variable <var>desc</var> could be computed
once and reused for all the calls. Therefore the above form of the
function is probably not the final one.
</p>
<hr size="6">
<a name="Wide-Character-Case-Conversion"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Using-Wide-Char-Classes" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="libc_5.html#String-and-Array-Utilities" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Character-Handling" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Character-Handling" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_5.html#String-and-Array-Utilities" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Mapping-of-wide-characters_002e"></a>
<h2 class="section">4.5 Mapping of wide characters.</h2>
<p>The classification functions are also generalized by the ISO C
standard. Instead of just allowing the two standard mappings, a
locale can contain others. Again, the <code>localedef</code> program
already supports generating such locale data files.
</p>
<dl>
<dt><a name="index-wctrans_005ft"></a><u>Data Type:</u> <b>wctrans_t</b></dt>
<dd><p>This data type is defined as a scalar type which can hold a value
representing the locale-dependent character mapping. There is no way to
construct such a value apart from using the return value of the
<code>wctrans</code> function.
</p>
<a name="index-wctype_002eh-14"></a>
<p>This type is defined in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<dl>
<dt><a name="index-wctrans"></a><u>Function:</u> wctrans_t <b>wctrans</b><i> (const char *<var>property</var>)</i></dt>
<dd><p>The <code>wctrans</code> function has to be used to find out whether a named
mapping is defined in the current locale selected for the
<code>LC_CTYPE</code> category. If the returned value is non-zero, you can use
it afterwards in calls to <code>towctrans</code>. If the return value is
zero no such mapping is known in the current locale.
</p>
<p>Beside locale-specific mappings there are two mappings which are
guaranteed to be available in every locale:
</p>
<table>
<tr><td width="50%"><code>"tolower"</code></td><td width="50%"><code>"toupper"</code></td></tr>
</table>
<a name="index-wctype_002eh-15"></a>
<p>These functions are declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<dl>
<dt><a name="index-towctrans"></a><u>Function:</u> wint_t <b>towctrans</b><i> (wint_t <var>wc</var>, wctrans_t <var>desc</var>)</i></dt>
<dd><p><code>towctrans</code> maps the input character <var>wc</var>
according to the rules of the mapping for which <var>desc</var> is a
descriptor, and returns the value it finds. <var>desc</var> must be
obtained by a successful call to <code>wctrans</code>.
</p>
<a name="index-wctype_002eh-16"></a>
<p>This function is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<p>For the generally available mappings, the ISO C standard defines
convenient shortcuts so that it is not necessary to call <code>wctrans</code>
for them.
</p>
<dl>
<dt><a name="index-towlower"></a><u>Function:</u> wint_t <b>towlower</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>If <var>wc</var> is an upper-case letter, <code>towlower</code> returns the corresponding
lower-case letter. If <var>wc</var> is not an upper-case letter,
<var>wc</var> is returned unchanged.
</p>
<p><code>towlower</code> can be implemented using
</p>
<table><tr><td> </td><td><pre class="smallexample">towctrans (wc, wctrans ("tolower"))
</pre></td></tr></table>
<a name="index-wctype_002eh-17"></a>
<p>This function is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<dl>
<dt><a name="index-towupper"></a><u>Function:</u> wint_t <b>towupper</b><i> (wint_t <var>wc</var>)</i></dt>
<dd><p>If <var>wc</var> is a lower-case letter, <code>towupper</code> returns the corresponding
upper-case letter. Otherwise <var>wc</var> is returned unchanged.
</p>
<p><code>towupper</code> can be implemented using
</p>
<table><tr><td> </td><td><pre class="smallexample">towctrans (wc, wctrans ("toupper"))
</pre></td></tr></table>
<a name="index-wctype_002eh-18"></a>
<p>This function is declared in ‘<tt>wctype.h</tt>’.
</p></dd></dl>
<p>The same warnings given in the last section for the use of the wide
character classification functions apply here. It is not possible to
simply cast a <code>char</code> type value to a <code>wint_t</code> and use it as an
argument to <code>towctrans</code> calls.
</p><hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Character-Handling" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="libc_5.html#String-and-Array-Utilities" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
<font size="-1">
This document was generated by <em>root</em> on <em>March 23, 2017</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.82</em></a>.
</font>
<br>
</p>
</body>
</html>
|