react-native-nitro-input 0.1.0
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/CHANGELOG.md +63 -0
- package/LICENSE +21 -0
- package/NitroInput.podspec +54 -0
- package/README.md +524 -0
- package/android/CMakeLists.txt +52 -0
- package/android/build.gradle +158 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +4 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/JAmountFormatter.cpp +70 -0
- package/android/src/main/cpp/JAmountFormatter.hpp +45 -0
- package/android/src/main/cpp/JMaskEngine.cpp +81 -0
- package/android/src/main/cpp/JMaskEngine.hpp +52 -0
- package/android/src/main/cpp/JMorphEngine.cpp +132 -0
- package/android/src/main/cpp/JMorphEngine.hpp +54 -0
- package/android/src/main/cpp/JNitroInputWorklets.cpp +83 -0
- package/android/src/main/cpp/JNitroInputWorklets.hpp +40 -0
- package/android/src/main/cpp/JOutlineGeometry.cpp +58 -0
- package/android/src/main/cpp/JOutlineGeometry.hpp +55 -0
- package/android/src/main/cpp/cpp-adapter.cpp +19 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/AmountFormatter.kt +35 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +730 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/MaskEngine.kt +50 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/MorphEngine.kt +47 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputPackage.kt +24 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +2176 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputWorklets.kt +34 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/OutlineGeometry.kt +71 -0
- package/cpp/AmountFormatter.cpp +346 -0
- package/cpp/AmountFormatter.hpp +88 -0
- package/cpp/MaskEngine.cpp +596 -0
- package/cpp/MaskEngine.hpp +136 -0
- package/cpp/MorphEngine.cpp +904 -0
- package/cpp/MorphEngine.hpp +213 -0
- package/cpp/OutlineGeometry.cpp +159 -0
- package/cpp/OutlineGeometry.hpp +107 -0
- package/cpp/worklets/HybridNitroInputWorklets.cpp +30 -0
- package/cpp/worklets/HybridNitroInputWorklets.hpp +30 -0
- package/cpp/worklets/NitroInputWorkletsBridge.cpp +203 -0
- package/cpp/worklets/NitroInputWorkletsBridge.hpp +52 -0
- package/cpp/worklets/NitroInputWorkletsBridgeJSI.hpp +23 -0
- package/ios/HybridMorphInputView.swift +710 -0
- package/ios/NitroInputCommands.mm +66 -0
- package/ios/NitroInputView.swift +2600 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +101 -0
- package/lib/commonjs/src/MorphInput.js +42 -0
- package/lib/commonjs/src/NitroInput.js +623 -0
- package/lib/commonjs/src/index.js +12 -0
- package/lib/commonjs/src/specs/NitroInput.nitro.js +2 -0
- package/lib/commonjs/src/specs/NitroInputWorklets.nitro.js +2 -0
- package/lib/commonjs/src/useNitroInputState.js +58 -0
- package/lib/commonjs/src/worklets.js +226 -0
- package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +101 -0
- package/lib/module/package.json +1 -0
- package/lib/module/src/MorphInput.js +6 -0
- package/lib/module/src/NitroInput.js +584 -0
- package/lib/module/src/index.js +4 -0
- package/lib/module/src/specs/NitroInput.nitro.js +1 -0
- package/lib/module/src/specs/NitroInputWorklets.nitro.js +1 -0
- package/lib/module/src/useNitroInputState.js +55 -0
- package/lib/module/src/worklets.js +214 -0
- package/lib/typescript/src/MorphInput.d.ts +18 -0
- package/lib/typescript/src/NitroInput.d.ts +411 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/specs/NitroInput.nitro.d.ts +390 -0
- package/lib/typescript/src/specs/NitroInputWorklets.nitro.d.ts +15 -0
- package/lib/typescript/src/useNitroInputState.d.ts +55 -0
- package/lib/typescript/src/worklets.d.ts +117 -0
- package/nitro.json +37 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroInput+autolinking.cmake +84 -0
- package/nitrogen/generated/android/NitroInput+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroInputOnLoad.cpp +78 -0
- package/nitrogen/generated/android/NitroInputOnLoad.hpp +34 -0
- package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_double.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string.hpp +76 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string_double.hpp +76 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string_std__string_std__string_bool.hpp +76 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +1073 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +254 -0
- package/nitrogen/generated/android/c++/JNitroInputAffixAlign.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroInputAutoCapitalize.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroInputEasing.hpp +67 -0
- package/nitrogen/generated/android/c++/JNitroInputEffect.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroInputKeyboardAppearance.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroInputKeyboardType.hpp +79 -0
- package/nitrogen/generated/android/c++/JNitroInputLabelBehavior.hpp +58 -0
- package/nitrogen/generated/android/c++/JNitroInputMode.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroInputNotation.hpp +65 -0
- package/nitrogen/generated/android/c++/JNitroInputReturnKeyType.hpp +70 -0
- package/nitrogen/generated/android/c++/JNitroInputSignPlacement.hpp +58 -0
- package/nitrogen/generated/android/c++/JNitroInputSubmitBehavior.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroInputTextAlign.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroInputTextAlignVertical.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroInputVariant.hpp +61 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +529 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.hpp +54 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_bool.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_double.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_double_double.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_std__string.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_std__string_double.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_std__string_std__string_std__string_bool.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +711 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputAffixAlign.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputAutoCapitalize.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputEasing.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputEffect.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputKeyboardAppearance.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputKeyboardType.kt +30 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputLabelBehavior.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputMode.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputNotation.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputReturnKeyType.kt +27 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSignPlacement.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSubmitBehavior.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputTextAlign.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputTextAlignVertical.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputVariant.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroInputViewManager.kt +96 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroInputViewStateUpdater.kt +23 -0
- package/nitrogen/generated/ios/NitroInput+autolinking.rb +62 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +81 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +348 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +92 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.mm +43 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +769 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +690 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_double_double.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string_double.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string_std__string_std__string_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +154 -0
- package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +1454 -0
- package/nitrogen/generated/ios/swift/NitroInputAffixAlign.swift +48 -0
- package/nitrogen/generated/ios/swift/NitroInputAutoCapitalize.swift +48 -0
- package/nitrogen/generated/ios/swift/NitroInputEasing.swift +52 -0
- package/nitrogen/generated/ios/swift/NitroInputEffect.swift +44 -0
- package/nitrogen/generated/ios/swift/NitroInputKeyboardAppearance.swift +44 -0
- package/nitrogen/generated/ios/swift/NitroInputKeyboardType.swift +68 -0
- package/nitrogen/generated/ios/swift/NitroInputLabelBehavior.swift +40 -0
- package/nitrogen/generated/ios/swift/NitroInputMode.swift +44 -0
- package/nitrogen/generated/ios/swift/NitroInputNotation.swift +39 -0
- package/nitrogen/generated/ios/swift/NitroInputReturnKeyType.swift +56 -0
- package/nitrogen/generated/ios/swift/NitroInputSignPlacement.swift +40 -0
- package/nitrogen/generated/ios/swift/NitroInputSubmitBehavior.swift +44 -0
- package/nitrogen/generated/ios/swift/NitroInputTextAlign.swift +48 -0
- package/nitrogen/generated/ios/swift/NitroInputTextAlignVertical.swift +48 -0
- package/nitrogen/generated/ios/swift/NitroInputVariant.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +213 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +300 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputWorkletsSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputWorkletsSpec.hpp +62 -0
- package/nitrogen/generated/shared/c++/NitroInputAffixAlign.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroInputAutoCapitalize.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroInputEasing.hpp +88 -0
- package/nitrogen/generated/shared/c++/NitroInputEffect.hpp +80 -0
- package/nitrogen/generated/shared/c++/NitroInputKeyboardAppearance.hpp +80 -0
- package/nitrogen/generated/shared/c++/NitroInputKeyboardType.hpp +104 -0
- package/nitrogen/generated/shared/c++/NitroInputLabelBehavior.hpp +76 -0
- package/nitrogen/generated/shared/c++/NitroInputMode.hpp +80 -0
- package/nitrogen/generated/shared/c++/NitroInputNotation.hpp +91 -0
- package/nitrogen/generated/shared/c++/NitroInputReturnKeyType.hpp +92 -0
- package/nitrogen/generated/shared/c++/NitroInputSignPlacement.hpp +76 -0
- package/nitrogen/generated/shared/c++/NitroInputSubmitBehavior.hpp +80 -0
- package/nitrogen/generated/shared/c++/NitroInputTextAlign.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroInputTextAlignVertical.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroInputVariant.hpp +80 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +216 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +374 -0
- package/nitrogen/generated/shared/json/NitroInputViewConfig.json +101 -0
- package/package.json +141 -0
- package/react-native.config.js +16 -0
- package/src/MorphInput.tsx +30 -0
- package/src/NitroInput.tsx +1364 -0
- package/src/index.ts +55 -0
- package/src/specs/NitroInput.nitro.ts +436 -0
- package/src/specs/NitroInputWorklets.nitro.ts +13 -0
- package/src/useNitroInputState.ts +101 -0
- package/src/worklets.ts +300 -0
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MaskEngine.cpp
|
|
3
|
+
// NitroInput
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
#include "MaskEngine.hpp"
|
|
7
|
+
|
|
8
|
+
#include "AmountFormatter.hpp"
|
|
9
|
+
|
|
10
|
+
#include <algorithm>
|
|
11
|
+
#include <optional>
|
|
12
|
+
|
|
13
|
+
namespace margelo::nitro::nitroinput {
|
|
14
|
+
|
|
15
|
+
namespace {
|
|
16
|
+
|
|
17
|
+
using CodePoints = std::vector<uint32_t>;
|
|
18
|
+
|
|
19
|
+
bool isDigit(uint32_t c) {
|
|
20
|
+
return c >= '0' && c <= '9';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
bool isLetter(uint32_t c) {
|
|
24
|
+
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
constexpr uint32_t kEllipsis = 0x2026; // …
|
|
28
|
+
constexpr uint32_t kEscape = '\\';
|
|
29
|
+
|
|
30
|
+
/// The slot characters with a built-in meaning. A custom notation may not
|
|
31
|
+
/// shadow one of these.
|
|
32
|
+
bool isReservedSlot(uint32_t c) {
|
|
33
|
+
return c == '0' || c == '9' || c == 'A' || c == 'a' || c == '_' || c == '-' || c == kEllipsis;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
bool isOptionalSlot(uint32_t c) {
|
|
37
|
+
return c == '9' || c == 'a' || c == '-';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// Which of the three built-in groups a slot character belongs to. Mixing
|
|
41
|
+
/// groups inside one `[]` block is what the sanitizer splits apart.
|
|
42
|
+
int slotGroup(uint32_t c) {
|
|
43
|
+
if (c == '0' || c == '9') return 0; // numeric
|
|
44
|
+
if (c == 'A' || c == 'a') return 1; // literal
|
|
45
|
+
if (c == '_' || c == '-') return 2; // alphanumeric
|
|
46
|
+
return -1;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
} // namespace
|
|
50
|
+
|
|
51
|
+
// MARK: - State
|
|
52
|
+
|
|
53
|
+
struct MaskEngine::State {
|
|
54
|
+
Slot slot = Slot::EndOfLine;
|
|
55
|
+
const State* child = nullptr;
|
|
56
|
+
/// Free and Fixed: the character this state stands for.
|
|
57
|
+
uint32_t ownCharacter = 0;
|
|
58
|
+
/// Value and OptionalValue.
|
|
59
|
+
CharClass cls = CharClass::AlphaNumeric;
|
|
60
|
+
const Notation* notation = nullptr;
|
|
61
|
+
bool elliptical = false;
|
|
62
|
+
|
|
63
|
+
const State* nextState() const {
|
|
64
|
+
// An ellipsis never advances: it accepts its type forever.
|
|
65
|
+
return elliptical ? this : child;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
bool accepts(uint32_t c) const {
|
|
69
|
+
switch (cls) {
|
|
70
|
+
case CharClass::Numeric:
|
|
71
|
+
return isDigit(c);
|
|
72
|
+
case CharClass::Literal:
|
|
73
|
+
return isLetter(c);
|
|
74
|
+
case CharClass::AlphaNumeric:
|
|
75
|
+
return isDigit(c) || isLetter(c);
|
|
76
|
+
case CharClass::Custom:
|
|
77
|
+
if (notation == nullptr) return false;
|
|
78
|
+
return std::find(notation->characterSet.begin(), notation->characterSet.end(), c) !=
|
|
79
|
+
notation->characterSet.end();
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/// The character shown for this slot when nothing has been typed into it.
|
|
85
|
+
uint32_t placeholderCharacter() const {
|
|
86
|
+
switch (cls) {
|
|
87
|
+
case CharClass::Numeric:
|
|
88
|
+
return '0';
|
|
89
|
+
case CharClass::Literal:
|
|
90
|
+
return 'a';
|
|
91
|
+
case CharClass::AlphaNumeric:
|
|
92
|
+
return '-';
|
|
93
|
+
case CharClass::Custom:
|
|
94
|
+
return notation != nullptr ? notation->character : '-';
|
|
95
|
+
}
|
|
96
|
+
return '-';
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/// One transition. `pass` means the input character was consumed.
|
|
101
|
+
struct MaskEngine::Step {
|
|
102
|
+
const State* state = nullptr;
|
|
103
|
+
std::optional<uint32_t> insert;
|
|
104
|
+
std::optional<uint32_t> value;
|
|
105
|
+
bool pass = false;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
namespace {
|
|
109
|
+
|
|
110
|
+
using State = MaskEngine::State;
|
|
111
|
+
using Step = MaskEngine::Step;
|
|
112
|
+
|
|
113
|
+
/// The transition for `c`, or nothing when the state refuses it outright
|
|
114
|
+
/// (only a mandatory Value does that - everything else steps over itself).
|
|
115
|
+
std::optional<Step> accept(const State* state, uint32_t c) {
|
|
116
|
+
switch (state->slot) {
|
|
117
|
+
case MaskEngine::Slot::Free:
|
|
118
|
+
if (state->ownCharacter == c) {
|
|
119
|
+
return Step{state->nextState(), c, std::nullopt, true};
|
|
120
|
+
}
|
|
121
|
+
return Step{state->nextState(), state->ownCharacter, std::nullopt, false};
|
|
122
|
+
case MaskEngine::Slot::Fixed:
|
|
123
|
+
if (state->ownCharacter == c) {
|
|
124
|
+
return Step{state->nextState(), c, c, true};
|
|
125
|
+
}
|
|
126
|
+
return Step{state->nextState(), state->ownCharacter, state->ownCharacter, false};
|
|
127
|
+
case MaskEngine::Slot::Value:
|
|
128
|
+
if (state->accepts(c)) {
|
|
129
|
+
return Step{state->nextState(), c, c, true};
|
|
130
|
+
}
|
|
131
|
+
return std::nullopt;
|
|
132
|
+
case MaskEngine::Slot::OptionalValue:
|
|
133
|
+
if (state->accepts(c)) {
|
|
134
|
+
return Step{state->nextState(), c, c, true};
|
|
135
|
+
}
|
|
136
|
+
return Step{state->nextState(), std::nullopt, std::nullopt, false};
|
|
137
|
+
case MaskEngine::Slot::EndOfLine:
|
|
138
|
+
return std::nullopt;
|
|
139
|
+
}
|
|
140
|
+
return std::nullopt;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/// What this state would emit on its own, with no input left.
|
|
144
|
+
std::optional<Step> autocompleteOf(const State* state) {
|
|
145
|
+
switch (state->slot) {
|
|
146
|
+
case MaskEngine::Slot::Free:
|
|
147
|
+
return Step{state->nextState(), state->ownCharacter, std::nullopt, false};
|
|
148
|
+
case MaskEngine::Slot::Fixed:
|
|
149
|
+
return Step{state->nextState(), state->ownCharacter, state->ownCharacter, false};
|
|
150
|
+
default:
|
|
151
|
+
return std::nullopt;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
bool noMandatoryLeft(const State* state) {
|
|
156
|
+
while (state != nullptr) {
|
|
157
|
+
switch (state->slot) {
|
|
158
|
+
case MaskEngine::Slot::EndOfLine:
|
|
159
|
+
return true;
|
|
160
|
+
case MaskEngine::Slot::Value:
|
|
161
|
+
// An ellipsis is satisfied by whatever it already has.
|
|
162
|
+
return state->elliptical;
|
|
163
|
+
case MaskEngine::Slot::Fixed:
|
|
164
|
+
return false;
|
|
165
|
+
default:
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
const State* next = state->nextState();
|
|
169
|
+
if (next == state) return true; // elliptical self-loop
|
|
170
|
+
state = next;
|
|
171
|
+
}
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// MARK: - Format sanitizer
|
|
176
|
+
|
|
177
|
+
/// Splits `format` into blocks: each `[...]`, each `{...}`, and each run of
|
|
178
|
+
/// free characters. Escapes are carried through untouched.
|
|
179
|
+
bool splitBlocks(const CodePoints& format, std::vector<CodePoints>* blocks) {
|
|
180
|
+
CodePoints current;
|
|
181
|
+
bool escape = false;
|
|
182
|
+
bool inSquare = false;
|
|
183
|
+
bool inCurly = false;
|
|
184
|
+
for (uint32_t c : format) {
|
|
185
|
+
if (escape) {
|
|
186
|
+
current.push_back(c);
|
|
187
|
+
escape = false;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (c == kEscape) {
|
|
191
|
+
current.push_back(c);
|
|
192
|
+
escape = true;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (c == '[' || c == '{') {
|
|
196
|
+
if (inSquare || inCurly) return false; // no nesting
|
|
197
|
+
if (!current.empty()) blocks->push_back(current);
|
|
198
|
+
current.clear();
|
|
199
|
+
current.push_back(c);
|
|
200
|
+
(c == '[' ? inSquare : inCurly) = true;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (c == ']' || c == '}') {
|
|
204
|
+
const bool matching = (c == ']' && inSquare) || (c == '}' && inCurly);
|
|
205
|
+
if (!matching) return false; // a close with no open
|
|
206
|
+
current.push_back(c);
|
|
207
|
+
blocks->push_back(current);
|
|
208
|
+
current.clear();
|
|
209
|
+
inSquare = false;
|
|
210
|
+
inCurly = false;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
current.push_back(c);
|
|
214
|
+
}
|
|
215
|
+
if (escape || inSquare || inCurly) return false;
|
|
216
|
+
if (!current.empty()) blocks->push_back(current);
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/// A `[]` block may only hold one group of slot characters, and within it the
|
|
221
|
+
/// mandatory ones come first: `[9900]` means `[0099]`, and `[00AA]` is really
|
|
222
|
+
/// `[00]` followed by `[AA]`. Custom notations are left where they are.
|
|
223
|
+
void normalizeBlock(const CodePoints& block, std::vector<CodePoints>* out) {
|
|
224
|
+
if (block.size() < 2 || block.front() != '[') {
|
|
225
|
+
out->push_back(block);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const CodePoints body(block.begin() + 1, block.end() - 1);
|
|
229
|
+
|
|
230
|
+
// Split on a change of built-in group. Custom notations (group -1) stay with
|
|
231
|
+
// whatever run they are in, since we cannot reorder what we cannot classify.
|
|
232
|
+
std::vector<CodePoints> runs;
|
|
233
|
+
CodePoints run;
|
|
234
|
+
int runGroup = -2;
|
|
235
|
+
for (uint32_t c : body) {
|
|
236
|
+
const int group = slotGroup(c);
|
|
237
|
+
if (group >= 0 && runGroup >= 0 && group != runGroup) {
|
|
238
|
+
runs.push_back(run);
|
|
239
|
+
run.clear();
|
|
240
|
+
}
|
|
241
|
+
if (group >= 0) runGroup = group;
|
|
242
|
+
run.push_back(c);
|
|
243
|
+
}
|
|
244
|
+
if (!run.empty()) runs.push_back(run);
|
|
245
|
+
|
|
246
|
+
for (CodePoints& piece : runs) {
|
|
247
|
+
// Mandatory before optional, order otherwise preserved.
|
|
248
|
+
std::stable_partition(piece.begin(), piece.end(), [](uint32_t c) { return !isOptionalSlot(c); });
|
|
249
|
+
CodePoints wrapped;
|
|
250
|
+
wrapped.reserve(piece.size() + 2);
|
|
251
|
+
wrapped.push_back('[');
|
|
252
|
+
wrapped.insert(wrapped.end(), piece.begin(), piece.end());
|
|
253
|
+
wrapped.push_back(']');
|
|
254
|
+
out->push_back(wrapped);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
bool sanitize(const CodePoints& format, CodePoints* out) {
|
|
259
|
+
std::vector<CodePoints> blocks;
|
|
260
|
+
if (!splitBlocks(format, &blocks)) return false;
|
|
261
|
+
std::vector<CodePoints> normalized;
|
|
262
|
+
for (const CodePoints& block : blocks) {
|
|
263
|
+
normalizeBlock(block, &normalized);
|
|
264
|
+
}
|
|
265
|
+
for (const CodePoints& block : normalized) {
|
|
266
|
+
out->insert(out->end(), block.begin(), block.end());
|
|
267
|
+
}
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
} // namespace
|
|
272
|
+
|
|
273
|
+
// MARK: - Lifetime
|
|
274
|
+
|
|
275
|
+
MaskEngine::MaskEngine() = default;
|
|
276
|
+
MaskEngine::~MaskEngine() = default;
|
|
277
|
+
MaskEngine::MaskEngine(const MaskEngine&) = default;
|
|
278
|
+
MaskEngine& MaskEngine::operator=(const MaskEngine&) = default;
|
|
279
|
+
MaskEngine::MaskEngine(MaskEngine&&) noexcept = default;
|
|
280
|
+
MaskEngine& MaskEngine::operator=(MaskEngine&&) noexcept = default;
|
|
281
|
+
|
|
282
|
+
bool MaskEngine::isActive() const {
|
|
283
|
+
return compiled_ != nullptr && compiled_->initial != nullptr;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
namespace {
|
|
287
|
+
const MaskEngine::State* makeState(std::vector<std::unique_ptr<MaskEngine::State>>& arena, MaskEngine::State state) {
|
|
288
|
+
arena.push_back(std::make_unique<MaskEngine::State>(state));
|
|
289
|
+
return arena.back().get();
|
|
290
|
+
}
|
|
291
|
+
} // namespace
|
|
292
|
+
|
|
293
|
+
// MARK: - Compiler
|
|
294
|
+
|
|
295
|
+
bool MaskEngine::classOf(const Compiled& compiled, uint32_t formatCharacter, CharClass* cls,
|
|
296
|
+
const Notation** notation) {
|
|
297
|
+
switch (formatCharacter) {
|
|
298
|
+
case '0':
|
|
299
|
+
case '9':
|
|
300
|
+
*cls = CharClass::Numeric;
|
|
301
|
+
*notation = nullptr;
|
|
302
|
+
return true;
|
|
303
|
+
case 'A':
|
|
304
|
+
case 'a':
|
|
305
|
+
*cls = CharClass::Literal;
|
|
306
|
+
*notation = nullptr;
|
|
307
|
+
return true;
|
|
308
|
+
case '_':
|
|
309
|
+
case '-':
|
|
310
|
+
*cls = CharClass::AlphaNumeric;
|
|
311
|
+
*notation = nullptr;
|
|
312
|
+
return true;
|
|
313
|
+
default:
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
for (const Notation& candidate : compiled.notations) {
|
|
317
|
+
if (candidate.character == formatCharacter) {
|
|
318
|
+
*cls = CharClass::Custom;
|
|
319
|
+
*notation = &candidate;
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
bool MaskEngine::inheritedClass(const Compiled& compiled, uint32_t lastCharacter, CharClass* cls,
|
|
327
|
+
const Notation** notation) {
|
|
328
|
+
// `[…]` with nothing before it, or straight after `[`, is alphanumeric.
|
|
329
|
+
if (lastCharacter == 0 || lastCharacter == '[' || lastCharacter == kEllipsis) {
|
|
330
|
+
*cls = CharClass::AlphaNumeric;
|
|
331
|
+
*notation = nullptr;
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
return classOf(compiled, lastCharacter, cls, notation);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const MaskEngine::State* MaskEngine::compile(Compiled& out, const CodePoints& format, size_t index,
|
|
338
|
+
bool valuable, bool fixed, uint32_t lastCharacter, bool* ok) {
|
|
339
|
+
if (!*ok) return nullptr;
|
|
340
|
+
if (index >= format.size()) {
|
|
341
|
+
return makeState(out.arena, State{Slot::EndOfLine, nullptr, 0, CharClass::AlphaNumeric, nullptr, false});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const uint32_t c = format[index];
|
|
345
|
+
|
|
346
|
+
if (c == kEscape && lastCharacter != kEscape) {
|
|
347
|
+
// Skip the backslash; the next character is taken literally.
|
|
348
|
+
return compile(out, format, index + 1, valuable, fixed, kEscape, ok);
|
|
349
|
+
}
|
|
350
|
+
if (lastCharacter != kEscape) {
|
|
351
|
+
if (c == '[') return compile(out, format, index + 1, true, false, c, ok);
|
|
352
|
+
if (c == '{') return compile(out, format, index + 1, false, true, c, ok);
|
|
353
|
+
if (c == ']' || c == '}') return compile(out, format, index + 1, false, false, c, ok);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (valuable && lastCharacter != kEscape) {
|
|
357
|
+
if (c == kEllipsis) {
|
|
358
|
+
CharClass cls = CharClass::AlphaNumeric;
|
|
359
|
+
const Notation* notation = nullptr;
|
|
360
|
+
if (!inheritedClass(out, lastCharacter, &cls, ¬ation)) {
|
|
361
|
+
*ok = false;
|
|
362
|
+
return nullptr;
|
|
363
|
+
}
|
|
364
|
+
// Elliptical states swallow the rest of the block, so they have no child.
|
|
365
|
+
return makeState(out.arena, State{Slot::Value, nullptr, 0, cls, notation, true});
|
|
366
|
+
}
|
|
367
|
+
CharClass cls = CharClass::AlphaNumeric;
|
|
368
|
+
const Notation* notation = nullptr;
|
|
369
|
+
if (!classOf(out, c, &cls, ¬ation)) {
|
|
370
|
+
*ok = false;
|
|
371
|
+
return nullptr;
|
|
372
|
+
}
|
|
373
|
+
const bool optional = isOptionalSlot(c) || (notation != nullptr && notation->isOptional);
|
|
374
|
+
const State* child = compile(out, format, index + 1, true, false, c, ok);
|
|
375
|
+
if (!*ok) return nullptr;
|
|
376
|
+
return makeState(out.arena, State{optional ? Slot::OptionalValue : Slot::Value, child, 0, cls, notation, false});
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const Slot slot = fixed ? Slot::Fixed : Slot::Free;
|
|
380
|
+
const State* child = compile(out, format, index + 1, false, fixed, c, ok);
|
|
381
|
+
if (!*ok) return nullptr;
|
|
382
|
+
return makeState(out.arena, State{slot, child, c, CharClass::AlphaNumeric, nullptr, false});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
void MaskEngine::clearNotations() {
|
|
386
|
+
staged_.clear();
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
void MaskEngine::addNotation(const std::string& character, const std::string& characterSet, bool isOptional) {
|
|
390
|
+
const CodePoints name = AmountFormatter::decode(character);
|
|
391
|
+
if (name.empty()) return;
|
|
392
|
+
staged_.push_back(Notation{name[0], AmountFormatter::decode(characterSet), isOptional});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
bool MaskEngine::setFormat(const std::string& format) {
|
|
396
|
+
return setFormat(format, staged_);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
bool MaskEngine::setFormat(const std::string& format, const std::vector<Notation>& notations) {
|
|
400
|
+
compiled_.reset();
|
|
401
|
+
if (format.empty()) return false;
|
|
402
|
+
|
|
403
|
+
auto next = std::make_unique<Compiled>();
|
|
404
|
+
next->notations = notations;
|
|
405
|
+
|
|
406
|
+
// A notation may not redefine a built-in slot character - the compiler would
|
|
407
|
+
// never reach it, so the caller's intent could not be honoured.
|
|
408
|
+
for (const Notation& notation : next->notations) {
|
|
409
|
+
if (isReservedSlot(notation.character) || notation.characterSet.empty()) return false;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
CodePoints sanitized;
|
|
413
|
+
if (!sanitize(AmountFormatter::decode(format), &sanitized)) return false;
|
|
414
|
+
|
|
415
|
+
bool ok = true;
|
|
416
|
+
const State* initial = compile(*next, sanitized, 0, false, false, 0, &ok);
|
|
417
|
+
if (!ok || initial == nullptr) return false;
|
|
418
|
+
|
|
419
|
+
next->initial = initial;
|
|
420
|
+
compiled_ = std::move(next);
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// MARK: - Applying
|
|
425
|
+
|
|
426
|
+
MaskEngine::Result MaskEngine::apply(const std::string& text, int caret, bool caretForward, bool autocomplete,
|
|
427
|
+
bool autoSkip) const {
|
|
428
|
+
if (!isActive()) {
|
|
429
|
+
// No mask: hand the text back untouched so a bad format cannot brick a field.
|
|
430
|
+
const int count = AmountFormatter::codePointCount(text);
|
|
431
|
+
Result passthrough;
|
|
432
|
+
passthrough.formattedText = text;
|
|
433
|
+
passthrough.caret = std::clamp(caret, 0, count);
|
|
434
|
+
passthrough.extractedValue = text;
|
|
435
|
+
passthrough.complete = true;
|
|
436
|
+
return passthrough;
|
|
437
|
+
}
|
|
438
|
+
// Nothing typed, nothing filled: no literal is completed into an empty field
|
|
439
|
+
// (the placeholder shows, as it does after deleting everything), whatever
|
|
440
|
+
// `autocomplete` says. `clear()`, `setText("")` and an empty `value` prop
|
|
441
|
+
// used to leave a mask's leading literals ("+1 (") behind.
|
|
442
|
+
if (text.empty() && autocomplete) {
|
|
443
|
+
return apply(text, caret, caretForward, false, autoSkip);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const CodePoints input = AmountFormatter::decode(text);
|
|
447
|
+
const int caretPosition = std::clamp(caret, 0, static_cast<int>(input.size()));
|
|
448
|
+
|
|
449
|
+
const auto insertionAffectsCaret = [&](size_t at) {
|
|
450
|
+
return caretForward ? static_cast<int>(at) < caretPosition : static_cast<int>(at) <= caretPosition;
|
|
451
|
+
};
|
|
452
|
+
const auto deletionAffectsCaret = [&](size_t at) { return static_cast<int>(at) < caretPosition; };
|
|
453
|
+
|
|
454
|
+
CodePoints formatted;
|
|
455
|
+
CodePoints extracted;
|
|
456
|
+
int modifiedCaret = caretPosition;
|
|
457
|
+
int affinity = 0;
|
|
458
|
+
const State* state = compiled_->initial;
|
|
459
|
+
std::vector<Step> autocompletionStack;
|
|
460
|
+
|
|
461
|
+
size_t at = 0;
|
|
462
|
+
bool insAffects = insertionAffectsCaret(at);
|
|
463
|
+
bool delAffects = deletionAffectsCaret(at);
|
|
464
|
+
bool have = at < input.size();
|
|
465
|
+
uint32_t c = have ? input[at++] : 0;
|
|
466
|
+
|
|
467
|
+
const auto advance = [&]() {
|
|
468
|
+
insAffects = insertionAffectsCaret(at);
|
|
469
|
+
delAffects = deletionAffectsCaret(at);
|
|
470
|
+
have = at < input.size();
|
|
471
|
+
if (have) c = input[at++];
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
while (have) {
|
|
475
|
+
const std::optional<Step> step = accept(state, c);
|
|
476
|
+
if (step.has_value()) {
|
|
477
|
+
if (delAffects) {
|
|
478
|
+
// A null autocomplete resets the run of skippable constants.
|
|
479
|
+
const std::optional<Step> skippable = autocompleteOf(state);
|
|
480
|
+
if (skippable.has_value()) {
|
|
481
|
+
autocompletionStack.push_back(*skippable);
|
|
482
|
+
} else {
|
|
483
|
+
autocompletionStack.clear();
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
state = step->state;
|
|
487
|
+
if (step->insert.has_value()) formatted.push_back(*step->insert);
|
|
488
|
+
if (step->value.has_value()) extracted.push_back(*step->value);
|
|
489
|
+
if (step->pass) {
|
|
490
|
+
advance();
|
|
491
|
+
affinity += 1;
|
|
492
|
+
} else {
|
|
493
|
+
if (insAffects && step->insert.has_value()) modifiedCaret += 1;
|
|
494
|
+
affinity -= 1;
|
|
495
|
+
}
|
|
496
|
+
} else {
|
|
497
|
+
if (delAffects) modifiedCaret -= 1;
|
|
498
|
+
advance();
|
|
499
|
+
affinity -= 1;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// Trailing constants are filled in once the caret has reached the end of the
|
|
504
|
+
// input - typing "212" into "+1 ([000]) [000]" leaves "+1 (212) " with the
|
|
505
|
+
// caret after the space, ready for the next digit.
|
|
506
|
+
//
|
|
507
|
+
// The engine this is modelled on gates this on `insertionAffectsCaret`, which
|
|
508
|
+
// is `index < caret` under forward gravity. The walk only ends when the index
|
|
509
|
+
// has reached the end of the input, and the caret can never be past that, so
|
|
510
|
+
// that test is always false and its loop is unreachable: constants only turn
|
|
511
|
+
// up retroactively, when the next value character arrives. Running both side
|
|
512
|
+
// by side on "+1 ([000]) [000]-[0000]":
|
|
513
|
+
//
|
|
514
|
+
// typed reference here
|
|
515
|
+
// 212 "+1 (212" "+1 (212) "
|
|
516
|
+
// 212555 "+1 (212) 555" "+1 (212) 555-"
|
|
517
|
+
//
|
|
518
|
+
// Gate it on the caret instead, which is the behaviour that was always
|
|
519
|
+
// described (and their issues #148 and #31).
|
|
520
|
+
const bool caretAtEnd = caretPosition >= static_cast<int>(input.size());
|
|
521
|
+
while (autocomplete && caretAtEnd) {
|
|
522
|
+
const std::optional<Step> step = autocompleteOf(state);
|
|
523
|
+
if (!step.has_value()) break;
|
|
524
|
+
state = step->state;
|
|
525
|
+
if (step->insert.has_value()) {
|
|
526
|
+
formatted.push_back(*step->insert);
|
|
527
|
+
modifiedCaret += 1;
|
|
528
|
+
}
|
|
529
|
+
if (step->value.has_value()) extracted.push_back(*step->value);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
const State* tailState = state;
|
|
533
|
+
CodePoints tail;
|
|
534
|
+
while (autoSkip && !autocompletionStack.empty()) {
|
|
535
|
+
const Step skip = autocompletionStack.back();
|
|
536
|
+
autocompletionStack.pop_back();
|
|
537
|
+
if (static_cast<int>(formatted.size()) == modifiedCaret) {
|
|
538
|
+
if (skip.insert.has_value() && !formatted.empty() && formatted.back() == *skip.insert) {
|
|
539
|
+
formatted.pop_back();
|
|
540
|
+
modifiedCaret -= 1;
|
|
541
|
+
}
|
|
542
|
+
if (skip.value.has_value() && !extracted.empty() && extracted.back() == *skip.value) {
|
|
543
|
+
extracted.pop_back();
|
|
544
|
+
}
|
|
545
|
+
} else if (skip.insert.has_value()) {
|
|
546
|
+
modifiedCaret -= 1;
|
|
547
|
+
}
|
|
548
|
+
tailState = skip.state;
|
|
549
|
+
if (skip.insert.has_value()) {
|
|
550
|
+
tail.assign(1, *skip.insert);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
Result result;
|
|
555
|
+
result.formattedText = AmountFormatter::encode(formatted);
|
|
556
|
+
result.caret = std::clamp(modifiedCaret, 0, static_cast<int>(formatted.size()));
|
|
557
|
+
result.extractedValue = AmountFormatter::encode(extracted);
|
|
558
|
+
result.complete = noMandatoryLeft(state);
|
|
559
|
+
result.affinity = affinity;
|
|
560
|
+
|
|
561
|
+
CodePoints placeholderTail = tail;
|
|
562
|
+
for (const State* s = tailState; s != nullptr;) {
|
|
563
|
+
if (s->slot == Slot::EndOfLine) break;
|
|
564
|
+
if (s->slot == Slot::Free || s->slot == Slot::Fixed) {
|
|
565
|
+
placeholderTail.push_back(s->ownCharacter);
|
|
566
|
+
} else if (s->elliptical) {
|
|
567
|
+
break;
|
|
568
|
+
} else {
|
|
569
|
+
placeholderTail.push_back(s->placeholderCharacter());
|
|
570
|
+
}
|
|
571
|
+
s = s->child;
|
|
572
|
+
}
|
|
573
|
+
result.tailPlaceholder = AmountFormatter::encode(placeholderTail);
|
|
574
|
+
return result;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
MaskEngine::Result MaskEngine::applyEdit(const std::string& current, int start, int end,
|
|
578
|
+
const std::string& replacement, bool autocomplete, bool autoSkip) const {
|
|
579
|
+
const CodePoints text = AmountFormatter::decode(current);
|
|
580
|
+
const int count = static_cast<int>(text.size());
|
|
581
|
+
start = std::clamp(start, 0, count);
|
|
582
|
+
end = std::clamp(end, start, count);
|
|
583
|
+
const CodePoints inserted = AmountFormatter::decode(replacement);
|
|
584
|
+
|
|
585
|
+
CodePoints spliced(text.begin(), text.begin() + start);
|
|
586
|
+
spliced.insert(spliced.end(), inserted.begin(), inserted.end());
|
|
587
|
+
spliced.insert(spliced.end(), text.begin() + end, text.end());
|
|
588
|
+
|
|
589
|
+
const int caret = start + static_cast<int>(inserted.size());
|
|
590
|
+
// Typing runs forward and may autocomplete; deleting runs backward and may
|
|
591
|
+
// auto-skip. Doing both at once would fight itself.
|
|
592
|
+
const bool deleting = inserted.empty();
|
|
593
|
+
return apply(AmountFormatter::encode(spliced), caret, !deleting, !deleting && autocomplete, deleting && autoSkip);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
} // namespace margelo::nitro::nitroinput
|