mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 22:50:38 +03:00
Added an enumerated type of ASCII control character.
This commit is contained in:
parent
4851827804
commit
6af0f68058
2 changed files with 75 additions and 0 deletions
10
changelog/asciicontroltable.dd
Normal file
10
changelog/asciicontroltable.dd
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
Added a table of control characters in ASCII table
|
||||||
|
|
||||||
|
There is a new enumerated type $(REF ControlChar, std, ascii). It has
|
||||||
|
values for every control character in ASCII table and has a base type
|
||||||
|
of `char`, allowing for alternative markup of strings with control
|
||||||
|
characters:
|
||||||
|
-------
|
||||||
|
import std.ascii, std.conv;
|
||||||
|
with (ControlChar) assert(text("Phobos", US, "Deimos", US, "Tango", RS) == "Phobos\x1FDeimos\x1FTango\x1E");
|
||||||
|
-------
|
65
std/ascii.d
65
std/ascii.d
|
@ -46,6 +46,7 @@ $(TR $(TD Constants) $(TD
|
||||||
$(LREF whitespace)
|
$(LREF whitespace)
|
||||||
))
|
))
|
||||||
$(TR $(TD Enums) $(TD
|
$(TR $(TD Enums) $(TD
|
||||||
|
$(LREF ControlChar)
|
||||||
$(LREF LetterCase)
|
$(LREF LetterCase)
|
||||||
))
|
))
|
||||||
))
|
))
|
||||||
|
@ -102,6 +103,70 @@ enum LetterCase : bool
|
||||||
assert(sha1HMAC == "49f2073c7bf58577e8c9ae59fe8cfd37c9ab94e5");
|
assert(sha1HMAC == "49f2073c7bf58577e8c9ae59fe8cfd37c9ab94e5");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/++
|
||||||
|
All the control characters in ASCII table
|
||||||
|
+/
|
||||||
|
enum ControlChar : char
|
||||||
|
{
|
||||||
|
NUL = '\x00', /// Null
|
||||||
|
SOH = '\x01', /// Start of heading
|
||||||
|
STX = '\x02', /// Start of text
|
||||||
|
ETX = '\x03', /// End of text
|
||||||
|
EOT = '\x04', /// End of transmission
|
||||||
|
ENQ = '\x05', /// Enquiry
|
||||||
|
ACK = '\x06', /// Acknowledge
|
||||||
|
BEL = '\x07', /// Bell
|
||||||
|
BS = '\x08', /// Backspace
|
||||||
|
TAB = '\x09', /// Horizontal tab
|
||||||
|
LF = '\x0A', /// NL line feed, new line
|
||||||
|
VT = '\x0B', /// Vertical tab
|
||||||
|
FF = '\x0C', /// NP form feed, new page
|
||||||
|
CR = '\x0D', /// Carriage return
|
||||||
|
SO = '\x0E', /// Shift out
|
||||||
|
SI = '\x0F', /// Shift in
|
||||||
|
DLE = '\x10', /// Data link escape
|
||||||
|
DC1 = '\x11', /// Device control 1
|
||||||
|
DC2 = '\x12', /// Device control 2
|
||||||
|
DC3 = '\x13', /// Device control 3
|
||||||
|
DC4 = '\x14', /// Device control 4
|
||||||
|
NAK = '\x15', /// Negative acknowledge
|
||||||
|
SYN = '\x16', /// Synchronous idle
|
||||||
|
ETB = '\x17', /// End of transmission block
|
||||||
|
CAN = '\x18', /// Cancel
|
||||||
|
EM = '\x19', /// End of medium
|
||||||
|
SUB = '\x1A', /// Substitute
|
||||||
|
ESC = '\x1B', /// Escape
|
||||||
|
FS = '\x1C', /// File separator
|
||||||
|
GS = '\x1D', /// Group separator
|
||||||
|
RS = '\x1E', /// Record separator
|
||||||
|
US = '\x1F', /// Unit separator
|
||||||
|
DEL = '\x7F' /// Delete
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
@safe pure nothrow @nogc unittest
|
||||||
|
{
|
||||||
|
// Because all ASCII characters fit in char, so do these
|
||||||
|
static assert(ControlChar.ACK.sizeof == 1);
|
||||||
|
|
||||||
|
static assert(ControlChar.NUL == '\0');
|
||||||
|
static assert(ControlChar.BEL == '\a');
|
||||||
|
static assert(ControlChar.BS == '\b');
|
||||||
|
static assert(ControlChar.FF == '\f');
|
||||||
|
static assert(ControlChar.LF == '\n');
|
||||||
|
static assert(ControlChar.CR == '\r');
|
||||||
|
static assert(ControlChar.TAB == '\t');
|
||||||
|
static assert(ControlChar.VT == '\v');
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
@safe pure nothrow unittest
|
||||||
|
{
|
||||||
|
import std.conv;
|
||||||
|
//Control character table can be used in place of hexcodes.
|
||||||
|
with (ControlChar) assert(text("Phobos", US, "Deimos", US, "Tango", RS) == "Phobos\x1FDeimos\x1FTango\x1E");
|
||||||
|
}
|
||||||
|
|
||||||
/// Newline sequence for this system.
|
/// Newline sequence for this system.
|
||||||
version (Windows)
|
version (Windows)
|
||||||
immutable newline = "\r\n";
|
immutable newline = "\r\n";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue