curses.ascii
--- Utilities for ASCII charactersP
The curses.ascii
module supplies name constants for ASCII characters and
functions to test membership in various ASCII character classes. The constants
supplied are names for control characters as follows:
名称 |
含义 |
---|---|
|
|
|
标题开始,控制台中断 |
|
文本开始 |
|
文本结束 |
|
传输结束 |
|
查询,附带 |
|
确认 |
|
蜂鸣器 |
|
退格 |
|
Tab |
|
|
|
换行 |
|
|
|
垂直制表符 |
|
换页 |
|
回车 |
|
Shift-out, begin alternate character set |
|
Shift-in, resume default character set |
|
Data-link escape |
|
XON, for flow control |
|
Device control 2, block-mode flow control |
|
XOFF, for flow control |
|
设备控制4 |
|
否定确认 |
|
同步空闲 |
|
末端传输块 |
|
取消 |
|
媒体结束 |
|
替换 |
|
退出 |
|
文件分隔符 |
|
Group separator |
|
记录分隔符,块模式终结器 |
|
单位分隔符 |
|
空格 |
|
删除 |
Note that many of these have little practical significance in modern usage. The mnemonics derive from teleprinter conventions that predate digital computers.
The module supplies the following functions, patterned on those in the standard C library:
-
curses.ascii.
isalnum
(c)P Checks for an ASCII alphanumeric character; it is equivalent to
isalpha(c) or isdigit(c)
.
-
curses.ascii.
isalpha
(c)P Checks for an ASCII alphabetic character; it is equivalent to
isupper(c) or islower(c)
.
-
curses.ascii.
isascii
(c)P Checks for a character value that fits in the 7-bit ASCII set.
-
curses.ascii.
isblank
(c)P Checks for an ASCII whitespace character; space or horizontal tab.
-
curses.ascii.
iscntrl
(c)P Checks for an ASCII control character (in the range 0x00 to 0x1f or 0x7f).
-
curses.ascii.
isdigit
(c)P Checks for an ASCII decimal digit,
'0'
through'9'
. This is equivalent toc in string.digits
.
-
curses.ascii.
isgraph
(c)P Checks for ASCII any printable character except space.
-
curses.ascii.
islower
(c)P Checks for an ASCII lower-case character.
-
curses.ascii.
isprint
(c)P Checks for any ASCII printable character including space.
-
curses.ascii.
ispunct
(c)P Checks for any printable ASCII character which is not a space or an alphanumeric character.
-
curses.ascii.
isspace
(c)P Checks for ASCII white-space characters; space, line feed, carriage return, form feed, horizontal tab, vertical tab.
-
curses.ascii.
isupper
(c)P Checks for an ASCII uppercase letter.
-
curses.ascii.
isxdigit
(c)P Checks for an ASCII hexadecimal digit. This is equivalent to
c in string.hexdigits
.
-
curses.ascii.
isctrl
(c)P Checks for an ASCII control character (ordinal values 0 to 31).
-
curses.ascii.
ismeta
(c)P Checks for a non-ASCII character (ordinal values 0x80 and above).
These functions accept either integers or single-character strings; when the argument is a
string, it is first converted using the built-in function ord()
.
Note that all these functions check ordinal bit values derived from the character of the string you pass in; they do not actually know anything about the host machine's character encoding.
The following two functions take either a single-character string or integer byte value; they return a value of the same type.
-
curses.ascii.
ascii
(c)P Return the ASCII value corresponding to the low 7 bits of c.
-
curses.ascii.
ctrl
(c)P Return the control character corresponding to the given character (the character bit value is bitwise-anded with 0x1f).
-
curses.ascii.
alt
(c)P Return the 8-bit character corresponding to the given ASCII character (the character bit value is bitwise-ored with 0x80).
The following function takes either a single-character string or integer value; it returns a string.
-
curses.ascii.
unctrl
(c)P Return a string representation of the ASCII character c. If c is printable, this string is the character itself. If the character is a control character (0x00--0x1f) the string consists of a caret (
'^'
) followed by the corresponding uppercase letter. If the character is an ASCII delete (0x7f) the string is'^?'
. If the character has its meta bit (0x80) set, the meta bit is stripped, the preceding rules applied, and'!'
prepended to the result.
-
curses.ascii.
controlnames
P A 33-element string array that contains the ASCII mnemonics for the thirty-two ASCII control characters from 0 (NUL) to 0x1f (US), in order, plus the mnemonic
SP
for the space character.