Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 1 | \section{\module{curses.ascii} --- |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 2 | Utilities for ASCII characters} |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 3 | |
| 4 | \declaremodule{standard}{curses.ascii} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 5 | \modulesynopsis{Constants and set-membership functions for |
| 6 | \ASCII{} characters.} |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 7 | \moduleauthor{Eric S. Raymond}{esr@thyrsus.com} |
| 8 | \sectionauthor{Eric S. Raymond}{esr@thyrsus.com} |
| 9 | |
Fred Drake | fc1f922 | 2000-08-09 14:36:11 +0000 | [diff] [blame] | 10 | \versionadded{1.6} |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 11 | |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 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: |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 16 | |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 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} |
Thomas Wouters | f831663 | 2000-07-16 19:01:10 +0000 | [diff] [blame] | 21 | \lineii{ETX}{End of text} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 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} |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 55 | |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 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: |
| 60 | |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 61 | |
| 62 | \begin{funcdesc}{isalnum}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 63 | Checks for an \ASCII{} alphanumeric character; it is equivalent to |
| 64 | \samp{isalpha(\var{c}) or isdigit(\var{c})}. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 65 | \end{funcdesc} |
| 66 | |
| 67 | \begin{funcdesc}{isalpha}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 68 | Checks for an \ASCII{} alphabetic character; it is equivalent to |
| 69 | \samp{isupper(\var{c}) or islower(\var{c})}. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 70 | \end{funcdesc} |
| 71 | |
| 72 | \begin{funcdesc}{isascii}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 73 | Checks for a character value that fits in the 7-bit \ASCII{} set. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 74 | \end{funcdesc} |
| 75 | |
| 76 | \begin{funcdesc}{isblank}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 77 | Checks for an \ASCII{} whitespace character. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 78 | \end{funcdesc} |
| 79 | |
| 80 | \begin{funcdesc}{iscntrl}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 81 | Checks for an \ASCII{} control character (in the range 0x00 to 0x1f). |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 82 | \end{funcdesc} |
| 83 | |
| 84 | \begin{funcdesc}{isdigit}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 85 | Checks for an \ASCII{} decimal digit, \character{0} through |
| 86 | \character{9}. This is equivalent to \samp{\var{c} in string.digits}. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 87 | \end{funcdesc} |
| 88 | |
| 89 | \begin{funcdesc}{isgraph}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 90 | Checks for \ASCII{} any printable character except space. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 91 | \end{funcdesc} |
| 92 | |
| 93 | \begin{funcdesc}{islower}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 94 | Checks for an \ASCII{} lower-case character. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 95 | \end{funcdesc} |
| 96 | |
| 97 | \begin{funcdesc}{isprint}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 98 | Checks for any \ASCII{} printable character including space. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 99 | \end{funcdesc} |
| 100 | |
| 101 | \begin{funcdesc}{ispunct}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 102 | Checks for any printable \ASCII{} character which is not a space or an |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 103 | alphanumeric character. |
| 104 | \end{funcdesc} |
| 105 | |
| 106 | \begin{funcdesc}{isspace}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 107 | Checks for \ASCII{} white-space characters; space, tab, line feed, |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 108 | carriage return, form feed, horizontal tab, vertical tab. |
| 109 | \end{funcdesc} |
| 110 | |
| 111 | \begin{funcdesc}{isupper}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 112 | Checks for an \ASCII{} uppercase letter. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 113 | \end{funcdesc} |
| 114 | |
| 115 | \begin{funcdesc}{isxdigit}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 116 | Checks for an \ASCII{} hexadecimal digit. This is equivalent to |
| 117 | \samp{\var{c} in string.hexdigits}. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 118 | \end{funcdesc} |
| 119 | |
| 120 | \begin{funcdesc}{isctrl}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 121 | Checks for an \ASCII{} control character (ordinal values 0 to 31). |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 122 | \end{funcdesc} |
| 123 | |
| 124 | \begin{funcdesc}{ismeta}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 125 | Checks for a non-\ASCII{} character (ordinal values 0x80 and above). |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 126 | \end{funcdesc} |
| 127 | |
| 128 | These functions accept either integers or strings; when the argument |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 129 | is a string, it is first converted using the built-in function |
| 130 | \function{ord()}. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 131 | |
| 132 | Note that all these functions check ordinal bit values derived from the |
| 133 | first character of the string you pass in; they do not actually know |
| 134 | anything about the host machine's character encoding. For functions |
| 135 | that know about the character encoding (and handle |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 136 | internationalization properly) see the \refmodule{string} module. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 137 | |
| 138 | The following two functions take either a single-character string or |
| 139 | integer byte value; they return a value of the same type. |
| 140 | |
| 141 | \begin{funcdesc}{ascii}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 142 | Return the ASCII value corresponding to the low 7 bits of \var{c}. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 143 | \end{funcdesc} |
| 144 | |
| 145 | \begin{funcdesc}{ctrl}{c} |
| 146 | Return the control character corresponding to the given character |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 147 | (the character bit value is bitwise-anded with 0x1f). |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 148 | \end{funcdesc} |
| 149 | |
| 150 | \begin{funcdesc}{alt}{c} |
| 151 | Return the 8-bit character corresponding to the given ASCII character |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 152 | (the character bit value is bitwise-ored with 0x80). |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 153 | \end{funcdesc} |
| 154 | |
| 155 | The following function takes either a single-character string or |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 156 | integer value; it returns a string. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 157 | |
| 158 | \begin{funcdesc}{unctrl}{c} |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 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. |
Andrew M. Kuchling | f57d7b9 | 2000-06-26 23:59:24 +0000 | [diff] [blame] | 167 | \end{funcdesc} |
| 168 | |
Fred Drake | 5ccd4b2 | 2000-06-28 22:03:29 +0000 | [diff] [blame] | 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} |