@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 COMPILER_H
7
+ #define COMPILER_H
7
8
  #pragma once
8
9
  #include <string>
9
10
  #include <vector>
@@ -23,86 +24,86 @@ private:
23
24
  std::vector<Notation> customNotations;
24
25
 
25
26
  public:
26
- Compiler(const std::vector<Notation> &notations) : customNotations(notations) {}
27
+ explicit Compiler(const std::vector<Notation> &notations) : customNotations(notations) {}
27
28
 
28
- std::shared_ptr<State> compile(const std::string &formatString) {
29
+ std::shared_ptr<State> compile(const std::string &formatString)
30
+ {
29
31
  FormatSanitizer sanitizer;
30
32
  std::string sanitizedString = sanitizer.sanitize(formatString);
31
33
  return compile(sanitizedString, false, false, '\0');
32
34
  }
33
35
 
34
- std::shared_ptr<State> compile(const std::string &formatString, bool valuable, bool fixed, char lastCharacter) {
36
+ std::shared_ptr<State> compile(const std::string &formatString, bool valuable, bool fixed, char lastCharacter)
37
+ {
35
38
  if (formatString.empty()) {
36
39
  return std::make_shared<EOLState>();
37
40
  }
38
-
39
41
  char ch = formatString.front();
40
42
  switch (ch) {
41
- case '[':
42
- if (lastCharacter != '\\') {
43
- return compile(formatString.substr(1), true, false, ch);
44
- }
45
- break;
46
-
47
- case '{':
48
- if (lastCharacter != '\\') {
49
- return compile(formatString.substr(1), false, true, ch);
50
- }
51
- break;
43
+ case '[':
44
+ if (lastCharacter != '\\') {
45
+ return compile(formatString.substr(1), true, false, ch);
46
+ }
47
+ break;
52
48
 
53
- case ']':
54
- case '}':
55
- if (lastCharacter != '\\') {
56
- return compile(formatString.substr(1), false, false, ch);
57
- }
58
- break;
49
+ case '{':
50
+ if (lastCharacter != '\\') {
51
+ return compile(formatString.substr(1), false, true, ch);
52
+ }
53
+ break;
59
54
 
60
- case '\\':
61
- if (lastCharacter != '\\') {
62
- return compile(formatString.substr(1), valuable, fixed, ch);
63
- }
64
- break;
55
+ case ']':
56
+ case '}':
57
+ if (lastCharacter != '\\') {
58
+ return compile(formatString.substr(1), false, false, ch);
59
+ }
60
+ break;
65
61
 
66
- default:
67
- break;
62
+ case '\\':
63
+ if (lastCharacter != '\\') {
64
+ return compile(formatString.substr(1), valuable, fixed, ch);
65
+ }
66
+ break;
67
+ default:
68
+ break;
68
69
  }
69
70
 
70
71
  if (valuable) {
71
72
  switch (ch) {
72
- case '0':
73
- return std::make_shared<ValueState>(
74
- this->compile(formatString.substr(1), true, false, ch),
75
- // std::static_pointer_cast<ValueState::StateType>( std::make_shared<ValueState::Numeric>())
76
- std::make_shared<ValueState::Numeric>());
73
+ case '0':
74
+ return std::make_shared<ValueState>(
75
+ this->compile(formatString.substr(1), true, false, ch),
76
+ // std::static_pointer_cast<ValueState::StateType>( std::make_shared<ValueState::Numeric>())
77
+ std::make_shared<ValueState::Numeric>());
77
78
 
78
- case 'A':
79
- return std::make_shared<ValueState>(this->compile(formatString.substr(1), true, false, ch),
80
- std::make_shared<ValueState::Literal>());
79
+ case 'A':
80
+ return std::make_shared<ValueState>(this->compile(formatString.substr(1), true, false, ch),
81
+ std::make_shared<ValueState::Literal>());
81
82
 
82
- case '_':
83
- return std::make_shared<ValueState>(this->compile(formatString.substr(1), true, false, ch),
84
- std::make_shared<ValueState::AlphaNumeric>());
83
+ case '_':
84
+ return std::make_shared<ValueState>(this->compile(formatString.substr(1), true, false, ch),
85
+ std::make_shared<ValueState::AlphaNumeric>());
85
86
 
86
- case '...':
87
- return std::make_unique<ValueState>(determineInheritedType(lastCharacter));
87
+ case '...':
88
+ return std::make_unique<ValueState>(determineInheritedType(lastCharacter));
88
89
 
89
- case '9':
90
- return std::make_shared<OptionalValueState>(this->compile(formatString.substr(1), true, false, ch),
91
- std::make_shared<OptionalValueState::Numeric>()
90
+ case '9':
91
+ return std::make_shared<OptionalValueState>(this->compile(formatString.substr(1), true, false, ch),
92
+ std::make_shared<OptionalValueState::Numeric>()
92
93
 
93
- );
94
+ );
94
95
 
95
- case 'a':
96
- return std::make_shared<OptionalValueState>(this->compile(formatString.substr(1), true, false, ch),
97
- std::make_shared<OptionalValueState::Literal>());
96
+ case 'a':
97
+ return std::make_shared<OptionalValueState>(this->compile(formatString.substr(1), true, false, ch),
98
+ std::make_shared<OptionalValueState::Literal>());
98
99
 
99
- case '-':
100
- return std::make_shared<OptionalValueState>(this->compile(formatString.substr(1), true, false, ch),
101
- std::make_shared<OptionalValueState::AlphaNumeric>());
100
+ case '-':
101
+ return std::make_shared<OptionalValueState>(this->compile(formatString.substr(1), true, false, ch),
102
+ std::make_shared<OptionalValueState::AlphaNumeric>());
102
103
 
103
- default:
104
- return compileWithCustomNotations(ch, formatString);
105
- }
104
+ default:
105
+ return compileWithCustomNotations(ch, formatString);
106
+ }
106
107
  }
107
108
  if (fixed) {
108
109
  return std::make_shared<FixedState>(compile(formatString.substr(1), false, true, ch), ch);
@@ -110,18 +111,21 @@ public:
110
111
  return std::make_shared<FreeState>(compile(formatString.substr(1), false, false, ch), ch);
111
112
  }
112
113
 
113
- std::unique_ptr<State> compileWithCustomNotations(char c, const std::string &str) {
114
- DLOG(ERROR) << "====== compileWithCustomNotations customNotations size: " << customNotations.size();
114
+ std::unique_ptr<State> compileWithCustomNotations(char c, const std::string &str)
115
+ {
116
+ DLOG(ERROR) << "====== compileWithCustomNotations customNotations size: " << customNotations.size();
115
117
  for (const auto &customNotation : customNotations) {
116
118
  if (customNotation.character == c) {
117
119
  std::shared_ptr<State> compiledState = compile(str.substr(1), true, false, c);
118
120
  if (customNotation.isOptional) {
119
- DLOG(ERROR) << "====== compileWithCustomNotations customNotations isOptional :" << customNotation.isOptional;
121
+ DLOG(ERROR) << "====== compileWithCustomNotations customNotations isOptional :"
122
+ << customNotation.isOptional;
120
123
  return std::make_unique<OptionalValueState>(
121
124
  std::move(compiledState),
122
125
  std::make_shared<OptionalValueState::Custom>(c, customNotation.characterSet));
123
126
  } else {
124
- DLOG(ERROR) << "======= compileWithCustomNotations customNotations isOptional :" << customNotation.isOptional;
127
+ DLOG(ERROR) << "======= compileWithCustomNotations customNotations isOptional :"
128
+ << customNotation.isOptional;
125
129
  return std::make_unique<ValueState>(
126
130
  std::move(compiledState), std::make_shared<ValueState::Custom>(c, customNotation.characterSet));
127
131
  }
@@ -130,46 +134,45 @@ public:
130
134
  DLOG(INFO) << "compileWithCustomNotations No Match Found ";
131
135
  throw FormatError("compileWithCustomNotations No Match Found");
132
136
  }
133
- std::shared_ptr<ValueState::ValueStateType> determineInheritedType(std::optional<char> lastCharacter) {
137
+ std::shared_ptr<ValueState::ValueStateType> determineInheritedType(std::optional<char> lastCharacter)
138
+ {
134
139
  if (!lastCharacter.has_value()) {
135
140
  throw FormatError(); // 处理空字符情况,抛出异常
136
141
  }
137
142
  char character = lastCharacter.value();
138
143
  switch (character) {
139
- case '0':
140
- case '9':
141
- return std::make_shared<ValueState::Numeric>();
142
-
143
- case 'A':
144
- case 'a':
145
- return std::make_shared<ValueState::Literal>();
146
-
147
- case '_':
148
- case '-':
149
- case '...':
150
- case '[':
151
- return std::make_shared<ValueState::AlphaNumeric>();
152
-
153
- default:
154
- return determineTypeWithCustomNotations(lastCharacter);
144
+ case '0':
145
+ case '9':
146
+ return std::make_shared<ValueState::Numeric>();
147
+ case 'A':
148
+ case 'a':
149
+ return std::make_shared<ValueState::Literal>();
150
+ case '_':
151
+ case '-':
152
+ case '...':
153
+ case '[':
154
+ return std::make_shared<ValueState::AlphaNumeric>();
155
+ default:
156
+ return determineTypeWithCustomNotations(lastCharacter);
155
157
  }
156
158
  }
157
-
158
- std::shared_ptr<ValueState::ValueStateType> determineTypeWithCustomNotations(std::optional<char> lastCharacter) {
159
+ std::shared_ptr<ValueState::ValueStateType> determineTypeWithCustomNotations(std::optional<char> lastCharacter)
160
+ {
159
161
  if (!lastCharacter.has_value()) {
160
162
  throw FormatError(); // 处理空字符情况,抛出异常
161
163
  }
162
- DLOG(INFO) << "======determineTypeWithCustomNotations customNotations size: "<<customNotations.size();
164
+ DLOG(INFO) << "======determineTypeWithCustomNotations customNotations size: "<<customNotations.size();
163
165
  char character = lastCharacter.value();
164
166
  for (const auto &customNotation : customNotations) {
165
167
  if (customNotation.character == character) {
166
168
  // 返回 Custom 状态
167
169
  return std::make_shared<ValueState::Custom>(lastCharacter.value(),
168
- customNotation.characterSet); // 可以根据需要调整返回内容
170
+ customNotation.characterSet); // 可以根据需要调整返回内容
169
171
  }
170
172
  }
171
173
  DLOG(INFO) << "determineTypeWithCustomNotations No Match Found ";
172
174
  throw FormatError("determineTypeWithCustomNotations No Match Found"); // 未找到匹配项,抛出异常
173
175
  }
174
176
  };
175
- } // namespace TinpMask
177
+ } // namespace TinpMask
178
+ #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 FORMATERROR_H
7
+ #define FORMATERROR_H
7
8
  #pragma once
8
9
  // 定义 FormatError 类
9
10
  #include <string>
@@ -13,11 +14,10 @@ class FormatError : public std::exception {
13
14
  public:
14
15
  // 构造函数接受错误消息
15
16
  explicit FormatError(const std::string &message = "An error occurred") : msg(message) {}
16
-
17
17
  // 重写 what() 方法,返回错误消息
18
- const char *what() const noexcept { return msg.c_str(); }
19
-
18
+ const char *what() const noexcept override { return msg.c_str(); }
20
19
  private:
21
20
  std::string msg; // 存储错误消息
22
21
  };
23
- } // namespace TinpMask
22
+ } // namespace TinpMask
23
+ #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 FORMATSANITIZER_H
7
+ #define FORMATSANITIZER_H
7
8
  #pragma once
8
9
  #include <iostream>
9
10
  #include <vector>
@@ -17,13 +18,15 @@ namespace TinpMask {
17
18
  class Compiler;
18
19
  class FormatSanitizer {
19
20
  public:
20
- std::string sanitize(const std::string &formatString) {
21
+ std::string sanitize(const std::string &formatString)
22
+ {
21
23
  checkOpenBraces(formatString);
22
24
  std::vector<std::string> blocks = divideBlocksWithMixedCharacters(getFormatBlocks(formatString));
23
25
  return sortFormatBlocks(blocks);
24
26
  }
25
27
 
26
- std::vector<std::string> getFormatBlocks(const std::string &formatString) {
28
+ std::vector<std::string> getFormatBlocks(const std::string &formatString)
29
+ {
27
30
  std::vector<std::string> blocks;
28
31
  std::string currentBlock;
29
32
  bool escape = false;
@@ -36,36 +39,30 @@ public:
36
39
  continue;
37
40
  }
38
41
  }
39
-
40
42
  if ((ch == '[' || ch == '{') && !escape) {
41
43
  if (!currentBlock.empty()) {
42
44
  blocks.push_back(currentBlock);
43
45
  }
44
46
  currentBlock.clear();
45
47
  }
46
-
47
48
  currentBlock += ch;
48
49
 
49
50
  if ((ch == ']' || ch == '}') && !escape) {
50
51
  blocks.push_back(currentBlock);
51
52
  currentBlock.clear();
52
53
  }
53
-
54
54
  escape = false;
55
55
  }
56
56
 
57
57
  if (!currentBlock.empty()) {
58
58
  blocks.push_back(currentBlock);
59
59
  }
60
-
61
60
  return blocks;
62
61
  }
63
-
64
-
65
62
  public:
66
- std::vector<std::string> divideBlocksWithMixedCharacters(const std::vector<std::string> &blocks) {
63
+ std::vector<std::string> divideBlocksWithMixedCharacters(const std::vector<std::string> &blocks)
64
+ {
67
65
  std::vector<std::string> resultingBlocks;
68
-
69
66
  for (const auto &block : blocks) {
70
67
  if (!block.empty() && block.substr(0, 1) == "[") { // 使用 substr 来检查开头
71
68
  std::string blockBuffer;
@@ -114,7 +111,6 @@ public:
114
111
  resultingBlocks.push_back(block);
115
112
  }
116
113
  }
117
-
118
114
  return resultingBlocks;
119
115
  }
120
116
 
@@ -127,7 +123,8 @@ private:
127
123
 
128
124
  bool isSpecialCharacter(char ch) const { return ch == '-' || ch == '_'; }
129
125
 
130
- bool containsAny(const std::string &str, const std::vector<char> &characters) const {
126
+ bool containsAny(const std::string &str, const std::vector<char> &characters) const
127
+ {
131
128
  for (char c : characters) {
132
129
  if (str.find(c) != std::string::npos) {
133
130
  return true;
@@ -135,9 +132,9 @@ private:
135
132
  }
136
133
  return false;
137
134
  }
138
-
139
135
  public:
140
- std::string sortFormatBlocks(const std::vector<std::string> &blocks) {
136
+ std::string sortFormatBlocks(const std::vector<std::string> &blocks)
137
+ {
141
138
  std::vector<std::string> sortedBlocks;
142
139
 
143
140
  for (const auto &block : blocks) {
@@ -162,12 +159,11 @@ public:
162
159
 
163
160
  return join(sortedBlocks); // Ensure this is returning std::vector<std::string>
164
161
  }
165
-
166
- void checkOpenBraces(const std::string &inputString) {
162
+ void checkOpenBraces(const std::string &inputString)
163
+ {
167
164
  bool escape = false;
168
165
  bool squareBraceOpen = false;
169
166
  bool curlyBraceOpen = false;
170
-
171
167
  for (const char &ch : inputString) {
172
168
  if (ch == '\\') {
173
169
  escape = !escape;
@@ -191,7 +187,6 @@ public:
191
187
  }
192
188
  curlyBraceOpen = !escape;
193
189
  }
194
-
195
190
  if (ch == '}' && !escape) {
196
191
  curlyBraceOpen = false;
197
192
  }
@@ -200,27 +195,29 @@ public:
200
195
  }
201
196
 
202
197
  private:
203
- bool startsWith(const std::string &str, const std::string &prefix) const { return str.rfind(prefix, 0) == 0; }
204
-
205
- std::string sortString(std::string str) {
198
+ bool startsWith(const std::string &str,
199
+ const std::string &prefix) const { return str.rfind(prefix, 0) == 0; }
200
+ std::string sortString(std::string str)
201
+ {
206
202
  std::sort(str.begin(), str.end());
207
203
  return str;
208
204
  }
209
-
210
- std::string replaceChars(const std::string &str) {
205
+ std::string replaceChars(const std::string &str)
206
+ {
211
207
  std::string newStr = str;
212
208
  std::replace(newStr.begin(), newStr.end(), '_', 'A');
213
209
  std::replace(newStr.begin(), newStr.end(), '-', 'a');
214
210
  return newStr;
215
211
  }
216
-
217
- std::string replaceCharsBack(const std::string &str) {
212
+ std::string replaceCharsBack(const std::string &str)
213
+ {
218
214
  std::string newStr = str;
219
215
  std::replace(newStr.begin(), newStr.end(), 'A', '_');
220
216
  std::replace(newStr.begin(), newStr.end(), 'a', '-');
221
217
  return newStr;
222
218
  }
223
- std::string join(const std::vector<std::string> &strings) {
219
+ std::string join(const std::vector<std::string> &strings)
220
+ {
224
221
  std::string result;
225
222
  for (const auto &str : strings) {
226
223
  result += str; // 将所有块连接成一个字符串
@@ -228,4 +225,5 @@ private:
228
225
  return result;
229
226
  }
230
227
  };
231
- } // namespace TinpMask
228
+ } // namespace TinpMask
229
+ #endif