@react-native-ohos/react-native-text-input-mask 3.1.6-rc.1 → 3.1.6-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/LICENSE +21 -21
  2. package/README.OpenSource +10 -10
  3. package/README.md +15 -134
  4. package/dist/tsconfig.tsbuildinfo +1 -1
  5. package/harmony/text_input_mask/BuildProfile.ets +16 -16
  6. package/harmony/text_input_mask/Index.ets +7 -7
  7. package/harmony/text_input_mask/build-profile.json5 +31 -31
  8. package/harmony/text_input_mask/hvigorfile.ts +6 -6
  9. package/harmony/text_input_mask/obfuscation-rules.txt +22 -22
  10. package/harmony/text_input_mask/oh-package.json5 +11 -11
  11. package/harmony/text_input_mask/src/main/cpp/CMakeLists.txt +9 -9
  12. package/harmony/text_input_mask/src/main/cpp/RNTextInputMask.cpp +421 -415
  13. package/harmony/text_input_mask/src/main/cpp/RNTextInputMask.h +93 -93
  14. package/harmony/text_input_mask/src/main/cpp/RNTextInputMaskPackage.h +31 -31
  15. package/harmony/text_input_mask/src/main/cpp/common/Compiler.h +174 -174
  16. package/harmony/text_input_mask/src/main/cpp/common/FormatError.h +22 -22
  17. package/harmony/text_input_mask/src/main/cpp/common/FormatSanitizer.h +230 -230
  18. package/harmony/text_input_mask/src/main/cpp/common/Mask.h +380 -377
  19. package/harmony/text_input_mask/src/main/cpp/common/RTLMask.h +78 -78
  20. package/harmony/text_input_mask/src/main/cpp/common/model/AffinityCalculationStrategy.h +57 -57
  21. package/harmony/text_input_mask/src/main/cpp/common/model/CaretString.h +75 -75
  22. package/harmony/text_input_mask/src/main/cpp/common/model/CaretStringIterator.h +58 -58
  23. package/harmony/text_input_mask/src/main/cpp/common/model/Next.h +24 -24
  24. package/harmony/text_input_mask/src/main/cpp/common/model/Notation.h +29 -24
  25. package/harmony/text_input_mask/src/main/cpp/common/model/RTLCaretStringIterator.h +22 -22
  26. package/harmony/text_input_mask/src/main/cpp/common/model/State.h +302 -302
  27. package/harmony/text_input_mask/src/main/cpp/common/model/common.h +94 -94
  28. package/harmony/text_input_mask/src/main/ets/RNTextInputMaskPackage.ts +28 -28
  29. package/harmony/text_input_mask/src/main/ets/RNTextInputMaskTurboModle.ts +32 -32
  30. package/harmony/text_input_mask/src/main/module.json5 +11 -11
  31. package/harmony/text_input_mask/src/main/resources/base/element/string.json +8 -8
  32. package/harmony/text_input_mask/src/main/resources/en_US/element/string.json +8 -8
  33. package/harmony/text_input_mask/src/main/resources/zh_CN/element/string.json +8 -8
  34. package/harmony/text_input_mask/ts.ts +8 -8
  35. package/harmony/text_input_mask.har +0 -0
  36. package/index.tsx +258 -258
  37. package/package.json +48 -50
  38. package/src/RNNativeTextInputMask.ts +142 -142
  39. package/src/index.harmony.ts +147 -147
  40. package/src/index.ts +36 -36
