blob: 51598043e08e5efa228046904a03bcc5627069d8 [file] [log] [blame]
Andrew M. Kuchlingf57d7b92000-06-26 23:59:24 +00001\section{\module{curses.ascii} ---
2 Constants and set-membership functions for ASCII characters.}
3
4\declaremodule{standard}{curses.ascii}
5\modulesynopsis{Constants and set-membership functions for ASCII characters.}
6\moduleauthor{Eric S. Raymond}{esr@thyrsus.com}
7\sectionauthor{Eric S. Raymond}{esr@thyrsus.com}
8
9\versionadded{1.6}
10
11The \module{curses.ascii} module supplies name constants for ASCII characters
12and functions to test membership in various ASCII character classes.
13The constants supplied are names for control characters as follows:
14
15NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS, TAB, HT, LF, NL, VT, FF, CR,
16SO, SI, DLE, DC1, DC2, DC3, DC4, NAK, SYN, ETB, CAN, EM, SUB, ESC, FS,
17GS, RS, US, SP, DEL.
18
19NL and LF are synonyms; so are HT and TAB. The module also supplies
20the following functions, patterned on those in the standard C library:
21
22\begin{funcdesc}{isalnum}{c}
23Checks for an ASCII alphanumeric character; it is equivalent to
24isalpha(c) or isdigit(c))
25\end{funcdesc}
26
27\begin{funcdesc}{isalpha}{c}
28Checks for an ASCII alphabetic character; it is equivalent to
29isupper(c) or islower(c))
30\end{funcdesc}
31
32\begin{funcdesc}{isascii}{c}
33Checks for a character value that fits in the 7-bit ASCII set.
34\end{funcdesc}
35
36\begin{funcdesc}{isblank}{c}
37Checks for an ASCII alphanumeric character; it is equivalent to
38isalpha(c) or isdigit(c))
39\end{funcdesc}
40
41\begin{funcdesc}{iscntrl}{c}
42Checks for an ASCII control character (range 0x00 to 0x1f).
43\end{funcdesc}
44
45\begin{funcdesc}{isdigit}{c}
46Checks for an ASCII decimal digit, 0 through 9.
47\end{funcdesc}
48
49\begin{funcdesc}{isgraph}{c}
50Checks for ASCII any printable character except space.
51\end{funcdesc}
52
53\begin{funcdesc}{islower}{c}
54Checks for an ASCII lower-case character.
55\end{funcdesc}
56
57\begin{funcdesc}{isprint}{c}
58Checks for any ASCII printable character including space.
59\end{funcdesc}
60
61\begin{funcdesc}{ispunct}{c}
62Checks for any printable ASCII character which is not a space or an
63alphanumeric character.
64\end{funcdesc}
65
66\begin{funcdesc}{isspace}{c}
67Checks for ASCII white-space characters; space, tab, line feed,
68carriage return, form feed, horizontal tab, vertical tab.
69\end{funcdesc}
70
71\begin{funcdesc}{isupper}{c}
72Checks for an ASCII uppercase letter.
73\end{funcdesc}
74
75\begin{funcdesc}{isxdigit}{c}
76Checks for an ASCII hexadecimal digit, i.e. one of 0123456789abcdefABCDEF.
77\end{funcdesc}
78
79\begin{funcdesc}{isctrl}{c}
80Checks for an ASCII control character, bit values 0 to 31.
81\end{funcdesc}
82
83\begin{funcdesc}{ismeta}{c}
84Checks for a (non-ASCII) character, bit values 0x80 and above.
85\end{funcdesc}
86
87These functions accept either integers or strings; when the argument
88is a string, it is first converted using the built-in function ord().
89
90Note that all these functions check ordinal bit values derived from the
91first character of the string you pass in; they do not actually know
92anything about the host machine's character encoding. For functions
93that know about the character encoding (and handle
94internationalization properly) see the string module.
95
96The following two functions take either a single-character string or
97integer byte value; they return a value of the same type.
98
99\begin{funcdesc}{ascii}{c}
100Return the ASCII value corresponding to the low 7 bits of c.
101\end{funcdesc}
102
103\begin{funcdesc}{ctrl}{c}
104Return the control character corresponding to the given character
105(the character bit value is logical-anded with 0x1f).
106\end{funcdesc}
107
108\begin{funcdesc}{alt}{c}
109Return the 8-bit character corresponding to the given ASCII character
110(the character bit value is logical-ored with 0x80).
111\end{funcdesc}
112
113The following function takes either a single-character string or
114integer byte value; it returns a string.
115
116\begin{funcdesc}{unctrl}{c}
117Return a string representation of the ASCII character c. If c is
118printable, this string is the character itself. If the character
119is a control character (0x00-0x1f) the string consists of a caret
120(^) followed by the corresponding uppercase letter. If the character
121is an ASCII delete (0x7f) the string is "^?". If the character has
122its meta bit (0x80) set, the meta bit is stripped, the preceding rules
123applied, and "!" prepended to the result.
124\end{funcdesc}
125
126Finally, the module supplies a 33-element string array
127called controlnames that contains the ASCII mnemonics for the
128thirty-two ASCII control characters from 0 (NUL) to 0x1f (US),
129in order, plus the mnemonic "SP" for space.
130
131