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

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 (51) hide show
  1. package/.eslintrc +16 -0
  2. package/.gitattributes +1 -0
  3. package/.mtslconfig.json +1 -0
  4. package/OAT.xml +79 -0
  5. package/README.md +6 -8
  6. package/dist/index.d.ts +0 -2
  7. package/dist/index.js +6 -25
  8. package/dist/index.js.map +1 -1
  9. package/dist/src/RNNativeTextInputMask.d.ts +0 -1
  10. package/dist/src/RNNativeTextInputMask.js.map +1 -1
  11. package/dist/src/index.harmony.d.ts +0 -1
  12. package/dist/src/index.harmony.js +0 -3
  13. package/dist/src/index.harmony.js.map +1 -1
  14. package/dist/tsconfig.tsbuildinfo +1 -1
  15. package/harmony/text_input_mask/Index.ets +3 -1
  16. package/harmony/text_input_mask/oh-package.json5 +2 -2
  17. package/harmony/text_input_mask/src/main/cpp/RNTextInputMask.cpp +73 -96
  18. package/harmony/text_input_mask/src/main/cpp/RNTextInputMask.h +11 -9
  19. package/harmony/text_input_mask/src/main/cpp/RNTextInputMaskPackage.h +4 -2
  20. package/harmony/text_input_mask/src/main/cpp/common/Compiler.h +84 -81
  21. package/harmony/text_input_mask/src/main/cpp/common/FormatError.h +5 -5
  22. package/harmony/text_input_mask/src/main/cpp/common/FormatSanitizer.h +26 -28
  23. package/harmony/text_input_mask/src/main/cpp/common/Mask.h +48 -45
  24. package/harmony/text_input_mask/src/main/cpp/common/RTLMask.h +18 -20
  25. package/harmony/text_input_mask/src/main/cpp/common/model/AffinityCalculationStrategy.h +23 -19
  26. package/harmony/text_input_mask/src/main/cpp/common/model/CaretString.h +11 -13
  27. package/harmony/text_input_mask/src/main/cpp/common/model/CaretStringIterator.h +9 -10
  28. package/harmony/text_input_mask/src/main/cpp/common/model/Next.h +8 -8
  29. package/harmony/text_input_mask/src/main/cpp/common/model/Notation.h +11 -11
  30. package/harmony/text_input_mask/src/main/cpp/common/model/RTLCaretStringIterator.h +2 -2
  31. package/harmony/text_input_mask/src/main/cpp/common/model/State.h +43 -32
  32. package/harmony/text_input_mask/src/main/cpp/common/model/common.h +19 -11
  33. package/harmony/text_input_mask/src/main/ets/{RNTextInputMaskPackage.ts → RNTextInputMaskPackage.ets} +2 -1
  34. package/harmony/text_input_mask/src/main/ets/RNTextInputMaskTurboModle.ts +0 -4
  35. package/harmony/text_input_mask/src/ohosTest/ets/test/Ability.test.ets +41 -0
  36. package/harmony/text_input_mask/src/ohosTest/ets/test/List.test.ets +11 -0
  37. package/harmony/text_input_mask/src/ohosTest/module.json5 +13 -0
  38. package/harmony/text_input_mask/src/test/List.test.ets +11 -0
  39. package/harmony/text_input_mask/src/test/LocalUnit.test.ets +39 -0
  40. package/harmony/text_input_mask.har +0 -0
  41. package/index.tsx +5 -24
  42. package/package.json +17 -11
  43. package/src/RNNativeTextInputMask.ts +0 -1
  44. package/src/index.harmony.ts +0 -3
  45. package/tsconfig.json +43 -0
  46. package/README.OpenSource +0 -11
  47. package/dist/babel.config.d.ts +0 -7
  48. package/dist/babel.config.js +0 -16
  49. package/dist/babel.config.js.map +0 -1
  50. package/harmony/text_input_mask/BuildProfile.ets +0 -17
  51. /package/harmony/text_input_mask/{ts.ts → ts.ets} +0 -0
@@ -3,7 +3,8 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
6
+ #ifndef MASK_H
7
+ #define MASK_H
7
8
  #pragma once
8
9
  #include <string>
9
10
  #include <vector>
