cppx-core
ascii-character-names.hpp
Go to the documentation of this file.
1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi").
2 
3 namespace cppx
4 {
5  namespace ascii
6  {
7  const char null = '\0'; // '\0' 0x00
8  const char bell = '\a'; // '\a' 0x07, ^G
9  const char backspace = '\b'; // '\b' 0x07, ^H
10  const char tab = '\t'; // '\t' 0x08, ^I, horizontal tab
11  const char linefeed = '\n'; // '\n' 0x09, ^J
12  const char vtab = '\v'; // '\v' 0x0A, ^K
13  const char formfeed = '\f'; // '\f' 0x0B, ^L
14  const char enter = '\r'; // '\r' 0x0C, ^M
15  const char xon = '\x11'; // 0x11, ^Q, "continue"
16  const char xoff = '\x13'; // 0x13, ^S, "stop"
17  const char end_of_text = '\x1A'; // 0x1A, ^Z, non-std MS meaning.
18  const char escape = '\x1B'; // 0x1B
19  const char del = '\x7F'; // 0x7F
20 
21  const char first_char = char( 0 ); static_assert( first_char == null );
22  const char last_char = char( 127 ); static_assert( last_char == del );
23 
24  // Standard but unfortunately uppercase abbreviations as per ASCII '67:
25  const char NUL = null;
26  const char BEL = bell;
27  const char BS = backspace;
28  const char HT = tab; // “Horizontal tab”
29  const char LF = linefeed;
30  const char VT = vtab; // “Vertical tab”
31  const char FF = formfeed;
32  const char CR = enter; // “Carriage return”
33  const char DC1 = xon; // “Device control 1”
34  const char DC3 = xoff; // “Device control 3”
35  const char SUB = end_of_text; // “Substitute”, but see below!
36  const char ESC = escape;
37  const char DEL = del; // “Delete”
38 
39  // ASCII DEL, code 0x7F = 127, “delete”, can be used as a replacement for encoding
40  // errors or unrepresentable code point.
41  //
42  // ASCII has a character dedicated to the purpose: SUB “substitute”, code 26,
43  // ^Z. But in Windows ^Z is used as an EOF marker for text streams. So ^Z as
44  // replacement is not usable in Windows, i.e. it's not a general solution.
45  //
46  // Unicode, an extension of ASCII, also has its own character dedicated to
47  // the purpose, namely code U+FFFD “replacement character”. It translates to
48  // at least two UTF-8 bytes so it's not trivial to check for. And it can't be
49  // represented in simple single byte encodings such as codepage 437, so it's
50  // not usable in single byte encodings, i.e. it's not a general solution.
51  //
52  // Using ASCII DEL as a replacement character does not preclude using it also to
53  // represent the DEL key in a keyboard interface, for in that context there is no
54  // possibility of encoding errors or unrepresentable code point. It doesn't appear
55  // in ordinary text. And it even has some mnemonic value as a deleted character.
56  //
57  // For these reasons I recommend using ASCII DEL as replacement and error
58  // indication character:
59 
60  const char bad_char = del;
61 
62  } // namespace ascii
63 
65  const wchar_t std_unicode_bad_char = L'\uFFFD';
66 
67 } // namespace cppx
const wchar_t std_unicode_bad_char
const char std_ascii_bad_char