mini-llvm 0.1.0
Loading...
Searching...
No Matches
Ascii.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <cstdint>
6
7namespace mini_llvm {
8
9namespace detail {
10
11inline constexpr uint8_t kAsciiMasks[] = {
12 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
13 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
14 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
15 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
16 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
17 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
18 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19,
19 0x19, 0x19, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
20 0x01, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x03,
21 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
22 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
23 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01,
24 0x01, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05,
25 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
26 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
27 0x05, 0x05, 0x05, 0x01, 0x01, 0x01, 0x01, 0x00,
28 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
37 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44};
45
46inline constexpr char kAsciiLower[] = {
47 '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
48 '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f',
49 '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17',
50 '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f',
51 '\x20', '\x21', '\x22', '\x23', '\x24', '\x25', '\x26', '\x27',
52 '\x28', '\x29', '\x2a', '\x2b', '\x2c', '\x2d', '\x2e', '\x2f',
53 '\x30', '\x31', '\x32', '\x33', '\x34', '\x35', '\x36', '\x37',
54 '\x38', '\x39', '\x3a', '\x3b', '\x3c', '\x3d', '\x3e', '\x3f',
55 '\x40', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
56 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
57 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
58 'x', 'y', 'z', '\x5b', '\x5c', '\x5d', '\x5e', '\x5f',
59 '\x60', '\x61', '\x62', '\x63', '\x64', '\x65', '\x66', '\x67',
60 '\x68', '\x69', '\x6a', '\x6b', '\x6c', '\x6d', '\x6e', '\x6f',
61 '\x70', '\x71', '\x72', '\x73', '\x74', '\x75', '\x76', '\x77',
62 '\x78', '\x79', '\x7a', '\x7b', '\x7c', '\x7d', '\x7e', '\x7f',
63 '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87',
64 '\x88', '\x89', '\x8a', '\x8b', '\x8c', '\x8d', '\x8e', '\x8f',
65 '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97',
66 '\x98', '\x99', '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f',
67 '\xa0', '\xa1', '\xa2', '\xa3', '\xa4', '\xa5', '\xa6', '\xa7',
68 '\xa8', '\xa9', '\xaa', '\xab', '\xac', '\xad', '\xae', '\xaf',
69 '\xb0', '\xb1', '\xb2', '\xb3', '\xb4', '\xb5', '\xb6', '\xb7',
70 '\xb8', '\xb9', '\xba', '\xbb', '\xbc', '\xbd', '\xbe', '\xbf',
71 '\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7',
72 '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf',
73 '\xd0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd7',
74 '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xdf',
75 '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7',
76 '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee', '\xef',
77 '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf7',
78 '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xff',
79};
80
81inline constexpr char kAsciiUpper[] = {
82 '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
83 '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f',
84 '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17',
85 '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f',
86 '\x20', '\x21', '\x22', '\x23', '\x24', '\x25', '\x26', '\x27',
87 '\x28', '\x29', '\x2a', '\x2b', '\x2c', '\x2d', '\x2e', '\x2f',
88 '\x30', '\x31', '\x32', '\x33', '\x34', '\x35', '\x36', '\x37',
89 '\x38', '\x39', '\x3a', '\x3b', '\x3c', '\x3d', '\x3e', '\x3f',
90 '\x40', '\x41', '\x42', '\x43', '\x44', '\x45', '\x46', '\x47',
91 '\x48', '\x49', '\x4a', '\x4b', '\x4c', '\x4d', '\x4e', '\x4f',
92 '\x50', '\x51', '\x52', '\x53', '\x54', '\x55', '\x56', '\x57',
93 '\x58', '\x59', '\x5a', '\x5b', '\x5c', '\x5d', '\x5e', '\x5f',
94 '\x60', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
95 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
96 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
97 'X', 'Y', 'Z', '\x7b', '\x7c', '\x7d', '\x7e', '\x7f',
98 '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87',
99 '\x88', '\x89', '\x8a', '\x8b', '\x8c', '\x8d', '\x8e', '\x8f',
100 '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97',
101 '\x98', '\x99', '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f',
102 '\xa0', '\xa1', '\xa2', '\xa3', '\xa4', '\xa5', '\xa6', '\xa7',
103 '\xa8', '\xa9', '\xaa', '\xab', '\xac', '\xad', '\xae', '\xaf',
104 '\xb0', '\xb1', '\xb2', '\xb3', '\xb4', '\xb5', '\xb6', '\xb7',
105 '\xb8', '\xb9', '\xba', '\xbb', '\xbc', '\xbd', '\xbe', '\xbf',
106 '\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7',
107 '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf',
108 '\xd0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd7',
109 '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xdf',
110 '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7',
111 '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee', '\xef',
112 '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf7',
113 '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xff',
114};
115
116} // namespace detail
117
118inline constexpr bool isAsciiPrintable(char ch) noexcept {
119 return detail::kAsciiMasks[static_cast<uint8_t>(ch)] & 0x01;
120}
121
122inline constexpr bool isAsciiUpper(char ch) noexcept {
123 return detail::kAsciiMasks[static_cast<uint8_t>(ch)] & 0x02;
124}
125
126inline constexpr bool isAsciiLower(char ch) noexcept {
127 return detail::kAsciiMasks[static_cast<uint8_t>(ch)] & 0x04;
128}
129
130inline constexpr bool isAsciiLetter(char ch) noexcept {
131 return detail::kAsciiMasks[static_cast<uint8_t>(ch)] & 0x06;
132}
133
134inline constexpr bool isAsciiDigit(char ch) noexcept {
135 return detail::kAsciiMasks[static_cast<uint8_t>(ch)] & 0x08;
136}
137
138inline constexpr bool isAsciiLetterOrDigit(char ch) noexcept {
139 return detail::kAsciiMasks[static_cast<uint8_t>(ch)] & 0x0e;
140}
141
142inline constexpr bool isAsciiHexDigit(char ch) noexcept {
143 return detail::kAsciiMasks[static_cast<uint8_t>(ch)] & 0x10;
144}
145
146inline constexpr char toAsciiLower(char ch) noexcept{
147 return detail::kAsciiLower[static_cast<uint8_t>(ch)];
148}
149
150inline constexpr char toAsciiUpper(char ch) noexcept {
151 return detail::kAsciiUpper[static_cast<uint8_t>(ch)];
152}
153
154} // namespace mini_llvm
Definition GraphColoringAllocator.h:13
constexpr bool isAsciiPrintable(char ch) noexcept
Definition Ascii.h:118
constexpr char toAsciiUpper(char ch) noexcept
Definition Ascii.h:150
constexpr bool isAsciiHexDigit(char ch) noexcept
Definition Ascii.h:142
constexpr bool isAsciiLetter(char ch) noexcept
Definition Ascii.h:130
constexpr bool isAsciiLetterOrDigit(char ch) noexcept
Definition Ascii.h:138
constexpr bool isAsciiUpper(char ch) noexcept
Definition Ascii.h:122
constexpr char toAsciiLower(char ch) noexcept
Definition Ascii.h:146
constexpr bool isAsciiLower(char ch) noexcept
Definition Ascii.h:126
constexpr bool isAsciiDigit(char ch) noexcept
Definition Ascii.h:134