@@ -15,7 +16,6 @@
15
16
  #include "model/State.h"
16
17
 
17
18
  namespace TinpMask {
18
-
19
19
  class Mask {
20
20
  protected:
21
21
  std::vector<Notation> customNotations;
@@ -28,21 +28,24 @@ private:
28
28
 
29
29
  public:
30
30
  // 主构造函数
31
- Mask(const std::string &format, const std::vector<Notation> &customNotations) : customNotations(customNotations) {
31
+ Mask(const std::string &format, const std::vector<Notation> &customNotations) : customNotations(customNotations)
32
+ {
32
33
  this->format = format;
33
34
  this->customNotations = customNotations;
34
35
  this->initialState = Compiler(customNotations).compile(format);
35
36
  }
36
37
 
37
38
  // 便利构造函数
38
- Mask(const std::string &format) : Mask(format, {}) { // 调用主构造函数,传入空的 customNotations
39
+ Mask(const std::string &format) : Mask(format, {})
40
+ { // 调用主构造函数,传入空的 customNotations
39
41
  std::vector<Notation> emptyVector;
40
42
  this->format = format;
41
43
  this->customNotations = emptyVector;
42
44
  this->initialState = Compiler(this->customNotations).compile(this->format);
43
45
  }
44
46
 
45
- bool hasSameCustomNotations(const std::vector<Notation>& targetNotations) const {
47
+ bool hasSameCustomNotations(const std::vector<Notation> &targetNotations) const
48
+ {
46
49
  return this->customNotations == targetNotations;
47
50
  }
48
51
 
@@ -51,7 +54,7 @@ public:
51
54
  static std::unordered_map<std::string, std::shared_ptr<Mask>> maskCache;
52
55
 
53
56
  public:
54
- /**
57
+ /* *
55
58
  * Factory constructor.
56
59
  *
57
60
  * Operates over own ``Mask`` cache where initialized ``Mask`` objects are stored under
@@ -61,7 +64,8 @@ public:
61
64
  * doesn't exist in cache, the object is constructed, cached and returned.
62
65
  */
63
66
  static std::shared_ptr<Mask> getOrCreate(const std::string &format,
64
- const std::vector<Notation> &customNotations) {
67
+ const std::vector<Notation> &customNotations)
68
+ {
65
69
  auto cachedMask = maskCache.find(format);
66
70
  if (cachedMask == maskCache.end() || !cachedMask->second->hasSameCustomNotations(customNotations)) {
67
71
  auto newMask = std::make_shared<Mask>(format, customNotations);
@@ -71,7 +75,7 @@ public:
71
75
  return cachedMask->second;
72
76
  }
73
77
 
74
- /**
78
+ /* *
75
79
  * Check your mask format is valid.
76
80
  *
77
81
  * @param format mask format.
@@ -80,7 +84,8 @@ public:
80
84
  * @returns `true` if this format coupled with custom notations will compile into a working ``Mask`` object.
81
85
  * Otherwise `false`.
82
86
  */
83
- static bool isValid(const std::string &format, const std::vector<Notation> &customNotations) {
87
+ static bool isValid(const std::string &format, const std::vector<Notation> &customNotations)
88
+ {
84
89
  try {
85
90
  Mask(format, customNotations);
86
91
  return true;
@@ -89,14 +94,15 @@ public:
89
94
  }
90
95
  }
91
96
  };
92
- /**
97
+ /* *
93
98
  * Apply mask to the user input string.
94
99
  *
95
100
  * @param text user input string with current cursor position
96
101
  *
97
102
  * @returns Formatted text with extracted value an adjusted cursor position.
98
103
  */
99
- virtual Result apply(const CaretString &text) {
104
+ virtual Result apply(const CaretString &text)
105
+ {
100
106
  auto iterator = makeIterator(text); // Assume this function is defined
101
107
 
102
108
  int affinity = 0;
@@ -112,7 +118,6 @@ public:
112
118
  char character = iterator->next();
113
119
  while (character != '\0') {
114
120
  auto next = state->accept(character);
115
-
116
121
  if (next != nullptr) {
117
122
  if (deletionAffectsCaret) {
118
123
  auto opt = state->autocomplete();
@@ -155,9 +160,9 @@ public:
155
160
 
156
161
  while (text.caretGravity->autocomplete() && insertionAffectsCaret) {
157
162
  auto next = state->autocomplete();
158
- if (next == nullptr)
163
+ if (next == nullptr) {
159
164
  break;
160
-
165
+ }
161
166
  state = next->state;
162
167
  if (next->insert == '\0') {
163
168
  modifiedString += "";
@@ -197,34 +202,35 @@ public:
197
202
  std::string tailPlaceholder = appendPlaceholder(tailState.get(), tail); // Assume this function is defined
198
203
 
199
204
  return Result(CaretString(modifiedString, modifiedCaretPosition, text.caretGravity), extractedValue, affinity,
200
- noMandatoryCharactersLeftAfterState(state.get()), // Assume this function is defined
201
- tailPlaceholder);
205
+ noMandatoryCharactersLeftAfterState(state.get()), tailPlaceholder);
202
206
  }
203
207
 
204
-
205
208
  public:
206
- std::shared_ptr<CaretStringIterator> makeIterator(const CaretString &text) const {
209
+ std::shared_ptr<CaretStringIterator> makeIterator(const CaretString &text) const
210
+ {
207
211
  return std::make_shared<CaretStringIterator>(text);
208
212
  }
209
-
210
- /**
213
+ /* *
211
214
  * Generate placeholder.
212
215
  *
213
216
  * @return Placeholder string.
214
217
  */
215
218
  public:
216
- std::string placeholder() { return appendPlaceholder(initialState.get(), ""); }
217
- /**
219
+ std::string placeholder()
220
+ {
221
+ return appendPlaceholder(initialState.get(), "");
222
+ }
223
+ /* *
218
224
  * Minimal length of the text inside the field to fill all mandatory characters in the mask.
219
225
  *
220
226
  * @return Minimal satisfying count of characters inside the text field.
221
227
  */
222
228
  public:
223
- int acceptableTextLength() {
229
+ int acceptableTextLength()
230
+ {
224
231
  std::shared_ptr<State> state = std::move(initialState);
225
232
  ;
226
233
  int length = 0;
227
-
228
234
  while (state != nullptr && dynamic_cast<EOLState *>(state.get()) == nullptr) {
229
235
  if (dynamic_cast<FixedState *>(state.get()) != nullptr ||
230
236
  dynamic_cast<FreeState *>(state.get()) != nullptr ||
@@ -233,18 +239,16 @@ public:
233
239
  }
234
240
  state = state->child; // 移动到下一个子状态
235
241
  }
236
-
237
242
  return length;
238
243
  }
239
-
240
-
241
- /**
244
+ /* *
242
245
  * Maximal length of the text inside the field.
243
246
  *
244
247
  * @return Total available count of mandatory and optional characters inside the text field.
245
248
  */
246
249
  public:
247
- int totalTextLength() const {
250
+ int totalTextLength() const
251
+ {
248
252
  std::shared_ptr<State> state = initialState;
249
253
  ;
250
254
  int length = 0;
@@ -258,16 +262,16 @@ public:
258
262
  }
259
263
  state = state->child; // 移动到下一个子状态
260
264
  }
261
-
262
265
  return length;
263
266
  }
264
- /**
267
+ /* *
265
268
  * Minimal length of the extracted value with all mandatory characters filled.\
266
269
  *
267
270
  * @return Minimal satisfying count of characters in extracted value.
268
271
  */
269
272
  public:
270
- int acceptableValueLength() const {
273
+ int acceptableValueLength() const
274
+ {
271
275
  std::shared_ptr<State> state = initialState;
272
276
  int length = 0;
273
277
  while (state != nullptr && dynamic_cast<EOLState *>(state.get()) == nullptr) {
@@ -277,16 +281,16 @@ public:
277
281
  }
278
282
  state = state->child; // 移动到下一个子状态
279
283
  }
280
-
281
284
  return length;
282
285
  }
283
- /**
286
+ /* *
284
287
  * Maximal length of the extracted value.
285
288
  *
286
289
  * @return Total available count of mandatory and optional characters for extracted value.
287
290
  */
288
291
  public:
289
- int totalValueLength() const {
292
+ int totalValueLength() const
293
+ {
290
294
  std::shared_ptr<State> state = initialState;
291
295
  int length = 0;
292
296
  while (state != nullptr && dynamic_cast<EOLState *>(state.get()) == nullptr) {
@@ -301,7 +305,8 @@ public:
301
305
  }
302
306
 
303
307
  private:
304
- std::string appendPlaceholder(State *state, const std::string &placeholder) const {
308
+ std::string appendPlaceholder(State *state, const std::string &placeholder) const
309
+ {
305
310
  if (state == nullptr) {
306
311
  return placeholder;
307
312
  }
@@ -337,7 +342,6 @@ private:
337
342
  return placeholder; // 未知类型,返回原始 placeholder
338
343
  }
339
344
  }
340
-
341
345
  if (auto valueState = dynamic_cast<ValueState *>(state)) {
342
346
  if (!state) {
343
347
  return placeholder; // 如果 state 为 nullptr,直接返回原始 placeholder
@@ -354,19 +358,17 @@ private:
354
358
  if (customValueState->type.get()) {
355
359
  auto customStateType = dynamic_cast<ValueState::Custom *>(customValueState->type.get());
356
360
  return appendPlaceholder(state->child.get(), placeholder + customStateType->character);
357
- }else {
358
- throw FormatError("appendPlaceholder customValueState type is null"); // 未找到匹配项,抛出异常
361
+ } else {
362
+ throw FormatError("appendPlaceholder customValueState type is null");
359
363
  }
360
-
361
364
  } else {
362
- return placeholder; // 未知类型,返回原始 placeholder
365
+ return placeholder;
363
366
  }
364
367
  }
365
-
366
368
  return placeholder;
367
369
  }
368
-
369
- bool noMandatoryCharactersLeftAfterState(State *state) const {
370
+ bool noMandatoryCharactersLeftAfterState(State *state) const
371
+ {
370
372
  if (dynamic_cast<EOLState *>(state)) {
371
373
  return true;
372
374
  } else if (auto valueState = dynamic_cast<ValueState *>(state)) {
@@ -378,4 +380,5 @@ private:
378
380
  }
379
381
  }
380
382
  };
381
- } // namespace TinpMask
383
+ } // namespace TinpMask
384
+ #endif
@@ -3,7 +3,8 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
6
+ #ifndef RTLMASK_H
7
+ #define RTLMASK_H
7
8
  #pragma once
8
9
  #include "common/Mask.h"
9
10
  #include "common/model/CaretString.h"
@@ -13,11 +14,12 @@ namespace TinpMask {
13
14
  class RTLMask : public Mask {
14
15
 
15
16
  public:
16
- static std::unordered_map<std::string, std::shared_ptr<RTLMask>> cache ;
17
+ static std::unordered_map<std::string, std::shared_ptr<RTLMask>> cache ;
17
18
  RTLMask(const std::string& format, const std::vector<Notation>& customNotations)
18
19
  : Mask(reversedFormat(format), customNotations) {}
19
-
20
- static std::shared_ptr<RTLMask> getOrCreate(const std::string& format, const std::vector<Notation>& customNotations) {
20
+ static std::shared_ptr<RTLMask> getOrCreate(const std::string& format,
21
+ const std::vector<Notation>& customNotations)
22
+ {
21
23
  std::string reversed = reversedFormat(format);
22
24
  auto it = cache.find(reversed);
23
25
  if (it != cache.end()) {
@@ -29,40 +31,35 @@ public:
29
31
  cache[reversed] = newMask;
30
32
  return newMask;
31
33
  }
32
-
33
- Result apply(const CaretString& text) override {
34
+ Result apply(const CaretString& text) override
35
+ {
34
36
  return Mask::apply(text.reversed()).reversed(); // Assuming the Result class has a reversed method
35
37
  }
36
-
37
-
38
38
  private:
39
-
40
-
41
- static std::string reversedFormat(const std::string& format) {
39
+ static constexpr size_t ESCAPED_BRACKET_LENGTH = 2;
40
+ static std::string reversedFormat(const std::string& format)
41
+ {
42
42
  std::string reversed = std::string(format.rbegin(), format.rend());
43
-
44
- // Replace logic (equivalent to Kotlin's replace)
45
43
  size_t pos = 0;
46
44
  while ((pos = reversed.find("\\[", pos)) != std::string::npos) {
47
- reversed.replace(pos, 2, "\\");
48
- pos += 1; // Advance position to prevent infinite loop
45
+ reversed.replace(pos, ESCAPED_BRACKET_LENGTH, "\\");
46
+ pos += 1;
49
47
  }
50
48
  pos = 0;
51
49
  while ((pos = reversed.find("]\\", pos)) != std::string::npos) {
52
- reversed.replace(pos, 2, "\\[");
50
+ reversed.replace(pos, ESCAPED_BRACKET_LENGTH, "\\[");
53
51
  pos += 1;
54
52
  }
55
53
  pos = 0;
56
54
  while ((pos = reversed.find("\\{", pos)) != std::string::npos) {
57
- reversed.replace(pos, 2, "\\}");
55
+ reversed.replace(pos, ESCAPED_BRACKET_LENGTH, "\\}");
58
56
  pos += 1;
59
57
  }
60
58
  pos = 0;
61
59
  while ((pos = reversed.find("}\\", pos)) != std::string::npos) {
62
- reversed.replace(pos, 2, "\\{");
60
+ reversed.replace(pos, ESCAPED_BRACKET_LENGTH, "\\{");
63
61
  pos += 1;
64
62
  }
65
-
66
63
  // Map logic for brackets
67
64
  for (char& ch : reversed) {
68
65
  switch (ch) {
@@ -76,4 +73,5 @@ private:
76
73
  return reversed;
77
74
  }
78
75
  };
79
- }
76
+ }
77
+ #endif
@@ -3,7 +3,8 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
6
+ #ifndef AFFINITYCALCULATIONSTRATEGY_H
7
+ #define AFFINITYCALCULATIONSTRATEGY_H
7
8
  #pragma once
8
9
  #include <string>
9
10
  #include <stdexcept>
@@ -18,32 +19,34 @@ enum class AffinityCalculationStrategy { WHOLE_STRING, PREFIX, CAPACITY, EXTRACT
18
19
  class AffinityCalculator {
19
20
  public:
20
21
  static int calculateAffinityOfMask(AffinityCalculationStrategy strategy, Mask &mask,
21
- const CaretString &text) {
22
+ const CaretString &text)
23
+ {
22
24
  switch (strategy) {
23
- case AffinityCalculationStrategy::WHOLE_STRING:
24
- return mask.apply(text).affinity;
25
+ case AffinityCalculationStrategy::WHOLE_STRING:
26
+ return mask.apply(text).affinity;
25
27
 
26
- case AffinityCalculationStrategy::PREFIX:
27
- return prefixIntersection(mask.apply(text).formattedText.string, text.string).length();
28
+ case AffinityCalculationStrategy::PREFIX:
29
+ return prefixIntersection(mask.apply(text).formattedText.string, text.string).length();
28
30
 
29
- case AffinityCalculationStrategy::CAPACITY:
30
- return text.string.length() > mask.totalTextLength() ? std::numeric_limits<int>::min()
31
- : text.string.length() - mask.totalTextLength();
31
+ case AffinityCalculationStrategy::CAPACITY:
32
+ return text.string.length() > mask.totalTextLength() ? std::numeric_limits<int>::min()
33
+ : text.string.length() - mask.totalTextLength();
32
34
 
33
- case AffinityCalculationStrategy::EXTRACTED_VALUE_CAPACITY: {
34
- const auto &extractedValue = mask.apply(text).extractedValue;
35
- return extractedValue.length() > mask.totalValueLength()
36
- ? std::numeric_limits<int>::min()
37
- : extractedValue.length() - mask.totalValueLength();
38
- }
39
- default:
40
- throw std::invalid_argument("Unknown AffinityCalculationStrategy");
35
+ case AffinityCalculationStrategy::EXTRACTED_VALUE_CAPACITY: {
36
+ const auto &extractedValue = mask.apply(text).extractedValue;
37
+ return extractedValue.length() > mask.totalValueLength()
38
+ ? std::numeric_limits<int>::min()
39
+ : extractedValue.length() - mask.totalValueLength();
40
+ }
41
+ default:
42
+ throw std::invalid_argument("Unknown AffinityCalculationStrategy");
41
43
  }
42
44
  }
43
45
 
44
46
  private:
45
47
  // Helper function to find prefix intersection
46
- static std::string prefixIntersection(const std::string &str1, const std::string &str2) {
48
+ static std::string prefixIntersection(const std::string &str1, const std::string &str2)
49
+ {
47
50
  size_t endIndex = 0;
48
51
  while (endIndex < str1.length() && endIndex < str2.length()) {
49
52
  if (str1[endIndex] == str2[endIndex]) {
@@ -55,4 +58,5 @@ private:
55
58
  return str1.substr(0, endIndex);
56
59
  }
57
60
  };
58
- } // namespace TinpMask
61
+ } // namespace TinpMask
62
+ #endif
@@ -3,7 +3,8 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
6
+ #ifndef CARETSTRING_H
7
+ #define CARETSTRING_H
7
8
  #pragma once
8
9
  #include <string>
9
10
  #include <memory>
@@ -26,7 +27,7 @@ public:
26
27
  // 向前的光标重力
27
28
  class Forward : public CaretGravity {
28
29
  public:
29
- Forward(bool autoCompleteValue) : autocompleteValue(autoCompleteValue) {}
30
+ explicit Forward(bool autoCompleteValue) : autocompleteValue(autoCompleteValue) {}
30
31
 
31
32
  bool autocomplete() const override { return autocompleteValue; }
32
33
 
@@ -37,7 +38,7 @@ public:
37
38
  // 向后的光标重力
38
39
  class Backward : public CaretGravity {
39
40
  public:
40
- Backward(bool autoSkipValue) : autoskipValue(autoSkipValue) {}
41
+ explicit Backward(bool autoSkipValue) : autoskipValue(autoSkipValue) {}
41
42
 
42
43
  bool autoskip() const override { return autoskipValue; }
43
44
 
@@ -51,26 +52,23 @@ public:
51
52
  : string(str), caretPosition(caretPos), caretGravity(caretGrav) {}
52
53
 
53
54
  // 反转字符串并返回新的 CaretString 对象
54
- CaretString reversed() const {
55
+ CaretString reversed() const
56
+ {
55
57
  // 创建一个反转后的字符串
56
58
  std::string reversedStr(string.rbegin(), string.rend());
57
59
  // 计算新的 caretPosition
58
60
  int newCaretPos = string.length() - caretPosition;
59
61
  return CaretString(reversedStr, newCaretPos, caretGravity);
60
62
  }
61
-
62
- // 获取字符串
63
63
  const std::string &getString() const { return string; }
64
64
  // 获取光标位置
65
65
  int getCaretPosition() const { return caretPosition; }
66
66
  // 获取光标重力
67
67
  std::shared_ptr<CaretGravity> getCaretGravity() const { return caretGravity; }
68
-
69
-
70
68
  public:
71
- std::string string; // 字符串内容
72
- int caretPosition; // 光标位置
73
- std::shared_ptr<CaretGravity> caretGravity; // 光标重力
69
+ std::string string;
70
+ int caretPosition;
71
+ std::shared_ptr<CaretGravity> caretGravity;
74
72
  };
75
-
76
- } // namespace TinpMask
73
+ } // namespace TinpMask
74
+ #endif
@@ -3,7 +3,8 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
6
+ #ifndef CARETSTRINGITERATOR_H
7
+ #define CARETSTRINGITERATOR_H
7
8
  #pragma once
8
9
  #include <string>
9
10
  #include <memory>
@@ -20,11 +21,12 @@ protected:
20
21
 
21
22
  public:
22
23
  // 构造函数
23
- CaretStringIterator(const CaretString &caretStr, int index = 0) : caretString(caretStr), currentIndex(index) {}
24
+ explicit CaretStringIterator(const CaretString &caretStr, int index = 0) : caretString(caretStr),
25
+ currentIndex(index) {}
24
26
 
25
27
  // 插入是否影响光标位置
26
- virtual bool insertionAffectsCaret() {
27
-
28
+ virtual bool insertionAffectsCaret()
29
+ {
28
30
  if (dynamic_cast<CaretString::Backward *>(caretString.caretGravity.get())) {
29
31
  return currentIndex < caretString.getCaretPosition();
30
32
  } else if (dynamic_cast<CaretString::Forward *>(caretString.caretGravity.get())) {
@@ -33,26 +35,23 @@ public:
33
35
  }
34
36
  return false;
35
37
  }
36
-
37
38
  // 删除是否影响光标位置
38
39
  virtual bool deletionAffectsCaret() { return currentIndex < caretString.getCaretPosition(); }
39
-
40
40
  /**
41
41
  * 遍历 CaretString.string
42
42
  * @postcondition: 迭代器位置移到下一个符号。
43
43
  * @returns 当前符号。如果迭代器到达字符串末尾,返回 nullptr。
44
44
  */
45
- virtual char next() {
45
+ virtual char next()
46
+ {
46
47
  if (currentIndex >= caretString.getString().length()) {
47
48
  return '\0'; // 返回空指针表示到达字符串末尾
48
49
  }
49
-
50
50
  // char *charPtr = new char; // 创建一个字符指针
51
51
  auto charPtr = caretString.getString()[currentIndex]; // 获取当前字符
52
52
  currentIndex += 1; // 移动到下一个索引
53
53
  return charPtr; // 返回当前字符
54
54
  }
55
55
  };
56
-
57
-
58
56
  } // namespace TinpMask
57
+ #endif
@@ -3,7 +3,8 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
6
+ #ifndef NEXT_H
7
+ #define NEXT_H
7
8
  #pragma once
8
9
  #include <memory>
9
10
  #include "State.h"
@@ -13,13 +14,12 @@ namespace TinpMask {
13
14
  class State;
14
15
  class Next {
15
16
  public:
16
- std::shared_ptr<State> state; // 存储状态的智能指针
17
- char insert; // 可插入的字符
18
- bool pass; // 是否通过
19
- char value; // 值字符,可选
20
-
21
- // 构造函数
17
+ std::shared_ptr<State> state;
18
+ char insert;
19
+ bool pass;
20
+ char value;
22
21
  Next(std::shared_ptr<State> state, char insert, bool pass, char value)
23
22
  : state(state), insert(insert), pass(pass), value(value) {}
24
23
  };
25
- } // namespace TinpMask
24
+ }
25
+ #endif
@@ -3,28 +3,28 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
6
+ #ifndef NOTATION_H
7
+ #define NOTATION_H
7
8
  #pragma once
8
9
  #include <string>
9
10
 
10
11
  namespace TinpMask {
11
-
12
12
  class Notation {
13
13
  public:
14
14
  // 构造函数
15
15
  Notation(const char character, const std::string &characterSet, bool isOptional)
16
- : character(character), characterSet(characterSet), isOptional(isOptional) {}
17
-
16
+ : character(character), characterSet(characterSet), isOptional(isOptional)
17
+ {}
18
18
  // 成员变量
19
19
  char character; // 单个字符作为字符串
20
20
  std::string characterSet; // 字符集
21
21
  bool isOptional; // 是否可选
22
-
23
- // 其他方法和成员可以根据需要添加
24
- bool operator==(const Notation& other) const {
25
- return (this->character == other.character) &&
26
- (this->characterSet == other.characterSet) &&
27
- (this->isOptional == other.isOptional);
22
+ // 其他方法和成员可以根据需要添加
23
+ bool operator == (const Notation &other) const
24
+ {
25
+ return (this->character == other.character) && (this->characterSet == other.characterSet) &&
26
+ (this->isOptional == other.isOptional);
28
27
  }
29
28
  };
30
- } // namespace TinpMask
29
+ } // namespace TinpMask
30
+ #endif
@@ -14,8 +14,8 @@ class RTLCaretStringIterator : public CaretStringIterator {
14
14
  public:
15
15
  RTLCaretStringIterator(const CaretString& caretString)
16
16
  : CaretStringIterator(caretString) {}
17
-
18
- bool insertionAffectsCaret() {
17
+ bool insertionAffectsCaret()
18
+ {
19
19
  return currentIndex <= caretString.caretPosition;
20
20
  }
21
21
  };