@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.
- package/LICENSE +21 -21
- package/README.OpenSource +10 -10
- package/README.md +15 -134
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/harmony/text_input_mask/BuildProfile.ets +16 -16
- package/harmony/text_input_mask/Index.ets +7 -7
- package/harmony/text_input_mask/build-profile.json5 +31 -31
- package/harmony/text_input_mask/hvigorfile.ts +6 -6
- package/harmony/text_input_mask/obfuscation-rules.txt +22 -22
- package/harmony/text_input_mask/oh-package.json5 +11 -11
- package/harmony/text_input_mask/src/main/cpp/CMakeLists.txt +9 -9
- package/harmony/text_input_mask/src/main/cpp/RNTextInputMask.cpp +421 -415
- package/harmony/text_input_mask/src/main/cpp/RNTextInputMask.h +93 -93
- package/harmony/text_input_mask/src/main/cpp/RNTextInputMaskPackage.h +31 -31
- package/harmony/text_input_mask/src/main/cpp/common/Compiler.h +174 -174
- package/harmony/text_input_mask/src/main/cpp/common/FormatError.h +22 -22
- package/harmony/text_input_mask/src/main/cpp/common/FormatSanitizer.h +230 -230
- package/harmony/text_input_mask/src/main/cpp/common/Mask.h +377 -377
- package/harmony/text_input_mask/src/main/cpp/common/RTLMask.h +78 -78
- package/harmony/text_input_mask/src/main/cpp/common/model/AffinityCalculationStrategy.h +57 -57
- package/harmony/text_input_mask/src/main/cpp/common/model/CaretString.h +75 -75
- package/harmony/text_input_mask/src/main/cpp/common/model/CaretStringIterator.h +58 -58
- package/harmony/text_input_mask/src/main/cpp/common/model/Next.h +24 -24
- package/harmony/text_input_mask/src/main/cpp/common/model/Notation.h +24 -24
- package/harmony/text_input_mask/src/main/cpp/common/model/RTLCaretStringIterator.h +22 -22
- package/harmony/text_input_mask/src/main/cpp/common/model/State.h +302 -302
- package/harmony/text_input_mask/src/main/cpp/common/model/common.h +94 -94
- package/harmony/text_input_mask/src/main/ets/RNTextInputMaskPackage.ts +28 -28
- package/harmony/text_input_mask/src/main/ets/RNTextInputMaskTurboModle.ts +32 -32
- package/harmony/text_input_mask/src/main/module.json5 +11 -11
- package/harmony/text_input_mask/src/main/resources/base/element/string.json +8 -8
- package/harmony/text_input_mask/src/main/resources/en_US/element/string.json +8 -8
- package/harmony/text_input_mask/src/main/resources/zh_CN/element/string.json +8 -8
- package/harmony/text_input_mask/ts.ts +8 -8
- package/harmony/text_input_mask.har +0 -0
- package/index.tsx +258 -258
- package/package.json +48 -50
- package/src/RNNativeTextInputMask.ts +142 -142
- package/src/index.harmony.ts +147 -147
- package/src/index.ts +36 -36
|
@@ -1,79 +1,79 @@
|
|
|
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 "common/Mask.h"
|
|
9
|
-
#include "common/model/CaretString.h"
|
|
10
|
-
#include "common/model/Notation.h"
|
|
11
|
-
#include "common/model/common.h"
|
|
12
|
-
namespace TinpMask {
|
|
13
|
-
class RTLMask : public Mask {
|
|
14
|
-
|
|
15
|
-
public:
|
|
16
|
-
static std::unordered_map<std::string, std::shared_ptr<RTLMask>> cache ;
|
|
17
|
-
RTLMask(const std::string& format, const std::vector<Notation>& customNotations)
|
|
18
|
-
: Mask(reversedFormat(format), customNotations) {}
|
|
19
|
-
|
|
20
|
-
static std::shared_ptr<RTLMask> getOrCreate(const std::string& format, const std::vector<Notation>& customNotations) {
|
|
21
|
-
std::string reversed = reversedFormat(format);
|
|
22
|
-
auto it = cache.find(reversed);
|
|
23
|
-
if (it != cache.end()) {
|
|
24
|
-
return it->second; // Return cached instance
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Create new instance and cache it
|
|
28
|
-
auto newMask = std::make_shared<RTLMask>(format, customNotations);
|
|
29
|
-
cache[reversed] = newMask;
|
|
30
|
-
return newMask;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
Result apply(const CaretString& text) override {
|
|
34
|
-
return Mask::apply(text.reversed()).reversed(); // Assuming the Result class has a reversed method
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
private:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
static std::string reversedFormat(const std::string& format) {
|
|
42
|
-
std::string reversed = std::string(format.rbegin(), format.rend());
|
|
43
|
-
|
|
44
|
-
// Replace logic (equivalent to Kotlin's replace)
|
|
45
|
-
size_t pos = 0;
|
|
46
|
-
while ((pos = reversed.find("\\[", pos)) != std::string::npos) {
|
|
47
|
-
reversed.replace(pos, 2, "\\");
|
|
48
|
-
pos += 1; // Advance position to prevent infinite loop
|
|
49
|
-
}
|
|
50
|
-
pos = 0;
|
|
51
|
-
while ((pos = reversed.find("]\\", pos)) != std::string::npos) {
|
|
52
|
-
reversed.replace(pos, 2, "\\[");
|
|
53
|
-
pos += 1;
|
|
54
|
-
}
|
|
55
|
-
pos = 0;
|
|
56
|
-
while ((pos = reversed.find("\\{", pos)) != std::string::npos) {
|
|
57
|
-
reversed.replace(pos, 2, "\\}");
|
|
58
|
-
pos += 1;
|
|
59
|
-
}
|
|
60
|
-
pos = 0;
|
|
61
|
-
while ((pos = reversed.find("}\\", pos)) != std::string::npos) {
|
|
62
|
-
reversed.replace(pos, 2, "\\{");
|
|
63
|
-
pos += 1;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Map logic for brackets
|
|
67
|
-
for (char& ch : reversed) {
|
|
68
|
-
switch (ch) {
|
|
69
|
-
case '[': ch = ']'; break;
|
|
70
|
-
case ']': ch = '['; break;
|
|
71
|
-
case '{': ch = '}'; break;
|
|
72
|
-
case '}': ch = '{'; break;
|
|
73
|
-
default: break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return reversed;
|
|
77
|
-
}
|
|
78
|
-
};
|
|
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 "common/Mask.h"
|
|
9
|
+
#include "common/model/CaretString.h"
|
|
10
|
+
#include "common/model/Notation.h"
|
|
11
|
+
#include "common/model/common.h"
|
|
12
|
+
namespace TinpMask {
|
|
13
|
+
class RTLMask : public Mask {
|
|
14
|
+
|
|
15
|
+
public:
|
|
16
|
+
static std::unordered_map<std::string, std::shared_ptr<RTLMask>> cache ;
|
|
17
|
+
RTLMask(const std::string& format, const std::vector<Notation>& customNotations)
|
|
18
|
+
: Mask(reversedFormat(format), customNotations) {}
|
|
19
|
+
|
|
20
|
+
static std::shared_ptr<RTLMask> getOrCreate(const std::string& format, const std::vector<Notation>& customNotations) {
|
|
21
|
+
std::string reversed = reversedFormat(format);
|
|
22
|
+
auto it = cache.find(reversed);
|
|
23
|
+
if (it != cache.end()) {
|
|
24
|
+
return it->second; // Return cached instance
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Create new instance and cache it
|
|
28
|
+
auto newMask = std::make_shared<RTLMask>(format, customNotations);
|
|
29
|
+
cache[reversed] = newMask;
|
|
30
|
+
return newMask;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Result apply(const CaretString& text) override {
|
|
34
|
+
return Mask::apply(text.reversed()).reversed(); // Assuming the Result class has a reversed method
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
private:
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
static std::string reversedFormat(const std::string& format) {
|
|
42
|
+
std::string reversed = std::string(format.rbegin(), format.rend());
|
|
43
|
+
|
|
44
|
+
// Replace logic (equivalent to Kotlin's replace)
|
|
45
|
+
size_t pos = 0;
|
|
46
|
+
while ((pos = reversed.find("\\[", pos)) != std::string::npos) {
|
|
47
|
+
reversed.replace(pos, 2, "\\");
|
|
48
|
+
pos += 1; // Advance position to prevent infinite loop
|
|
49
|
+
}
|
|
50
|
+
pos = 0;
|
|
51
|
+
while ((pos = reversed.find("]\\", pos)) != std::string::npos) {
|
|
52
|
+
reversed.replace(pos, 2, "\\[");
|
|
53
|
+
pos += 1;
|
|
54
|
+
}
|
|
55
|
+
pos = 0;
|
|
56
|
+
while ((pos = reversed.find("\\{", pos)) != std::string::npos) {
|
|
57
|
+
reversed.replace(pos, 2, "\\}");
|
|
58
|
+
pos += 1;
|
|
59
|
+
}
|
|
60
|
+
pos = 0;
|
|
61
|
+
while ((pos = reversed.find("}\\", pos)) != std::string::npos) {
|
|
62
|
+
reversed.replace(pos, 2, "\\{");
|
|
63
|
+
pos += 1;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Map logic for brackets
|
|
67
|
+
for (char& ch : reversed) {
|
|
68
|
+
switch (ch) {
|
|
69
|
+
case '[': ch = ']'; break;
|
|
70
|
+
case ']': ch = '['; break;
|
|
71
|
+
case '{': ch = '}'; break;
|
|
72
|
+
case '}': ch = '{'; break;
|
|
73
|
+
default: break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return reversed;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
79
|
}
|
|
@@ -1,58 +1,58 @@
|
|
|
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 <string>
|
|
9
|
-
#include <stdexcept>
|
|
10
|
-
#include <limits>
|
|
11
|
-
#include "../Mask.h" // 确保包含 Mask 头文件
|
|
12
|
-
#include "CaretString.h" // 确保包含 CaretString 头文件
|
|
13
|
-
|
|
14
|
-
namespace TinpMask {
|
|
15
|
-
|
|
16
|
-
enum class AffinityCalculationStrategy { WHOLE_STRING, PREFIX, CAPACITY, EXTRACTED_VALUE_CAPACITY };
|
|
17
|
-
|
|
18
|
-
class AffinityCalculator {
|
|
19
|
-
public:
|
|
20
|
-
static int calculateAffinityOfMask(AffinityCalculationStrategy strategy, Mask &mask,
|
|
21
|
-
const CaretString &text) {
|
|
22
|
-
switch (strategy) {
|
|
23
|
-
case AffinityCalculationStrategy::WHOLE_STRING:
|
|
24
|
-
return mask.apply(text).affinity;
|
|
25
|
-
|
|
26
|
-
case AffinityCalculationStrategy::PREFIX:
|
|
27
|
-
return prefixIntersection(mask.apply(text).formattedText.string, text.string).length();
|
|
28
|
-
|
|
29
|
-
case AffinityCalculationStrategy::CAPACITY:
|
|
30
|
-
return text.string.length() > mask.totalTextLength() ? std::numeric_limits<int>::min()
|
|
31
|
-
: text.string.length() - mask.totalTextLength();
|
|
32
|
-
|
|
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");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private:
|
|
45
|
-
// Helper function to find prefix intersection
|
|
46
|
-
static std::string prefixIntersection(const std::string &str1, const std::string &str2) {
|
|
47
|
-
size_t endIndex = 0;
|
|
48
|
-
while (endIndex < str1.length() && endIndex < str2.length()) {
|
|
49
|
-
if (str1[endIndex] == str2[endIndex]) {
|
|
50
|
-
endIndex += 1;
|
|
51
|
-
} else {
|
|
52
|
-
return str1.substr(0, endIndex);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return str1.substr(0, endIndex);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
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 <string>
|
|
9
|
+
#include <stdexcept>
|
|
10
|
+
#include <limits>
|
|
11
|
+
#include "../Mask.h" // 确保包含 Mask 头文件
|
|
12
|
+
#include "CaretString.h" // 确保包含 CaretString 头文件
|
|
13
|
+
|
|
14
|
+
namespace TinpMask {
|
|
15
|
+
|
|
16
|
+
enum class AffinityCalculationStrategy { WHOLE_STRING, PREFIX, CAPACITY, EXTRACTED_VALUE_CAPACITY };
|
|
17
|
+
|
|
18
|
+
class AffinityCalculator {
|
|
19
|
+
public:
|
|
20
|
+
static int calculateAffinityOfMask(AffinityCalculationStrategy strategy, Mask &mask,
|
|
21
|
+
const CaretString &text) {
|
|
22
|
+
switch (strategy) {
|
|
23
|
+
case AffinityCalculationStrategy::WHOLE_STRING:
|
|
24
|
+
return mask.apply(text).affinity;
|
|
25
|
+
|
|
26
|
+
case AffinityCalculationStrategy::PREFIX:
|
|
27
|
+
return prefixIntersection(mask.apply(text).formattedText.string, text.string).length();
|
|
28
|
+
|
|
29
|
+
case AffinityCalculationStrategy::CAPACITY:
|
|
30
|
+
return text.string.length() > mask.totalTextLength() ? std::numeric_limits<int>::min()
|
|
31
|
+
: text.string.length() - mask.totalTextLength();
|
|
32
|
+
|
|
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");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private:
|
|
45
|
+
// Helper function to find prefix intersection
|
|
46
|
+
static std::string prefixIntersection(const std::string &str1, const std::string &str2) {
|
|
47
|
+
size_t endIndex = 0;
|
|
48
|
+
while (endIndex < str1.length() && endIndex < str2.length()) {
|
|
49
|
+
if (str1[endIndex] == str2[endIndex]) {
|
|
50
|
+
endIndex += 1;
|
|
51
|
+
} else {
|
|
52
|
+
return str1.substr(0, endIndex);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return str1.substr(0, endIndex);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
58
|
} // namespace TinpMask
|
|
@@ -1,76 +1,76 @@
|
|
|
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 <string>
|
|
9
|
-
#include <memory>
|
|
10
|
-
|
|
11
|
-
namespace TinpMask {
|
|
12
|
-
|
|
13
|
-
class CaretString {
|
|
14
|
-
// 光标重力基类
|
|
15
|
-
public:
|
|
16
|
-
class CaretGravity {
|
|
17
|
-
public:
|
|
18
|
-
virtual ~CaretGravity() = default; // 虚析构函数
|
|
19
|
-
|
|
20
|
-
// 获取自动完成值
|
|
21
|
-
virtual bool autocomplete() const { return false; }
|
|
22
|
-
// 获取自动跳过值
|
|
23
|
-
virtual bool autoskip() const { return false; }
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// 向前的光标重力
|
|
27
|
-
class Forward : public CaretGravity {
|
|
28
|
-
public:
|
|
29
|
-
Forward(bool autoCompleteValue) : autocompleteValue(autoCompleteValue) {}
|
|
30
|
-
|
|
31
|
-
bool autocomplete() const override { return autocompleteValue; }
|
|
32
|
-
|
|
33
|
-
private:
|
|
34
|
-
bool autocompleteValue; // 自动完成值
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// 向后的光标重力
|
|
38
|
-
class Backward : public CaretGravity {
|
|
39
|
-
public:
|
|
40
|
-
Backward(bool autoSkipValue) : autoskipValue(autoSkipValue) {}
|
|
41
|
-
|
|
42
|
-
bool autoskip() const override { return autoskipValue; }
|
|
43
|
-
|
|
44
|
-
private:
|
|
45
|
-
bool autoskipValue; // 自动跳过值
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
public:
|
|
49
|
-
// 构造函数
|
|
50
|
-
CaretString(const std::string &str, int caretPos, std::shared_ptr<CaretGravity> caretGrav)
|
|
51
|
-
: string(str), caretPosition(caretPos), caretGravity(caretGrav) {}
|
|
52
|
-
|
|
53
|
-
// 反转字符串并返回新的 CaretString 对象
|
|
54
|
-
CaretString reversed() const {
|
|
55
|
-
// 创建一个反转后的字符串
|
|
56
|
-
std::string reversedStr(string.rbegin(), string.rend());
|
|
57
|
-
// 计算新的 caretPosition
|
|
58
|
-
int newCaretPos = string.length() - caretPosition;
|
|
59
|
-
return CaretString(reversedStr, newCaretPos, caretGravity);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// 获取字符串
|
|
63
|
-
const std::string &getString() const { return string; }
|
|
64
|
-
// 获取光标位置
|
|
65
|
-
int getCaretPosition() const { return caretPosition; }
|
|
66
|
-
// 获取光标重力
|
|
67
|
-
std::shared_ptr<CaretGravity> getCaretGravity() const { return caretGravity; }
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
public:
|
|
71
|
-
std::string string; // 字符串内容
|
|
72
|
-
int caretPosition; // 光标位置
|
|
73
|
-
std::shared_ptr<CaretGravity> caretGravity; // 光标重力
|
|
74
|
-
};
|
|
75
|
-
|
|
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 <string>
|
|
9
|
+
#include <memory>
|
|
10
|
+
|
|
11
|
+
namespace TinpMask {
|
|
12
|
+
|
|
13
|
+
class CaretString {
|
|
14
|
+
// 光标重力基类
|
|
15
|
+
public:
|
|
16
|
+
class CaretGravity {
|
|
17
|
+
public:
|
|
18
|
+
virtual ~CaretGravity() = default; // 虚析构函数
|
|
19
|
+
|
|
20
|
+
// 获取自动完成值
|
|
21
|
+
virtual bool autocomplete() const { return false; }
|
|
22
|
+
// 获取自动跳过值
|
|
23
|
+
virtual bool autoskip() const { return false; }
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// 向前的光标重力
|
|
27
|
+
class Forward : public CaretGravity {
|
|
28
|
+
public:
|
|
29
|
+
Forward(bool autoCompleteValue) : autocompleteValue(autoCompleteValue) {}
|
|
30
|
+
|
|
31
|
+
bool autocomplete() const override { return autocompleteValue; }
|
|
32
|
+
|
|
33
|
+
private:
|
|
34
|
+
bool autocompleteValue; // 自动完成值
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// 向后的光标重力
|
|
38
|
+
class Backward : public CaretGravity {
|
|
39
|
+
public:
|
|
40
|
+
Backward(bool autoSkipValue) : autoskipValue(autoSkipValue) {}
|
|
41
|
+
|
|
42
|
+
bool autoskip() const override { return autoskipValue; }
|
|
43
|
+
|
|
44
|
+
private:
|
|
45
|
+
bool autoskipValue; // 自动跳过值
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
// 构造函数
|
|
50
|
+
CaretString(const std::string &str, int caretPos, std::shared_ptr<CaretGravity> caretGrav)
|
|
51
|
+
: string(str), caretPosition(caretPos), caretGravity(caretGrav) {}
|
|
52
|
+
|
|
53
|
+
// 反转字符串并返回新的 CaretString 对象
|
|
54
|
+
CaretString reversed() const {
|
|
55
|
+
// 创建一个反转后的字符串
|
|
56
|
+
std::string reversedStr(string.rbegin(), string.rend());
|
|
57
|
+
// 计算新的 caretPosition
|
|
58
|
+
int newCaretPos = string.length() - caretPosition;
|
|
59
|
+
return CaretString(reversedStr, newCaretPos, caretGravity);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 获取字符串
|
|
63
|
+
const std::string &getString() const { return string; }
|
|
64
|
+
// 获取光标位置
|
|
65
|
+
int getCaretPosition() const { return caretPosition; }
|
|
66
|
+
// 获取光标重力
|
|
67
|
+
std::shared_ptr<CaretGravity> getCaretGravity() const { return caretGravity; }
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
public:
|
|
71
|
+
std::string string; // 字符串内容
|
|
72
|
+
int caretPosition; // 光标位置
|
|
73
|
+
std::shared_ptr<CaretGravity> caretGravity; // 光标重力
|
|
74
|
+
};
|
|
75
|
+
|
|
76
76
|
} // namespace TinpMask
|
|
@@ -1,58 +1,58 @@
|
|
|
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 <string>
|
|
9
|
-
#include <memory>
|
|
10
|
-
#include <string>
|
|
11
|
-
#include <memory>
|
|
12
|
-
#include "CaretString.h"
|
|
13
|
-
|
|
14
|
-
namespace TinpMask {
|
|
15
|
-
|
|
16
|
-
class CaretStringIterator {
|
|
17
|
-
protected:
|
|
18
|
-
CaretString caretString; // 关联的 CaretString 对象
|
|
19
|
-
int currentIndex; // 当前索引
|
|
20
|
-
|
|
21
|
-
public:
|
|
22
|
-
// 构造函数
|
|
23
|
-
CaretStringIterator(const CaretString &caretStr, int index = 0) : caretString(caretStr), currentIndex(index) {}
|
|
24
|
-
|
|
25
|
-
// 插入是否影响光标位置
|
|
26
|
-
virtual bool insertionAffectsCaret() {
|
|
27
|
-
|
|
28
|
-
if (dynamic_cast<CaretString::Backward *>(caretString.caretGravity.get())) {
|
|
29
|
-
return currentIndex < caretString.getCaretPosition();
|
|
30
|
-
} else if (dynamic_cast<CaretString::Forward *>(caretString.caretGravity.get())) {
|
|
31
|
-
return currentIndex <= caretString.getCaretPosition() ||
|
|
32
|
-
(currentIndex == 0 && caretString.getCaretPosition() == 0);
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 删除是否影响光标位置
|
|
38
|
-
virtual bool deletionAffectsCaret() { return currentIndex < caretString.getCaretPosition(); }
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 遍历 CaretString.string
|
|
42
|
-
* @postcondition: 迭代器位置移到下一个符号。
|
|
43
|
-
* @returns 当前符号。如果迭代器到达字符串末尾,返回 nullptr。
|
|
44
|
-
*/
|
|
45
|
-
virtual char next() {
|
|
46
|
-
if (currentIndex >= caretString.getString().length()) {
|
|
47
|
-
return '\0'; // 返回空指针表示到达字符串末尾
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// char *charPtr = new char; // 创建一个字符指针
|
|
51
|
-
auto charPtr = caretString.getString()[currentIndex]; // 获取当前字符
|
|
52
|
-
currentIndex += 1; // 移动到下一个索引
|
|
53
|
-
return charPtr; // 返回当前字符
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
} // namespace TinpMask
|
|
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 <string>
|
|
9
|
+
#include <memory>
|
|
10
|
+
#include <string>
|
|
11
|
+
#include <memory>
|
|
12
|
+
#include "CaretString.h"
|
|
13
|
+
|
|
14
|
+
namespace TinpMask {
|
|
15
|
+
|
|
16
|
+
class CaretStringIterator {
|
|
17
|
+
protected:
|
|
18
|
+
CaretString caretString; // 关联的 CaretString 对象
|
|
19
|
+
int currentIndex; // 当前索引
|
|
20
|
+
|
|
21
|
+
public:
|
|
22
|
+
// 构造函数
|
|
23
|
+
CaretStringIterator(const CaretString &caretStr, int index = 0) : caretString(caretStr), currentIndex(index) {}
|
|
24
|
+
|
|
25
|
+
// 插入是否影响光标位置
|
|
26
|
+
virtual bool insertionAffectsCaret() {
|
|
27
|
+
|
|
28
|
+
if (dynamic_cast<CaretString::Backward *>(caretString.caretGravity.get())) {
|
|
29
|
+
return currentIndex < caretString.getCaretPosition();
|
|
30
|
+
} else if (dynamic_cast<CaretString::Forward *>(caretString.caretGravity.get())) {
|
|
31
|
+
return currentIndex <= caretString.getCaretPosition() ||
|
|
32
|
+
(currentIndex == 0 && caretString.getCaretPosition() == 0);
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 删除是否影响光标位置
|
|
38
|
+
virtual bool deletionAffectsCaret() { return currentIndex < caretString.getCaretPosition(); }
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 遍历 CaretString.string
|
|
42
|
+
* @postcondition: 迭代器位置移到下一个符号。
|
|
43
|
+
* @returns 当前符号。如果迭代器到达字符串末尾,返回 nullptr。
|
|
44
|
+
*/
|
|
45
|
+
virtual char next() {
|
|
46
|
+
if (currentIndex >= caretString.getString().length()) {
|
|
47
|
+
return '\0'; // 返回空指针表示到达字符串末尾
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// char *charPtr = new char; // 创建一个字符指针
|
|
51
|
+
auto charPtr = caretString.getString()[currentIndex]; // 获取当前字符
|
|
52
|
+
currentIndex += 1; // 移动到下一个索引
|
|
53
|
+
return charPtr; // 返回当前字符
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
} // namespace TinpMask
|
|
@@ -1,25 +1,25 @@
|
|
|
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 "State.h"
|
|
10
|
-
|
|
11
|
-
namespace TinpMask {
|
|
12
|
-
|
|
13
|
-
class State;
|
|
14
|
-
class Next {
|
|
15
|
-
public:
|
|
16
|
-
std::shared_ptr<State> state; // 存储状态的智能指针
|
|
17
|
-
char insert; // 可插入的字符
|
|
18
|
-
bool pass; // 是否通过
|
|
19
|
-
char value; // 值字符,可选
|
|
20
|
-
|
|
21
|
-
// 构造函数
|
|
22
|
-
Next(std::shared_ptr<State> state, char insert, bool pass, char value)
|
|
23
|
-
: state(state), insert(insert), pass(pass), value(value) {}
|
|
24
|
-
};
|
|
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 "State.h"
|
|
10
|
+
|
|
11
|
+
namespace TinpMask {
|
|
12
|
+
|
|
13
|
+
class State;
|
|
14
|
+
class Next {
|
|
15
|
+
public:
|
|
16
|
+
std::shared_ptr<State> state; // 存储状态的智能指针
|
|
17
|
+
char insert; // 可插入的字符
|
|
18
|
+
bool pass; // 是否通过
|
|
19
|
+
char value; // 值字符,可选
|
|
20
|
+
|
|
21
|
+
// 构造函数
|
|
22
|
+
Next(std::shared_ptr<State> state, char insert, bool pass, char value)
|
|
23
|
+
: state(state), insert(insert), pass(pass), value(value) {}
|
|
24
|
+
};
|
|
25
25
|
} // namespace TinpMask
|
|
@@ -1,25 +1,25 @@
|
|
|
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 <string>
|
|
9
|
-
|
|
10
|
-
namespace TinpMask {
|
|
11
|
-
|
|
12
|
-
class Notation {
|
|
13
|
-
public:
|
|
14
|
-
// 构造函数
|
|
15
|
-
Notation(const char character, const std::string &characterSet, bool isOptional)
|
|
16
|
-
: character(character), characterSet(characterSet), isOptional(isOptional) {}
|
|
17
|
-
|
|
18
|
-
// 成员变量
|
|
19
|
-
char character; // 单个字符作为字符串
|
|
20
|
-
std::string characterSet; // 字符集
|
|
21
|
-
bool isOptional; // 是否可选
|
|
22
|
-
|
|
23
|
-
// 其他方法和成员可以根据需要添加
|
|
24
|
-
};
|
|
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 <string>
|
|
9
|
+
|
|
10
|
+
namespace TinpMask {
|
|
11
|
+
|
|
12
|
+
class Notation {
|
|
13
|
+
public:
|
|
14
|
+
// 构造函数
|
|
15
|
+
Notation(const char character, const std::string &characterSet, bool isOptional)
|
|
16
|
+
: character(character), characterSet(characterSet), isOptional(isOptional) {}
|
|
17
|
+
|
|
18
|
+
// 成员变量
|
|
19
|
+
char character; // 单个字符作为字符串
|
|
20
|
+
std::string characterSet; // 字符集
|
|
21
|
+
bool isOptional; // 是否可选
|
|
22
|
+
|
|
23
|
+
// 其他方法和成员可以根据需要添加
|
|
24
|
+
};
|
|
25
25
|
} // namespace TinpMask
|