mFrame
載入中...
搜尋中...
無符合項目
Character.h
1
7#ifndef MFRAME_5098703C_A1D7_4D60_9E2D_E5F648A0C629
8#define MFRAME_5098703C_A1D7_4D60_9E2D_E5F648A0C629
9
10/* ***************************************************************************************
11 * Include
12 */
13
14//----------------------------------------------------------------------------------------
15
16//----------------------------------------------------------------------------------------
17#include "./../lang/Appendable.h"
18#include "./../lang/NonInstantiable.h"
19#include "./../lang/Strings.h"
20
21/* ***************************************************************************************
22 * Namespace
23 */
24namespace ufm::lang {
25 class Character;
26} // namespace ufm::lang
27
28/* ***************************************************************************************
29 * Class/Interface/Struct/Enum
30 */
31
46 /* *************************************************************************************
47 * Class/Interface/Struct/Enum
48 */
49 public:
50 enum struct LineEnding : uint8;
51 /* *************************************************************************************
52 * Variable
53 */
54
55 /* *************************************************************************************
56 * Abstract Method
57 */
58
59 /* *************************************************************************************
60 * Construct Method
61 */
62 protected:
66 virtual ~Character(void) override = default;
67
68 /* *************************************************************************************
69 * Operator Method
70 */
71
72 /* *************************************************************************************
73 * Override Method
74 */
75
76 /* *************************************************************************************
77 * Public Method
78 */
79
80 /* *************************************************************************************
81 * Protected Method
82 */
83
84 /* *************************************************************************************
85 * Private Method
86 */
87
88 /* *************************************************************************************
89 * Static Variable
90 */
91 public:
92 // 控制字符(Control Characters)
93 static constexpr char KEY_NUL = 0x00;
94 static constexpr char KEY_SOH = 0x01;
95 static constexpr char KEY_STX = 0x02;
96 static constexpr char KEY_ETX = 0x03;
97 static constexpr char KEY_EOT = 0x04;
98 static constexpr char KEY_ENQ = 0x05;
99 static constexpr char KEY_ACK = 0x06;
100 static constexpr char KEY_BEL = 0x07;
101 static constexpr char KEY_BS = 0x08;
102 static constexpr char KEY_TAB = 0x09;
103 static constexpr char KEY_LF = 0x0A;
104 static constexpr char KEY_VT = 0x0B;
105 static constexpr char KEY_FF = 0x0C;
106 static constexpr char KEY_CR = 0x0D;
107 static constexpr char KEY_SO = 0x0E;
108 static constexpr char KEY_SI = 0x0F;
109 static constexpr char KEY_DLE = 0x10;
110 static constexpr char KEY_DC1 = 0x11;
111 static constexpr char KEY_DC2 = 0x12;
112 static constexpr char KEY_DC3 = 0x13;
113 static constexpr char KEY_DC4 = 0x14;
114 static constexpr char KEY_NAK = 0x15;
115 static constexpr char KEY_SYN = 0x16;
116 static constexpr char KEY_ETB = 0x17;
117 static constexpr char KEY_CAN = 0x18;
118 static constexpr char KEY_EM = 0x19;
119 static constexpr char KEY_SUB = 0x1A;
120 static constexpr char KEY_ESC = 0x1B;
121 static constexpr char KEY_FS = 0x1C;
122 static constexpr char KEY_GS = 0x1D;
123 static constexpr char KEY_RS = 0x1E;
124 static constexpr char KEY_US = 0x1F;
125 static constexpr char KEY_BACKSPACE = 0x7F;
127 // 符號字符(Symbol Characters)
128 static constexpr char KEY_SPACE = 0x20;
129 static constexpr char KEY_EXCLAM = 0x21;
130 static constexpr char KEY_QUOTE = 0x22;
131 static constexpr char KEY_HASH = 0x23;
132 static constexpr char KEY_DOLLAR = 0x24;
133 static constexpr char KEY_PERCENT = 0x25;
134 static constexpr char KEY_AMPERSAND = 0x26;
135 static constexpr char KEY_APOSTROPHE = 0x27;
136 static constexpr char KEY_LEFT_PAREN = 0x28;
137 static constexpr char KEY_RIGHT_PAREN = 0x29;
138 static constexpr char KEY_ASTERISK = 0x2A;
139 static constexpr char KEY_PLUS = 0x2B;
140 static constexpr char KEY_COMMA = 0x2C;
141 static constexpr char KEY_MINUS = 0x2D;
142 static constexpr char KEY_PERIOD = 0x2E;
143 static constexpr char KEY_SLASH = 0x2F;
144 static constexpr char KEY_COLON = 0x3A;
145 static constexpr char KEY_SEMICOLON = 0x3B;
146 static constexpr char KEY_LESS_THAN = 0x3C;
147 static constexpr char KEY_EQUAL = 0x3D;
148 static constexpr char KEY_GREATER_THAN = 0x3E;
149 static constexpr char KEY_QUESTION = 0x3F;
150 static constexpr char KEY_AT = 0x40;
151 static constexpr char KEY_LEFT_BRACKET = 0x5B;
152 static constexpr char KEY_BACKSLASH = 0x5C;
153 static constexpr char KEY_RIGHT_BRACKET = 0x5D;
154 static constexpr char KEY_CARET = 0x5E;
155 static constexpr char KEY_UNDERSCORE = 0x5F;
156 static constexpr char KEY_GRAVE = 0x60;
157 static constexpr char KEY_LEFT_CURLY = 0x7B;
158 static constexpr char KEY_VERTICAL_BAR = 0x7C;
159 static constexpr char KEY_RIGHT_CURLY = 0x7D;
160 static constexpr char KEY_TILDE = 0x7E;
162 /* *************************************************************************************
163 * Static Method
164 */
165 public:
178 static inline bool isTokenSymbol(char c) {
179 return ((c == ' ') || (c == Character::KEY_TAB) || (c == Character::KEY_CR) ||
180 (c == Character::KEY_LF) || (c == Character::KEY_NUL));
181 }
182
193 static inline bool isNextLineSymbol(char c) {
194 return ((c == Character::KEY_CR) || (c == Character::KEY_LF) ||
195 (c == Character::KEY_NUL));
196 }
197
207 static inline bool isHexChar(char c) {
208 if ((c >= '0') && (c <= '9')) return true;
209 if ((c >= 'a') && (c <= 'f')) return true;
210 if ((c >= 'A') && (c <= 'F')) return true;
211 return false;
212 }
213
223 static inline bool isNumberChar(char c) {
224 return ((c >= '0') && (c <= '9'));
225 }
226
236 static inline bool isPrintable(char c) {
237 return ((c >= ' ') && (c <= '~'));
238 }
239
249 static inline bool isControl(char c) {
250 return (((c > Character::KEY_NUL) && (c <= Character::KEY_US)) ||
252 }
253
262 static inline char toUpperCase(char ch) {
263 return (((ch >= 'a') && (ch <= 'z')) ? (ch - ('a' - 'A')) : ch);
264 }
265
273 static int toUpperCase(const char* src, char* dst);
274
283 static int toUpperCase(const char* src, char* dst, int length);
284
293 static inline char toLowerCase(char ch) {
294 return (((ch >= 'A') && (ch <= 'Z')) ? (ch + ('a' - 'A')) : ch);
295 }
296
304 static int toLowerCase(const char* src, char* dst);
305
314 static int toLowerCase(const char* src, char* dst, int length);
315
325 static bool hexCharToChar(char& result, char highChar, char lowChar);
326
335 static bool hexCharToChar(char& result, char source);
336
345 static inline bool compare(char src1, char src2) {
346 return (src1 == src2);
347 }
348
358 static bool compare(const char* str1, const char* str2, int length = -1);
359
368 static inline bool compareIgnoreCast(char src1, char src2) {
369 return (Character::toLowerCase(src1) == Character::toLowerCase(src2));
370 }
371
381 static bool compareIgnoreCast(const char* src1, const char* src2, int length = -1);
382
394 static bool compareTokenIgnoreCast(const char* src1, const char* src2, int length = -1);
395
402 static int length(const char* src);
403
413 static int lengthToken(const char* src);
414
422 static inline bool isHexString(const ufm::lang::Data& source);
423
432 static bool parseHexString(ufm::lang::Data& result, const ufm::lang::Data& source);
433};
434
446 LF,
447 CR,
448 CRLF
449};
450
451/* ***************************************************************************************
452 * End of file
453 */
454
455#endif /* MFRAME_5098703C_A1D7_4D60_9E2D_E5F648A0C629 */
字元操作工具類別
Definition Character.h:45
LineEnding
行結尾類型的列舉類型。
Definition Character.h:445
static constexpr char KEY_RIGHT_CURLY
Definition Character.h:159
static bool isNumberChar(char c)
判斷字元是否為數字
Definition Character.h:223
static char toUpperCase(char ch)
將單一字元轉換為大寫
Definition Character.h:262
static bool compare(char src1, char src2)
字元比較
Definition Character.h:345
static constexpr char KEY_EOT
Definition Character.h:97
static bool isHexString(const ufm::lang::Data &source)
判斷目標是否為16進制字串。
static bool compareIgnoreCast(char src1, char src2)
字元比較且忽略大小寫
Definition Character.h:368
static constexpr char KEY_RIGHT_PAREN
Definition Character.h:137
static bool isControl(char c)
判斷字元是否為控制字元
Definition Character.h:249
static constexpr char KEY_EM
Definition Character.h:118
static bool hexCharToChar(char &result, char source)
將16進制文字轉換至數值。
static constexpr char KEY_BACKSLASH
Definition Character.h:152
static constexpr char KEY_VERTICAL_BAR
Definition Character.h:158
static char toLowerCase(char ch)
將單一字元轉換為小寫
Definition Character.h:293
static constexpr char KEY_LF
Definition Character.h:103
static constexpr char KEY_LEFT_BRACKET
Definition Character.h:151
static constexpr char KEY_DC2
Definition Character.h:111
static constexpr char KEY_STX
Definition Character.h:95
static constexpr char KEY_SEMICOLON
Definition Character.h:145
static constexpr char KEY_AT
Definition Character.h:150
static int toUpperCase(const char *src, char *dst, int length)
將字串轉換為大寫,當遇到'\0'或滿足最大轉換長度時停止。
static constexpr char KEY_SUB
Definition Character.h:119
static constexpr char KEY_SO
Definition Character.h:107
static constexpr char KEY_ETX
Definition Character.h:96
virtual ~Character(void) override=default
銷毀 Character 物件
static constexpr char KEY_DC1
Definition Character.h:110
static constexpr char KEY_DC4
Definition Character.h:113
static constexpr char KEY_PERCENT
Definition Character.h:133
static constexpr char KEY_LEFT_PAREN
Definition Character.h:136
static constexpr char KEY_DLE
Definition Character.h:109
static constexpr char KEY_SYN
Definition Character.h:115
static constexpr char KEY_LESS_THAN
Definition Character.h:146
static constexpr char KEY_COMMA
Definition Character.h:140
static constexpr char KEY_ESC
Definition Character.h:120
static constexpr char KEY_DOLLAR
Definition Character.h:132
static constexpr char KEY_EXCLAM
Definition Character.h:129
static bool compare(const char *str1, const char *str2, int length=-1)
字符串比較
static bool isPrintable(char c)
判斷字元是否為可列印字元
Definition Character.h:236
static constexpr char KEY_MINUS
Definition Character.h:141
static constexpr char KEY_ETB
Definition Character.h:116
static constexpr char KEY_ASTERISK
Definition Character.h:138
static constexpr char KEY_TAB
Definition Character.h:102
static int toUpperCase(const char *src, char *dst)
將字串轉換為大寫,當遇到'\0'時停止。
static constexpr char KEY_GRAVE
Definition Character.h:156
static constexpr char KEY_EQUAL
Definition Character.h:147
static constexpr char KEY_RS
Definition Character.h:123
static constexpr char KEY_SLASH
Definition Character.h:143
static int lengthToken(const char *src)
取得字符串長度,當遇到斷落或滿足最大長度時返回計數
static constexpr char KEY_SOH
Definition Character.h:94
static constexpr char KEY_AMPERSAND
Definition Character.h:134
static constexpr char KEY_ENQ
Definition Character.h:98
static constexpr char KEY_CR
Definition Character.h:106
static constexpr char KEY_QUESTION
Definition Character.h:149
static bool isNextLineSymbol(char c)
Check if the character is a newline control symbol.
Definition Character.h:193
static constexpr char KEY_VT
Definition Character.h:104
static bool compareTokenIgnoreCast(const char *src1, const char *src2, int length=-1)
比較字符串且忽略大小寫,直到遇到斷落符號或滿足最大長度
static constexpr char KEY_CAN
Definition Character.h:117
static constexpr char KEY_RIGHT_BRACKET
Definition Character.h:153
static bool isTokenSymbol(char c)
Check if the character is a separator symbol.
Definition Character.h:178
static constexpr char KEY_PLUS
Definition Character.h:139
static constexpr char KEY_SPACE
Definition Character.h:128
static constexpr char KEY_LEFT_CURLY
Definition Character.h:157
static constexpr char KEY_ACK
Definition Character.h:99
static int length(const char *src)
取得字符串長度,當遇到'\0'時返回計數
static constexpr char KEY_FS
Definition Character.h:121
static constexpr char KEY_TILDE
Definition Character.h:160
static int toLowerCase(const char *src, char *dst, int length)
將字串轉換為小寫,當遇到'\0'或滿足最大轉換長度時停止。
static bool isHexChar(char c)
判斷字元是否為十六進位字元
Definition Character.h:207
static constexpr char KEY_GS
Definition Character.h:122
static bool compareIgnoreCast(const char *src1, const char *src2, int length=-1)
比較字符串且忽略大小寫,限定字符串最大長度為length
static constexpr char KEY_CARET
Definition Character.h:154
static constexpr char KEY_BEL
Definition Character.h:100
static int toLowerCase(const char *src, char *dst)
將字串轉換為小寫,當遇到'\0'時停止。
static bool hexCharToChar(char &result, char highChar, char lowChar)
將16進制文字轉換至數值。
static constexpr char KEY_NUL
Definition Character.h:93
static constexpr char KEY_US
Definition Character.h:124
static constexpr char KEY_UNDERSCORE
Definition Character.h:155
static constexpr char KEY_PERIOD
Definition Character.h:142
static constexpr char KEY_QUOTE
Definition Character.h:130
static constexpr char KEY_HASH
Definition Character.h:131
static constexpr char KEY_SI
Definition Character.h:108
static bool parseHexString(ufm::lang::Data &result, const ufm::lang::Data &source)
將二進制字串轉換為位元組資料。
static constexpr char KEY_BACKSPACE
Definition Character.h:125
static constexpr char KEY_GREATER_THAN
Definition Character.h:148
static constexpr char KEY_FF
Definition Character.h:105
static constexpr char KEY_NAK
Definition Character.h:114
static constexpr char KEY_BS
Definition Character.h:101
static constexpr char KEY_COLON
Definition Character.h:144
static constexpr char KEY_DC3
Definition Character.h:112
static constexpr char KEY_APOSTROPHE
Definition Character.h:135
資料處理類別
Definition Data.h:43
Definition NonInstantiable.h:29
Definition Appendable.h:23