@@ -1,23 +1,23 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
- * Use of this source code is governed by a MIT license that can be
4
- * found in the LICENSE file.
5
- */
6
-
7
- #pragma once
8
- #include "CaretString.h"
9
- #include "CaretStringIterator.h"
10
-
11
- namespace TinpMask {
12
-
13
- class RTLCaretStringIterator : public CaretStringIterator {
14
- public:
15
- RTLCaretStringIterator(const CaretString& caretString)
16
- : CaretStringIterator(caretString) {}
17
-
18
- bool insertionAffectsCaret() {
19
- return currentIndex <= caretString.caretPosition;
20
- }
21
- };
22
-
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ #pragma once
8
+ #include "CaretString.h"
9
+ #include "CaretStringIterator.h"
10
+
11
+ namespace TinpMask {
12
+
13
+ class RTLCaretStringIterator : public CaretStringIterator {
14
+ public:
15
+ RTLCaretStringIterator(const CaretString& caretString)
16
+ : CaretStringIterator(caretString) {}
17
+
18
+ bool insertionAffectsCaret() {
19
+ return currentIndex <= caretString.caretPosition;
20
+ }
21
+ };
22
+
23
23
  }
@@ -1,302 +1,302 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
- * Use of this source code is governed by a MIT license that can be
4
- * found in the LICENSE file.
5
- */
6
-
7
- #pragma once
8
- #include <memory>
9
- #include <iostream>
10
-
11
- namespace TinpMask {
12
-
13
-
14
- class Next;
15
- class State {
16
- public:
17
- std::shared_ptr<State> child; // 指向下一个状态的智能指针
18
-
19
- public:
20
- // 构造函数
21
- explicit State(std::shared_ptr<State> child = nullptr) : child(child) {}
22
-
23
- // 虚析构函数,以确保派生类的析构函数被正确调用
24
- virtual ~State() = default;
25
-
26
- /**
27
- * Abstract method.
28
- *
29
- * Defines whether the state accepts user input character or not, and which actions should take
30
- * place when the character is accepted.
31
- *
32
- * @param character character from the user input string.
33
- *
34
- * @returns Next object instance with a set of actions that should take place when the user
35
- * input character is accepted.
36
- *
37
- * @throws Fatal error, if the method is not implemented.
38
- */
39
- virtual std::shared_ptr<Next> accept(char character) = 0;
40
-
41
- /**
42
- * Automatically complete user input.
43
- *
44
- * @returns Next object instance with a set of actions to complete user input. If no
45
- * autocomplete available, returns nullptr.
46
- */
47
- virtual std::shared_ptr<Next> autocomplete() {
48
- return nullptr; // 默认返回 nullptr
49
- }
50
-
51
- /**
52
- * Obtain the next state.
53
- *
54
- * Sometimes it is necessary to override this behavior. For instance, State may want to
55
- * return self as the next state under certain conditions.
56
- *
57
- * @returns State object.
58
- */
59
- virtual std::shared_ptr<State> nextState() {
60
- return child; // 返回下一个状态
61
- }
62
-
63
- // 转换为字符串表示
64
- virtual std::string toString() const { return "BASE -> " + (child ? child->toString() : "null"); }
65
- };
66
-
67
- // EOLState 类的实现
68
- class EOLState : public State {
69
- public:
70
- EOLState(std::shared_ptr<State> child = nullptr) : State(child) {}
71
-
72
- std::shared_ptr<Next> accept(char character) override {
73
- return nullptr; // 该状态不接受字符
74
- }
75
-
76
- std::string toString() const override {
77
- return "EOL"; // 返回字符串表示
78
- }
79
- };
80
-
81
-
82
- // FixedState 类的实现
83
- class FixedState : public State {
84
- public:
85
- char ownCharacter;
86
-
87
- public:
88
- FixedState(std::shared_ptr<State> child, char ownCharacter) : State(child), ownCharacter(ownCharacter) {}
89
-
90
- std::shared_ptr<Next> accept(char character) override {
91
- if (this->ownCharacter == character) {
92
- return std::make_shared<Next>(this->nextState(), character, true, character);
93
- } else {
94
- return std::make_shared<Next>(this->nextState(), this->ownCharacter, false, this->ownCharacter);
95
- }
96
- }
97
-
98
- std::shared_ptr<Next> autocomplete() override {
99
- return std::make_shared<Next>(this->nextState(), this->ownCharacter, false, this->ownCharacter);
100
- }
101
-
102
- std::string toString() const override {
103
- return "{" + std::string(1, this->ownCharacter) + "} -> " + (child ? child->toString() : "null");
104
- }
105
- };
106
-
107
- // FreeState 类的实现
108
- class FreeState : public State {
109
- public:
110
- char ownCharacter;
111
-
112
- public:
113
- FreeState(std::shared_ptr<State> child, char ownCharacter) : State(child), ownCharacter(ownCharacter) {}
114
-
115
- std::shared_ptr<Next> accept(char character) override {
116
- if (this->ownCharacter == character) {
117
- return std::make_shared<Next>(this->nextState(), character, true, '\0');
118
- } else {
119
- return std::make_shared<Next>(this->nextState(), this->ownCharacter, false, '\0');
120
- }
121
- }
122
-
123
- std::shared_ptr<Next> autocomplete() override {
124
- return std::make_shared<Next>(this->nextState(), this->ownCharacter, false, '\0');
125
- }
126
-
127
- std::string toString() const override {
128
- return std::string(1, this->ownCharacter) + " -> " + (child ? child->toString() : "null");
129
- }
130
- };
131
- enum StateTypeName { Numeric, Literal, AlphaNumeric, Custom };
132
- class OptionalValueState : public State {
133
- public:
134
- class OptionalValueStateType {
135
- public:
136
- virtual StateTypeName getName() = 0;
137
- };
138
-
139
- class Numeric : public OptionalValueStateType {
140
- public:
141
- StateTypeName getName() override { return StateTypeName::Numeric; }
142
- };
143
- class Literal : public OptionalValueStateType {
144
- public:
145
- StateTypeName getName() override { return StateTypeName::Literal; }
146
- };
147
- class AlphaNumeric : public OptionalValueStateType {
148
- public:
149
- StateTypeName getName() override { return StateTypeName::AlphaNumeric; }
150
- };
151
-
152
- class Custom : public OptionalValueStateType {
153
- public:
154
- char character;
155
- std::string characterSet;
156
- StateTypeName getName() override { return StateTypeName::Custom; }
157
- Custom(char character, const std::string &characterSet) : character(character), characterSet(characterSet) {}
158
- };
159
-
160
- public:
161
- std::shared_ptr<OptionalValueStateType> type;
162
-
163
- bool accepts(char character) {
164
- if (dynamic_cast<Numeric *>(type.get())) {
165
- return std::isdigit(character);
166
- } else if (dynamic_cast<Literal *>(type.get())) {
167
- return std::isalpha(character);
168
- } else if (dynamic_cast<AlphaNumeric *>(type.get())) {
169
- return std::isalnum(character);
170
- } else if (auto customType = dynamic_cast<Custom *>(type.get())) {
171
- return customType->characterSet.find(character) != std::string::npos;
172
- }
173
- return false;
174
- }
175
-
176
- OptionalValueState(std::shared_ptr<State> child, std::shared_ptr<OptionalValueStateType> type)
177
- : State(child), type(type) {}
178
-
179
- OptionalValueState(std::shared_ptr<State> child, std::shared_ptr<OptionalValueStateType> &type)
180
- : State(child), type(type) {}
181
-
182
- std::shared_ptr<Next> accept(char character) override {
183
- if (this->accepts(character)) {
184
- return std::make_shared<Next>(this->nextState(), character, true, character);
185
- } else {
186
- return std::make_shared<Next>(this->nextState(), '\0', false, '\0');
187
- }
188
- }
189
-
190
- std::string toString() const override {
191
- if (dynamic_cast<Literal *>(type.get())) {
192
- return "[a] -> " + (child ? child->toString() : "null");
193
- } else if (dynamic_cast<Numeric *>(type.get())) {
194
- return "[9] -> " + (child ? child->toString() : "null");
195
- } else if (dynamic_cast<AlphaNumeric *>(type.get())) {
196
- return "[-] -> " + (child ? child->toString() : "null");
197
- } else if (auto customType = dynamic_cast<Custom *>(type.get())) {
198
- return "[" + std::string(1, customType->character) + "] -> " + (child ? child->toString() : "null");
199
- }
200
- return "unknown -> null";
201
- }
202
- };
203
-
204
- // ValueState 类定义
205
- class ValueState : public State, public std::enable_shared_from_this<ValueState> {
206
- public:
207
- class ValueStateType {
208
- public:
209
- virtual StateTypeName getName() = 0;
210
- };
211
-
212
- class Numeric : public ValueStateType {
213
- public:
214
- StateTypeName getName() override { return StateTypeName::Numeric; }
215
- };
216
- class Literal : public ValueStateType {
217
- public:
218
- StateTypeName getName() override { return StateTypeName::Literal; }
219
- };
220
- class AlphaNumeric : public ValueStateType {
221
- public:
222
- StateTypeName getName() override { return StateTypeName::AlphaNumeric; }
223
- };
224
- class Ellipsis : public ValueStateType {
225
- public:
226
- std::shared_ptr<ValueStateType> inheritedType;
227
- explicit Ellipsis(std::shared_ptr<ValueStateType> inheritedType) : inheritedType(inheritedType) {}
228
- StateTypeName getName() override { return StateTypeName::Custom; }
229
- };
230
- class Custom : public ValueStateType {
231
-
232
- public:
233
- char character;
234
- std::string characterSet;
235
- Custom(char character, const std::string &characterSet) : character(character), characterSet(characterSet) {}
236
- StateTypeName getName() override { return StateTypeName::Custom; }
237
- };
238
-
239
- public:
240
- std::shared_ptr<ValueStateType> type;
241
- bool accepts(char character) {
242
- if (dynamic_cast<Numeric *>(type.get())) {
243
- return std::isdigit(character);
244
- } else if (dynamic_cast<Literal *>(type.get())) {
245
- return std::isalpha(character);
246
- } else if (dynamic_cast<AlphaNumeric *>(type.get())) {
247
- return std::isalnum(character);
248
- } else if (auto ellipsisType = dynamic_cast<Ellipsis *>(type.get())) {
249
- return acceptsWithInheritedType(ellipsisType->inheritedType, character);
250
- } else if (auto customType = dynamic_cast<Custom *>(type.get())) {
251
- return customType->characterSet.find(character) != std::string::npos;
252
- }
253
- return false;
254
- }
255
-
256
- bool acceptsWithInheritedType(std::shared_ptr<ValueStateType> inheritedType, char character) {
257
- if (dynamic_cast<Numeric *>(inheritedType.get())) {
258
- return std::isdigit(character);
259
- } else if (dynamic_cast<Literal *>(inheritedType.get())) {
260
- return std::isalpha(character);
261
- } else if (dynamic_cast<AlphaNumeric *>(inheritedType.get())) {
262
- return std::isalnum(character);
263
- } else if (auto customType = dynamic_cast<Custom *>(inheritedType.get())) {
264
- return customType->characterSet.find(character) != std::string::npos;
265
- }
266
- return false;
267
- }
268
-
269
- public:
270
- // 构造函数用于创建 Ellipsis 类型的 ValueState
271
- ValueState(std::shared_ptr<ValueStateType> inheritedType)
272
- : State(nullptr), type(std::make_shared<Ellipsis>(inheritedType)) {}
273
-
274
- ValueState(std::shared_ptr<State> child, std::shared_ptr<ValueStateType> type) : State(child), type(type) {}
275
-
276
- std::shared_ptr<Next> accept(char character) override {
277
- if (!accepts(character))
278
- return nullptr;
279
- return std::make_shared<Next>(nextState(), character, true, character);
280
- }
281
-
282
- bool isElliptical() const { return dynamic_cast<Ellipsis *>(type.get()) != nullptr; }
283
-
284
- std::shared_ptr<State> nextState() override { return isElliptical() ? shared_from_this() : State::nextState(); }
285
-
286
- std::string toString() const override {
287
- if (dynamic_cast<Literal *>(type.get())) {
288
- return "[A] -> " + (child ? child->toString() : "null");
289
- } else if (dynamic_cast<Numeric *>(type.get())) {
290
- return "[0] -> " + (child ? child->toString() : "null");
291
- } else if (dynamic_cast<AlphaNumeric *>(type.get())) {
292
- return "[_] -> " + (child ? child->toString() : "null");
293
- } else if (dynamic_cast<Ellipsis *>(type.get())) {
294
- return "[…] -> " + (child ? child->toString() : "null");
295
- } else if (auto customType = dynamic_cast<Custom *>(type.get())) {
296
- return "[" + std::string(1, customType->character) + "] -> " + (child ? child->toString() : "null");
297
- }
298
- return "unknown -> null";
299
- }
300
- };
301
-
302
- }
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ #pragma once
8
+ #include <memory>
9
+ #include <iostream>
10
+
11
+ namespace TinpMask {
12
+
13
+
14
+ class Next;
15
+ class State {
16
+ public:
17
+ std::shared_ptr<State> child; // 指向下一个状态的智能指针
18
+
19
+ public:
20
+ // 构造函数
21
+ explicit State(std::shared_ptr<State> child = nullptr) : child(child) {}
22
+
23
+ // 虚析构函数,以确保派生类的析构函数被正确调用
24
+ virtual ~State() = default;
25
+
26
+ /**
27
+ * Abstract method.
28
+ *
29
+ * Defines whether the state accepts user input character or not, and which actions should take
30
+ * place when the character is accepted.
31
+ *
32
+ * @param character character from the user input string.
33
+ *
34
+ * @returns Next object instance with a set of actions that should take place when the user
35
+ * input character is accepted.
36
+ *
37
+ * @throws Fatal error, if the method is not implemented.
38
+ */
39
+ virtual std::shared_ptr<Next> accept(char character) = 0;
40
+
41
+ /**
42
+ * Automatically complete user input.
43
+ *
44
+ * @returns Next object instance with a set of actions to complete user input. If no
45
+ * autocomplete available, returns nullptr.
46
+ */
47
+ virtual std::shared_ptr<Next> autocomplete() {
48
+ return nullptr; // 默认返回 nullptr
49
+ }
50
+
51
+ /**
52
+ * Obtain the next state.
53
+ *
54
+ * Sometimes it is necessary to override this behavior. For instance, State may want to
55
+ * return self as the next state under certain conditions.
56
+ *
57
+ * @returns State object.
58
+ */
59
+ virtual std::shared_ptr<State> nextState() {
60
+ return child; // 返回下一个状态
61
+ }
62
+
63
+ // 转换为字符串表示
64
+ virtual std::string toString() const { return "BASE -> " + (child ? child->toString() : "null"); }
65
+ };
66
+
67
+ // EOLState 类的实现
68
+ class EOLState : public State {
69
+ public:
70
+ EOLState(std::shared_ptr<State> child = nullptr) : State(child) {}
71
+
72
+ std::shared_ptr<Next> accept(char character) override {
73
+ return nullptr; // 该状态不接受字符
74
+ }
75
+
76
+ std::string toString() const override {
77
+ return "EOL"; // 返回字符串表示
78
+ }
79
+ };
80
+
81
+
82
+ // FixedState 类的实现
83
+ class FixedState : public State {
84
+ public:
85
+ char ownCharacter;
86
+
87
+ public:
88
+ FixedState(std::shared_ptr<State> child, char ownCharacter) : State(child), ownCharacter(ownCharacter) {}
89
+
90
+ std::shared_ptr<Next> accept(char character) override {
91
+ if (this->ownCharacter == character) {
92
+ return std::make_shared<Next>(this->nextState(), character, true, character);
93
+ } else {
94
+ return std::make_shared<Next>(this->nextState(), this->ownCharacter, false, this->ownCharacter);
95
+ }
96
+ }
97
+
98
+ std::shared_ptr<Next> autocomplete() override {
99
+ return std::make_shared<Next>(this->nextState(), this->ownCharacter, false, this->ownCharacter);
100
+ }
101
+
102
+ std::string toString() const override {
103
+ return "{" + std::string(1, this->ownCharacter) + "} -> " + (child ? child->toString() : "null");
104
+ }
105
+ };
106
+
107
+ // FreeState 类的实现
108
+ class FreeState : public State {
109
+ public:
110
+ char ownCharacter;
111
+
112
+ public:
113
+ FreeState(std::shared_ptr<State> child, char ownCharacter) : State(child), ownCharacter(ownCharacter) {}
114
+
115
+ std::shared_ptr<Next> accept(char character) override {
116
+ if (this->ownCharacter == character) {
117
+ return std::make_shared<Next>(this->nextState(), character, true, '\0');
118
+ } else {
119
+ return std::make_shared<Next>(this->nextState(), this->ownCharacter, false, '\0');
120
+ }
121
+ }
122
+
123
+ std::shared_ptr<Next> autocomplete() override {
124
+ return std::make_shared<Next>(this->nextState(), this->ownCharacter, false, '\0');
125
+ }
126
+
127
+ std::string toString() const override {
128
+ return std::string(1, this->ownCharacter) + " -> " + (child ? child->toString() : "null");
129
+ }
130
+ };
131
+ enum StateTypeName { Numeric, Literal, AlphaNumeric, Custom };
132
+ class OptionalValueState : public State {
133
+ public:
134
+ class OptionalValueStateType {
135
+ public:
136
+ virtual StateTypeName getName() = 0;
137
+ };
138
+
139
+ class Numeric : public OptionalValueStateType {
140
+ public:
141
+ StateTypeName getName() override { return StateTypeName::Numeric; }
142
+ };
143
+ class Literal : public OptionalValueStateType {
144
+ public:
145
+ StateTypeName getName() override { return StateTypeName::Literal; }
146
+ };
147
+ class AlphaNumeric : public OptionalValueStateType {
148
+ public:
149
+ StateTypeName getName() override { return StateTypeName::AlphaNumeric; }
150
+ };
151
+
152
+ class Custom : public OptionalValueStateType {
153
+ public:
154
+ char character;
155
+ std::string characterSet;
156
+ StateTypeName getName() override { return StateTypeName::Custom; }
157
+ Custom(char character, const std::string &characterSet) : character(character), characterSet(characterSet) {}
158
+ };
159
+
160
+ public:
161
+ std::shared_ptr<OptionalValueStateType> type;
162
+
163
+ bool accepts(char character) {
164
+ if (dynamic_cast<Numeric *>(type.get())) {
165
+ return std::isdigit(character);
166
+ } else if (dynamic_cast<Literal *>(type.get())) {
167
+ return std::isalpha(character);
168
+ } else if (dynamic_cast<AlphaNumeric *>(type.get())) {
169
+ return std::isalnum(character);
170
+ } else if (auto customType = dynamic_cast<Custom *>(type.get())) {
171
+ return customType->characterSet.find(character) != std::string::npos;
172
+ }
173
+ return false;
174
+ }
175
+
176
+ OptionalValueState(std::shared_ptr<State> child, std::shared_ptr<OptionalValueStateType> type)
177
+ : State(child), type(type) {}
178
+
179
+ OptionalValueState(std::shared_ptr<State> child, std::shared_ptr<OptionalValueStateType> &type)
180
+ : State(child), type(type) {}
181
+
182
+ std::shared_ptr<Next> accept(char character) override {
183
+ if (this->accepts(character)) {
184
+ return std::make_shared<Next>(this->nextState(), character, true, character);
185
+ } else {
186
+ return std::make_shared<Next>(this->nextState(), '\0', false, '\0');
187
+ }
188
+ }
189
+
190
+ std::string toString() const override {
191
+ if (dynamic_cast<Literal *>(type.get())) {
192
+ return "[a] -> " + (child ? child->toString() : "null");
193
+ } else if (dynamic_cast<Numeric *>(type.get())) {
194
+ return "[9] -> " + (child ? child->toString() : "null");
195
+ } else if (dynamic_cast<AlphaNumeric *>(type.get())) {
196
+ return "[-] -> " + (child ? child->toString() : "null");
197
+ } else if (auto customType = dynamic_cast<Custom *>(type.get())) {
198
+ return "[" + std::string(1, customType->character) + "] -> " + (child ? child->toString() : "null");
199
+ }
200
+ return "unknown -> null";
201
+ }
202
+ };
203
+
204
+ // ValueState 类定义
205
+ class ValueState : public State, public std::enable_shared_from_this<ValueState> {
206
+ public:
207
+ class ValueStateType {
208
+ public:
209
+ virtual StateTypeName getName() = 0;
210
+ };
211
+
212
+ class Numeric : public ValueStateType {
213
+ public:
214
+ StateTypeName getName() override { return StateTypeName::Numeric; }
215
+ };
216
+ class Literal : public ValueStateType {
217
+ public:
218
+ StateTypeName getName() override { return StateTypeName::Literal; }
219
+ };
220
+ class AlphaNumeric : public ValueStateType {
221
+ public:
222
+ StateTypeName getName() override { return StateTypeName::AlphaNumeric; }
223
+ };
224
+ class Ellipsis : public ValueStateType {
225
+ public:
226
+ std::shared_ptr<ValueStateType> inheritedType;
227
+ explicit Ellipsis(std::shared_ptr<ValueStateType> inheritedType) : inheritedType(inheritedType) {}
228
+ StateTypeName getName() override { return StateTypeName::Custom; }
229
+ };
230
+ class Custom : public ValueStateType {
231
+
232
+ public:
233
+ char character;
234
+ std::string characterSet;
235
+ Custom(char character, const std::string &characterSet) : character(character), characterSet(characterSet) {}
236
+ StateTypeName getName() override { return StateTypeName::Custom; }
237
+ };
238
+
239
+ public:
240
+ std::shared_ptr<ValueStateType> type;
241
+ bool accepts(char character) {
242
+ if (dynamic_cast<Numeric *>(type.get())) {
243
+ return std::isdigit(character);
244
+ } else if (dynamic_cast<Literal *>(type.get())) {
245
+ return std::isalpha(character);
246
+ } else if (dynamic_cast<AlphaNumeric *>(type.get())) {
247
+ return std::isalnum(character);
248
+ } else if (auto ellipsisType = dynamic_cast<Ellipsis *>(type.get())) {
249
+ return acceptsWithInheritedType(ellipsisType->inheritedType, character);
250
+ } else if (auto customType = dynamic_cast<Custom *>(type.get())) {
251
+ return customType->characterSet.find(character) != std::string::npos;
252
+ }
253
+ return false;
254
+ }
255
+
256
+ bool acceptsWithInheritedType(std::shared_ptr<ValueStateType> inheritedType, char character) {
257
+ if (dynamic_cast<Numeric *>(inheritedType.get())) {
258
+ return std::isdigit(character);
259
+ } else if (dynamic_cast<Literal *>(inheritedType.get())) {
260
+ return std::isalpha(character);
261
+ } else if (dynamic_cast<AlphaNumeric *>(inheritedType.get())) {
262
+ return std::isalnum(character);
263
+ } else if (auto customType = dynamic_cast<Custom *>(inheritedType.get())) {
264
+ return customType->characterSet.find(character) != std::string::npos;
265
+ }
266
+ return false;
267
+ }
268
+
269
+ public:
270
+ // 构造函数用于创建 Ellipsis 类型的 ValueState
271
+ ValueState(std::shared_ptr<ValueStateType> inheritedType)
272
+ : State(nullptr), type(std::make_shared<Ellipsis>(inheritedType)) {}
273
+
274
+ ValueState(std::shared_ptr<State> child, std::shared_ptr<ValueStateType> type) : State(child), type(type) {}
275
+
276
+ std::shared_ptr<Next> accept(char character) override {
277
+ if (!accepts(character))
278
+ return nullptr;
279
+ return std::make_shared<Next>(nextState(), character, true, character);
280
+ }
281
+
282
+ bool isElliptical() const { return dynamic_cast<Ellipsis *>(type.get()) != nullptr; }
283
+
284
+ std::shared_ptr<State> nextState() override { return isElliptical() ? shared_from_this() : State::nextState(); }
285
+
286
+ std::string toString() const override {
287
+ if (dynamic_cast<Literal *>(type.get())) {
288
+ return "[A] -> " + (child ? child->toString() : "null");
289
+ } else if (dynamic_cast<Numeric *>(type.get())) {
290
+ return "[0] -> " + (child ? child->toString() : "null");
291
+ } else if (dynamic_cast<AlphaNumeric *>(type.get())) {
292
+ return "[_] -> " + (child ? child->toString() : "null");
293
+ } else if (dynamic_cast<Ellipsis *>(type.get())) {
294
+ return "[…] -> " + (child ? child->toString() : "null");
295
+ } else if (auto customType = dynamic_cast<Custom *>(type.get())) {
296
+ return "[" + std::string(1, customType->character) + "] -> " + (child ? child->toString() : "null");
297
+ }
298
+ return "unknown -> null";
299
+ }
300
+ };
301
+
302
+ }