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

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 +377 -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 +24 -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,231 +1,231 @@
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 <iostream>
9
- #include <vector>
10
- #include <string>
11
- #include <algorithm>
12
- #include "Compiler.h"
13
-
14
- namespace TinpMask {
15
-
16
-
17
- class Compiler;
18
- class FormatSanitizer {
19
- public:
20
- std::string sanitize(const std::string &formatString) {
21
- checkOpenBraces(formatString);
22
- std::vector<std::string> blocks = divideBlocksWithMixedCharacters(getFormatBlocks(formatString));
23
- return sortFormatBlocks(blocks);
24
- }
25
-
26
- std::vector<std::string> getFormatBlocks(const std::string &formatString) {
27
- std::vector<std::string> blocks;
28
- std::string currentBlock;
29
- bool escape = false;
30
-
31
- for (char ch : formatString) {
32
- if (ch == '\\') {
33
- if (!escape) {
34
- escape = true;
35
- currentBlock += ch;
36
- continue;
37
- }
38
- }
39
-
40
- if ((ch == '[' || ch == '{') && !escape) {
41
- if (!currentBlock.empty()) {
42
- blocks.push_back(currentBlock);
43
- }
44
- currentBlock.clear();
45
- }
46
-
47
- currentBlock += ch;
48
-
49
- if ((ch == ']' || ch == '}') && !escape) {
50
- blocks.push_back(currentBlock);
51
- currentBlock.clear();
52
- }
53
-
54
- escape = false;
55
- }
56
-
57
- if (!currentBlock.empty()) {
58
- blocks.push_back(currentBlock);
59
- }
60
-
61
- return blocks;
62
- }
63
-
64
-
65
- public:
66
- std::vector<std::string> divideBlocksWithMixedCharacters(const std::vector<std::string> &blocks) {
67
- std::vector<std::string> resultingBlocks;
68
-
69
- for (const auto &block : blocks) {
70
- if (!block.empty() && block.substr(0, 1) == "[") { // 使用 substr 来检查开头
71
- std::string blockBuffer;
72
- for (char blockCharacter : block) {
73
- if (blockCharacter == '[') {
74
- blockBuffer += blockCharacter;
75
- continue;
76
- }
77
-
78
- if (blockCharacter == ']' && !endsWithEscapeCharacter(blockBuffer)) {
79
- blockBuffer += blockCharacter;
80
- resultingBlocks.push_back(blockBuffer);
81
- break;
82
- }
83
-
84
- if (isDigit(blockCharacter)) {
85
- if (containsAny(blockBuffer, {'A', 'a', '-', '_'})) {
86
- blockBuffer += "]";
87
- resultingBlocks.push_back(blockBuffer);
88
- blockBuffer = "[" + std::string(1, blockCharacter);
89
- continue;
90
- }
91
- }
92
-
93
- if (isAlpha(blockCharacter)) {
94
- if (containsAny(blockBuffer, {'0', '9', '-', '_'})) {
95
- blockBuffer += "]";
96
- resultingBlocks.push_back(blockBuffer);
97
- blockBuffer = "[" + std::string(1, blockCharacter);
98
- continue;
99
- }
100
- }
101
-
102
- if (isSpecialCharacter(blockCharacter)) {
103
- if (containsAny(blockBuffer, {'0', '9', 'A', 'a'})) {
104
- blockBuffer += "]";
105
- resultingBlocks.push_back(blockBuffer);
106
- blockBuffer = "[" + std::string(1, blockCharacter);
107
- continue;
108
- }
109
- }
110
-
111
- blockBuffer += blockCharacter;
112
- }
113
- } else {
114
- resultingBlocks.push_back(block);
115
- }
116
- }
117
-
118
- return resultingBlocks;
119
- }
120
-
121
- private:
122
- bool endsWithEscapeCharacter(const std::string &str) const { return !str.empty() && str.back() == '\\'; }
123
-
124
- bool isDigit(char ch) const { return ch >= '0' && ch <= '9'; }
125
-
126
- bool isAlpha(char ch) const { return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); }
127
-
128
- bool isSpecialCharacter(char ch) const { return ch == '-' || ch == '_'; }
129
-
130
- bool containsAny(const std::string &str, const std::vector<char> &characters) const {
131
- for (char c : characters) {
132
- if (str.find(c) != std::string::npos) {
133
- return true;
134
- }
135
- }
136
- return false;
137
- }
138
-
139
- public:
140
- std::string sortFormatBlocks(const std::vector<std::string> &blocks) {
141
- std::vector<std::string> sortedBlocks;
142
-
143
- for (const auto &block : blocks) {
144
- std::string sortedBlock;
145
-
146
- if (startsWith(block, "[")) {
147
- std::string cleanedBlock = block.substr(1, block.size() - 2); // Remove the surrounding brackets
148
- if (cleanedBlock.find("0") != std::string::npos || cleanedBlock.find("9") != std::string::npos ||
149
- cleanedBlock.find("a") != std::string::npos || cleanedBlock.find("A") != std::string::npos) {
150
- sortedBlock = "[" + sortString(cleanedBlock) + "]";
151
- } else {
152
- cleanedBlock = replaceChars(cleanedBlock);
153
- sortedBlock = "[" + sortString(cleanedBlock) + "]";
154
- sortedBlock = replaceCharsBack(sortedBlock);
155
- }
156
- } else {
157
- sortedBlock = block;
158
- }
159
-
160
- sortedBlocks.push_back(sortedBlock);
161
- }
162
-
163
- return join(sortedBlocks); // Ensure this is returning std::vector<std::string>
164
- }
165
-
166
- void checkOpenBraces(const std::string &inputString) {
167
- bool escape = false;
168
- bool squareBraceOpen = false;
169
- bool curlyBraceOpen = false;
170
-
171
- for (const char &ch : inputString) {
172
- if (ch == '\\') {
173
- escape = !escape;
174
- continue;
175
- }
176
-
177
- if (ch == '[') {
178
- if (squareBraceOpen) {
179
- throw FormatError();
180
- }
181
- squareBraceOpen = !escape;
182
- }
183
-
184
- if (ch == ']' && !escape) {
185
- squareBraceOpen = false;
186
- }
187
-
188
- if (ch == '{') {
189
- if (curlyBraceOpen) {
190
- throw FormatError();
191
- }
192
- curlyBraceOpen = !escape;
193
- }
194
-
195
- if (ch == '}' && !escape) {
196
- curlyBraceOpen = false;
197
- }
198
- escape = false;
199
- }
200
- }
201
-
202
- 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) {
206
- std::sort(str.begin(), str.end());
207
- return str;
208
- }
209
-
210
- std::string replaceChars(const std::string &str) {
211
- std::string newStr = str;
212
- std::replace(newStr.begin(), newStr.end(), '_', 'A');
213
- std::replace(newStr.begin(), newStr.end(), '-', 'a');
214
- return newStr;
215
- }
216
-
217
- std::string replaceCharsBack(const std::string &str) {
218
- std::string newStr = str;
219
- std::replace(newStr.begin(), newStr.end(), 'A', '_');
220
- std::replace(newStr.begin(), newStr.end(), 'a', '-');
221
- return newStr;
222
- }
223
- std::string join(const std::vector<std::string> &strings) {
224
- std::string result;
225
- for (const auto &str : strings) {
226
- result += str; // 将所有块连接成一个字符串
227
- }
228
- return result;
229
- }
230
- };
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 <iostream>
9
+ #include <vector>
10
+ #include <string>
11
+ #include <algorithm>
12
+ #include "Compiler.h"
13
+
14
+ namespace TinpMask {
15
+
16
+
17
+ class Compiler;
18
+ class FormatSanitizer {
19
+ public:
20
+ std::string sanitize(const std::string &formatString) {
21
+ checkOpenBraces(formatString);
22
+ std::vector<std::string> blocks = divideBlocksWithMixedCharacters(getFormatBlocks(formatString));
23
+ return sortFormatBlocks(blocks);
24
+ }
25
+
26
+ std::vector<std::string> getFormatBlocks(const std::string &formatString) {
27
+ std::vector<std::string> blocks;
28
+ std::string currentBlock;
29
+ bool escape = false;
30
+
31
+ for (char ch : formatString) {
32
+ if (ch == '\\') {
33
+ if (!escape) {
34
+ escape = true;
35
+ currentBlock += ch;
36
+ continue;
37
+ }
38
+ }
39
+
40
+ if ((ch == '[' || ch == '{') && !escape) {
41
+ if (!currentBlock.empty()) {
42
+ blocks.push_back(currentBlock);
43
+ }
44
+ currentBlock.clear();
45
+ }
46
+
47
+ currentBlock += ch;
48
+
49
+ if ((ch == ']' || ch == '}') && !escape) {
50
+ blocks.push_back(currentBlock);
51
+ currentBlock.clear();
52
+ }
53
+
54
+ escape = false;
55
+ }
56
+
57
+ if (!currentBlock.empty()) {
58
+ blocks.push_back(currentBlock);
59
+ }
60
+
61
+ return blocks;
62
+ }
63
+
64
+
65
+ public:
66
+ std::vector<std::string> divideBlocksWithMixedCharacters(const std::vector<std::string> &blocks) {
67
+ std::vector<std::string> resultingBlocks;
68
+
69
+ for (const auto &block : blocks) {
70
+ if (!block.empty() && block.substr(0, 1) == "[") { // 使用 substr 来检查开头
71
+ std::string blockBuffer;
72
+ for (char blockCharacter : block) {
73
+ if (blockCharacter == '[') {
74
+ blockBuffer += blockCharacter;
75
+ continue;
76
+ }
77
+
78
+ if (blockCharacter == ']' && !endsWithEscapeCharacter(blockBuffer)) {
79
+ blockBuffer += blockCharacter;
80
+ resultingBlocks.push_back(blockBuffer);
81
+ break;
82
+ }
83
+
84
+ if (isDigit(blockCharacter)) {
85
+ if (containsAny(blockBuffer, {'A', 'a', '-', '_'})) {
86
+ blockBuffer += "]";
87
+ resultingBlocks.push_back(blockBuffer);
88
+ blockBuffer = "[" + std::string(1, blockCharacter);
89
+ continue;
90
+ }
91
+ }
92
+
93
+ if (isAlpha(blockCharacter)) {
94
+ if (containsAny(blockBuffer, {'0', '9', '-', '_'})) {
95
+ blockBuffer += "]";
96
+ resultingBlocks.push_back(blockBuffer);
97
+ blockBuffer = "[" + std::string(1, blockCharacter);
98
+ continue;
99
+ }
100
+ }
101
+
102
+ if (isSpecialCharacter(blockCharacter)) {
103
+ if (containsAny(blockBuffer, {'0', '9', 'A', 'a'})) {
104
+ blockBuffer += "]";
105
+ resultingBlocks.push_back(blockBuffer);
106
+ blockBuffer = "[" + std::string(1, blockCharacter);
107
+ continue;
108
+ }
109
+ }
110
+
111
+ blockBuffer += blockCharacter;
112
+ }
113
+ } else {
114
+ resultingBlocks.push_back(block);
115
+ }
116
+ }
117
+
118
+ return resultingBlocks;
119
+ }
120
+
121
+ private:
122
+ bool endsWithEscapeCharacter(const std::string &str) const { return !str.empty() && str.back() == '\\'; }
123
+
124
+ bool isDigit(char ch) const { return ch >= '0' && ch <= '9'; }
125
+
126
+ bool isAlpha(char ch) const { return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); }
127
+
128
+ bool isSpecialCharacter(char ch) const { return ch == '-' || ch == '_'; }
129
+
130
+ bool containsAny(const std::string &str, const std::vector<char> &characters) const {
131
+ for (char c : characters) {
132
+ if (str.find(c) != std::string::npos) {
133
+ return true;
134
+ }
135
+ }
136
+ return false;
137
+ }
138
+
139
+ public:
140
+ std::string sortFormatBlocks(const std::vector<std::string> &blocks) {
141
+ std::vector<std::string> sortedBlocks;
142
+
143
+ for (const auto &block : blocks) {
144
+ std::string sortedBlock;
145
+
146
+ if (startsWith(block, "[")) {
147
+ std::string cleanedBlock = block.substr(1, block.size() - 2); // Remove the surrounding brackets
148
+ if (cleanedBlock.find("0") != std::string::npos || cleanedBlock.find("9") != std::string::npos ||
149
+ cleanedBlock.find("a") != std::string::npos || cleanedBlock.find("A") != std::string::npos) {
150
+ sortedBlock = "[" + sortString(cleanedBlock) + "]";
151
+ } else {
152
+ cleanedBlock = replaceChars(cleanedBlock);
153
+ sortedBlock = "[" + sortString(cleanedBlock) + "]";
154
+ sortedBlock = replaceCharsBack(sortedBlock);
155
+ }
156
+ } else {
157
+ sortedBlock = block;
158
+ }
159
+
160
+ sortedBlocks.push_back(sortedBlock);
161
+ }
162
+
163
+ return join(sortedBlocks); // Ensure this is returning std::vector<std::string>
164
+ }
165
+
166
+ void checkOpenBraces(const std::string &inputString) {
167
+ bool escape = false;
168
+ bool squareBraceOpen = false;
169
+ bool curlyBraceOpen = false;
170
+
171
+ for (const char &ch : inputString) {
172
+ if (ch == '\\') {
173
+ escape = !escape;
174
+ continue;
175
+ }
176
+
177
+ if (ch == '[') {
178
+ if (squareBraceOpen) {
179
+ throw FormatError();
180
+ }
181
+ squareBraceOpen = !escape;
182
+ }
183
+
184
+ if (ch == ']' && !escape) {
185
+ squareBraceOpen = false;
186
+ }
187
+
188
+ if (ch == '{') {
189
+ if (curlyBraceOpen) {
190
+ throw FormatError();
191
+ }
192
+ curlyBraceOpen = !escape;
193
+ }
194
+
195
+ if (ch == '}' && !escape) {
196
+ curlyBraceOpen = false;
197
+ }
198
+ escape = false;
199
+ }
200
+ }
201
+
202
+ 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) {
206
+ std::sort(str.begin(), str.end());
207
+ return str;
208
+ }
209
+
210
+ std::string replaceChars(const std::string &str) {
211
+ std::string newStr = str;
212
+ std::replace(newStr.begin(), newStr.end(), '_', 'A');
213
+ std::replace(newStr.begin(), newStr.end(), '-', 'a');
214
+ return newStr;
215
+ }
216
+
217
+ std::string replaceCharsBack(const std::string &str) {
218
+ std::string newStr = str;
219
+ std::replace(newStr.begin(), newStr.end(), 'A', '_');
220
+ std::replace(newStr.begin(), newStr.end(), 'a', '-');
221
+ return newStr;
222
+ }
223
+ std::string join(const std::vector<std::string> &strings) {
224
+ std::string result;
225
+ for (const auto &str : strings) {
226
+ result += str; // 将所有块连接成一个字符串
227
+ }
228
+ return result;
229
+ }
230
+ };
231
231
  } // namespace TinpMask