|
1 | 1 | \section{\module{curses.ascii} --- |
2 | | - Constants and set-membership functions for ASCII characters.} |
| 2 | + Utilities for ASCII characters} |
3 | 3 |
|
4 | 4 | \declaremodule{standard}{curses.ascii} |
5 | | -\modulesynopsis{Constants and set-membership functions for ASCII characters.} |
| 5 | +\modulesynopsis{Constants and set-membership functions for |
| 6 | + \ASCII{} characters.} |
6 | 7 | \moduleauthor{Eric S. Raymond}{ [email protected]} |
7 | 8 | \sectionauthor{Eric S. Raymond}{ [email protected]} |
8 | 9 |
|
9 | 10 | \versionadded{1.6} |
10 | 11 |
|
11 | | -The \module{curses.ascii} module supplies name constants for ASCII characters |
12 | | -and functions to test membership in various ASCII character classes. |
13 | | -The constants supplied are names for control characters as follows: |
| 12 | +The \module{curses.ascii} module supplies name constants for |
| 13 | +\ASCII{} characters and functions to test membership in various |
| 14 | +\ASCII{} character classes. The constants supplied are names for |
| 15 | +control characters as follows: |
| 16 | + |
| 17 | +\begin{tableii}{l|l}{constant}{Name}{Meaning} |
| 18 | + \lineii{NUL}{} |
| 19 | + \lineii{SOH}{Start of heading, console interrupt} |
| 20 | + \lineii{STX}{Start of text} |
| 21 | + \lineii{ETX}{Ennd of text} |
| 22 | + \lineii{EOT}{End of transmission} |
| 23 | + \lineii{ENQ}{Enquiry, goes with \constant{ACK} flow control} |
| 24 | + \lineii{ACK}{Acknowledgement} |
| 25 | + \lineii{BEL}{Bell} |
| 26 | + \lineii{BS}{Backspace} |
| 27 | + \lineii{TAB}{Tab} |
| 28 | + \lineii{HT}{Alias for \constant{TAB}: ``Horizontal tab''} |
| 29 | + \lineii{LF}{Line feed} |
| 30 | + \lineii{NL}{Alias for \constant{LF}: ``New line''} |
| 31 | + \lineii{VT}{Vertical tab} |
| 32 | + \lineii{FF}{Form feed} |
| 33 | + \lineii{CR}{Carriage return} |
| 34 | + \lineii{SO}{Shift-out, begin alternate character set} |
| 35 | + \lineii{SI}{Shift-in, resume default character set} |
| 36 | + \lineii{DLE}{Data-link escape} |
| 37 | + \lineii{DC1}{XON, for flow control} |
| 38 | + \lineii{DC2}{Device control 2, block-mode flow control} |
| 39 | + \lineii{DC3}{XOFF, for flow control} |
| 40 | + \lineii{DC4}{Device control 4} |
| 41 | + \lineii{NAK}{Negative acknowledgement} |
| 42 | + \lineii{SYN}{Synchronous idle} |
| 43 | + \lineii{ETB}{End transmission block} |
| 44 | + \lineii{CAN}{Cancel} |
| 45 | + \lineii{EM}{End of medium} |
| 46 | + \lineii{SUB}{Substitute} |
| 47 | + \lineii{ESC}{Escape} |
| 48 | + \lineii{FS}{File separator} |
| 49 | + \lineii{GS}{Group separator} |
| 50 | + \lineii{RS}{Record separator, block-mode terminator} |
| 51 | + \lineii{US}{Unit separator} |
| 52 | + \lineii{SP}{Space} |
| 53 | + \lineii{DEL}{Delete} |
| 54 | +\end{tableii} |
| 55 | + |
| 56 | +Note that many of these have little practical use in modern usage. |
| 57 | + |
| 58 | +The module supplies the following functions, patterned on those in the |
| 59 | +standard C library: |
14 | 60 |
|
15 | | -NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS, TAB, HT, LF, NL, VT, FF, CR, |
16 | | -SO, SI, DLE, DC1, DC2, DC3, DC4, NAK, SYN, ETB, CAN, EM, SUB, ESC, FS, |
17 | | -GS, RS, US, SP, DEL. |
18 | | - |
19 | | -NL and LF are synonyms; so are HT and TAB. The module also supplies |
20 | | -the following functions, patterned on those in the standard C library: |
21 | 61 |
|
22 | 62 | \begin{funcdesc}{isalnum}{c} |
23 | | -Checks for an ASCII alphanumeric character; it is equivalent to |
24 | | -isalpha(c) or isdigit(c)) |
| 63 | +Checks for an \ASCII{} alphanumeric character; it is equivalent to |
| 64 | +\samp{isalpha(\var{c}) or isdigit(\var{c})}. |
25 | 65 | \end{funcdesc} |
26 | 66 |
|
27 | 67 | \begin{funcdesc}{isalpha}{c} |
28 | | -Checks for an ASCII alphabetic character; it is equivalent to |
29 | | -isupper(c) or islower(c)) |
| 68 | +Checks for an \ASCII{} alphabetic character; it is equivalent to |
| 69 | +\samp{isupper(\var{c}) or islower(\var{c})}. |
30 | 70 | \end{funcdesc} |
31 | 71 |
|
32 | 72 | \begin{funcdesc}{isascii}{c} |
33 | | -Checks for a character value that fits in the 7-bit ASCII set. |
| 73 | +Checks for a character value that fits in the 7-bit \ASCII{} set. |
34 | 74 | \end{funcdesc} |
35 | 75 |
|
36 | 76 | \begin{funcdesc}{isblank}{c} |
37 | | -Checks for an ASCII alphanumeric character; it is equivalent to |
38 | | -isalpha(c) or isdigit(c)) |
| 77 | +Checks for an \ASCII{} whitespace character. |
39 | 78 | \end{funcdesc} |
40 | 79 |
|
41 | 80 | \begin{funcdesc}{iscntrl}{c} |
42 | | -Checks for an ASCII control character (range 0x00 to 0x1f). |
| 81 | +Checks for an \ASCII{} control character (in the range 0x00 to 0x1f). |
43 | 82 | \end{funcdesc} |
44 | 83 |
|
45 | 84 | \begin{funcdesc}{isdigit}{c} |
46 | | -Checks for an ASCII decimal digit, 0 through 9. |
| 85 | +Checks for an \ASCII{} decimal digit, \character{0} through |
| 86 | +\character{9}. This is equivalent to \samp{\var{c} in string.digits}. |
47 | 87 | \end{funcdesc} |
48 | 88 |
|
49 | 89 | \begin{funcdesc}{isgraph}{c} |
50 | | -Checks for ASCII any printable character except space. |
| 90 | +Checks for \ASCII{} any printable character except space. |
51 | 91 | \end{funcdesc} |
52 | 92 |
|
53 | 93 | \begin{funcdesc}{islower}{c} |
54 | | -Checks for an ASCII lower-case character. |
| 94 | +Checks for an \ASCII{} lower-case character. |
55 | 95 | \end{funcdesc} |
56 | 96 |
|
57 | 97 | \begin{funcdesc}{isprint}{c} |
58 | | -Checks for any ASCII printable character including space. |
| 98 | +Checks for any \ASCII{} printable character including space. |
59 | 99 | \end{funcdesc} |
60 | 100 |
|
61 | 101 | \begin{funcdesc}{ispunct}{c} |
62 | | -Checks for any printable ASCII character which is not a space or an |
| 102 | +Checks for any printable \ASCII{} character which is not a space or an |
63 | 103 | alphanumeric character. |
64 | 104 | \end{funcdesc} |
65 | 105 |
|
66 | 106 | \begin{funcdesc}{isspace}{c} |
67 | | -Checks for ASCII white-space characters; space, tab, line feed, |
| 107 | +Checks for \ASCII{} white-space characters; space, tab, line feed, |
68 | 108 | carriage return, form feed, horizontal tab, vertical tab. |
69 | 109 | \end{funcdesc} |
70 | 110 |
|
71 | 111 | \begin{funcdesc}{isupper}{c} |
72 | | -Checks for an ASCII uppercase letter. |
| 112 | +Checks for an \ASCII{} uppercase letter. |
73 | 113 | \end{funcdesc} |
74 | 114 |
|
75 | 115 | \begin{funcdesc}{isxdigit}{c} |
76 | | -Checks for an ASCII hexadecimal digit, i.e. one of 0123456789abcdefABCDEF. |
| 116 | +Checks for an \ASCII{} hexadecimal digit. This is equivalent to |
| 117 | +\samp{\var{c} in string.hexdigits}. |
77 | 118 | \end{funcdesc} |
78 | 119 |
|
79 | 120 | \begin{funcdesc}{isctrl}{c} |
80 | | -Checks for an ASCII control character, bit values 0 to 31. |
| 121 | +Checks for an \ASCII{} control character (ordinal values 0 to 31). |
81 | 122 | \end{funcdesc} |
82 | 123 |
|
83 | 124 | \begin{funcdesc}{ismeta}{c} |
84 | | -Checks for a (non-ASCII) character, bit values 0x80 and above. |
| 125 | +Checks for a non-\ASCII{} character (ordinal values 0x80 and above). |
85 | 126 | \end{funcdesc} |
86 | 127 |
|
87 | 128 | These functions accept either integers or strings; when the argument |
88 | | -is a string, it is first converted using the built-in function ord(). |
| 129 | +is a string, it is first converted using the built-in function |
| 130 | +\function{ord()}. |
89 | 131 |
|
90 | 132 | Note that all these functions check ordinal bit values derived from the |
91 | 133 | first character of the string you pass in; they do not actually know |
92 | 134 | anything about the host machine's character encoding. For functions |
93 | 135 | that know about the character encoding (and handle |
94 | | -internationalization properly) see the string module. |
| 136 | +internationalization properly) see the \refmodule{string} module. |
95 | 137 |
|
96 | 138 | The following two functions take either a single-character string or |
97 | 139 | integer byte value; they return a value of the same type. |
98 | 140 |
|
99 | 141 | \begin{funcdesc}{ascii}{c} |
100 | | -Return the ASCII value corresponding to the low 7 bits of c. |
| 142 | +Return the ASCII value corresponding to the low 7 bits of \var{c}. |
101 | 143 | \end{funcdesc} |
102 | 144 |
|
103 | 145 | \begin{funcdesc}{ctrl}{c} |
104 | 146 | Return the control character corresponding to the given character |
105 | | -(the character bit value is logical-anded with 0x1f). |
| 147 | +(the character bit value is bitwise-anded with 0x1f). |
106 | 148 | \end{funcdesc} |
107 | 149 |
|
108 | 150 | \begin{funcdesc}{alt}{c} |
109 | 151 | Return the 8-bit character corresponding to the given ASCII character |
110 | | -(the character bit value is logical-ored with 0x80). |
| 152 | +(the character bit value is bitwise-ored with 0x80). |
111 | 153 | \end{funcdesc} |
112 | 154 |
|
113 | 155 | The following function takes either a single-character string or |
114 | | -integer byte value; it returns a string. |
| 156 | +integer value; it returns a string. |
115 | 157 |
|
116 | 158 | \begin{funcdesc}{unctrl}{c} |
117 | | -Return a string representation of the ASCII character c. If c is |
118 | | -printable, this string is the character itself. If the character |
119 | | -is a control character (0x00-0x1f) the string consists of a caret |
120 | | -(^) followed by the corresponding uppercase letter. If the character |
121 | | -is an ASCII delete (0x7f) the string is "^?". If the character has |
122 | | -its meta bit (0x80) set, the meta bit is stripped, the preceding rules |
123 | | -applied, and "!" prepended to the result. |
124 | | -\end{funcdesc} |
125 | | - |
126 | | -Finally, the module supplies a 33-element string array |
127 | | -called controlnames that contains the ASCII mnemonics for the |
128 | | -thirty-two ASCII control characters from 0 (NUL) to 0x1f (US), |
129 | | -in order, plus the mnemonic "SP" for space. |
130 | | - |
131 | | - |
| 159 | +Return a string representation of the \ASCII{} character \var{c}. If |
| 160 | +\var{c} is printable, this string is the character itself. If the |
| 161 | +character is a control character (0x00-0x1f) the string consists of a |
| 162 | +caret (\character{\^}) followed by the corresponding uppercase letter. |
| 163 | +If the character is an \ASCII{} delete (0x7f) the string is |
| 164 | +\code{'\^{}?'}. If the character has its meta bit (0x80) set, the meta |
| 165 | +bit is stripped, the preceding rules applied, and |
| 166 | +\character{!} prepended to the result. |
| 167 | +\end{funcdesc} |
| 168 | + |
| 169 | +\begin{datadesc}{controlnames} |
| 170 | +A 33-element string array that contains the \ASCII{} mnemonics for the |
| 171 | +thirty-two \ASCII{} control characters from 0 (NUL) to 0x1f (US), in |
| 172 | +order, plus the mnemonic \samp{SP} for the space character. |
| 173 | +\end{datadesc} |
0 commit comments