aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/i18n/numparse_symbols.cpp
diff options
context:
space:
mode:
authorvvvv <vvvv@yandex-team.ru>2022-03-03 23:09:11 +0300
committervvvv <vvvv@yandex-team.ru>2022-03-03 23:09:11 +0300
commit8dbdbab054b6eb352cfffdad09991052008062fc (patch)
tree71befed92d327f2cc409bff4986ec510d0530d92 /contrib/libs/icu/i18n/numparse_symbols.cpp
parented3f4e21f3a3837059607ec2606e1dc910269ac0 (diff)
downloadydb-8dbdbab054b6eb352cfffdad09991052008062fc.tar.gz
YQL-13710 try to switch to new shiny PG
ref:2bed0445c8e8bd6c575883632adf19445f0a72a7
Diffstat (limited to 'contrib/libs/icu/i18n/numparse_symbols.cpp')
-rw-r--r--contrib/libs/icu/i18n/numparse_symbols.cpp198
1 files changed, 198 insertions, 0 deletions
diff --git a/contrib/libs/icu/i18n/numparse_symbols.cpp b/contrib/libs/icu/i18n/numparse_symbols.cpp
new file mode 100644
index 0000000000..608f4f5c8b
--- /dev/null
+++ b/contrib/libs/icu/i18n/numparse_symbols.cpp
@@ -0,0 +1,198 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "numparse_types.h"
+#include "numparse_symbols.h"
+#include "numparse_utils.h"
+#include "string_segment.h"
+
+using namespace icu;
+using namespace icu::numparse;
+using namespace icu::numparse::impl;
+
+
+SymbolMatcher::SymbolMatcher(const UnicodeString& symbolString, unisets::Key key) {
+ fUniSet = unisets::get(key);
+ if (fUniSet->contains(symbolString)) {
+ fString.setToBogus();
+ } else {
+ fString = symbolString;
+ }
+}
+
+const UnicodeSet* SymbolMatcher::getSet() const {
+ return fUniSet;
+}
+
+bool SymbolMatcher::match(StringSegment& segment, ParsedNumber& result, UErrorCode&) const {
+ // Smoke test first; this matcher might be disabled.
+ if (isDisabled(result)) {
+ return false;
+ }
+
+ // Test the string first in order to consume trailing chars greedily.
+ int overlap = 0;
+ if (!fString.isEmpty()) {
+ overlap = segment.getCommonPrefixLength(fString);
+ if (overlap == fString.length()) {
+ segment.adjustOffset(fString.length());
+ accept(segment, result);
+ return false;
+ }
+ }
+
+ int cp = segment.getCodePoint();
+ if (cp != -1 && fUniSet->contains(cp)) {
+ segment.adjustOffset(U16_LENGTH(cp));
+ accept(segment, result);
+ return false;
+ }
+
+ return overlap == segment.length();
+}
+
+bool SymbolMatcher::smokeTest(const StringSegment& segment) const {
+ return segment.startsWith(*fUniSet) || segment.startsWith(fString);
+}
+
+UnicodeString SymbolMatcher::toString() const {
+ // TODO: Customize output for each symbol
+ return u"<Symbol>";
+}
+
+
+IgnorablesMatcher::IgnorablesMatcher(parse_flags_t parseFlags) :
+ SymbolMatcher(
+ {},
+ (0 != (parseFlags & PARSE_FLAG_STRICT_IGNORABLES)) ?
+ unisets::STRICT_IGNORABLES :
+ unisets::DEFAULT_IGNORABLES) {
+}
+
+bool IgnorablesMatcher::isFlexible() const {
+ return true;
+}
+
+UnicodeString IgnorablesMatcher::toString() const {
+ return u"<Ignorables>";
+}
+
+bool IgnorablesMatcher::isDisabled(const ParsedNumber&) const {
+ return false;
+}
+
+void IgnorablesMatcher::accept(StringSegment&, ParsedNumber&) const {
+ // No-op
+}
+
+
+InfinityMatcher::InfinityMatcher(const DecimalFormatSymbols& dfs)
+ : SymbolMatcher(dfs.getConstSymbol(DecimalFormatSymbols::kInfinitySymbol), unisets::INFINITY_SIGN) {
+}
+
+bool InfinityMatcher::isDisabled(const ParsedNumber& result) const {
+ return 0 != (result.flags & FLAG_INFINITY);
+}
+
+void InfinityMatcher::accept(StringSegment& segment, ParsedNumber& result) const {
+ result.flags |= FLAG_INFINITY;
+ result.setCharsConsumed(segment);
+}
+
+
+MinusSignMatcher::MinusSignMatcher(const DecimalFormatSymbols& dfs, bool allowTrailing)
+ : SymbolMatcher(dfs.getConstSymbol(DecimalFormatSymbols::kMinusSignSymbol), unisets::MINUS_SIGN),
+ fAllowTrailing(allowTrailing) {
+}
+
+bool MinusSignMatcher::isDisabled(const ParsedNumber& result) const {
+ return !fAllowTrailing && result.seenNumber();
+}
+
+void MinusSignMatcher::accept(StringSegment& segment, ParsedNumber& result) const {
+ result.flags |= FLAG_NEGATIVE;
+ result.setCharsConsumed(segment);
+}
+
+
+NanMatcher::NanMatcher(const DecimalFormatSymbols& dfs)
+ : SymbolMatcher(dfs.getConstSymbol(DecimalFormatSymbols::kNaNSymbol), unisets::EMPTY) {
+}
+
+bool NanMatcher::isDisabled(const ParsedNumber& result) const {
+ return result.seenNumber();
+}
+
+void NanMatcher::accept(StringSegment& segment, ParsedNumber& result) const {
+ result.flags |= FLAG_NAN;
+ result.setCharsConsumed(segment);
+}
+
+
+PaddingMatcher::PaddingMatcher(const UnicodeString& padString)
+ : SymbolMatcher(padString, unisets::EMPTY) {}
+
+bool PaddingMatcher::isFlexible() const {
+ return true;
+}
+
+bool PaddingMatcher::isDisabled(const ParsedNumber&) const {
+ return false;
+}
+
+void PaddingMatcher::accept(StringSegment&, ParsedNumber&) const {
+ // No-op
+}
+
+
+PercentMatcher::PercentMatcher(const DecimalFormatSymbols& dfs)
+ : SymbolMatcher(dfs.getConstSymbol(DecimalFormatSymbols::kPercentSymbol), unisets::PERCENT_SIGN) {
+}
+
+bool PercentMatcher::isDisabled(const ParsedNumber& result) const {
+ return 0 != (result.flags & FLAG_PERCENT);
+}
+
+void PercentMatcher::accept(StringSegment& segment, ParsedNumber& result) const {
+ result.flags |= FLAG_PERCENT;
+ result.setCharsConsumed(segment);
+}
+
+
+PermilleMatcher::PermilleMatcher(const DecimalFormatSymbols& dfs)
+ : SymbolMatcher(dfs.getConstSymbol(DecimalFormatSymbols::kPerMillSymbol), unisets::PERMILLE_SIGN) {
+}
+
+bool PermilleMatcher::isDisabled(const ParsedNumber& result) const {
+ return 0 != (result.flags & FLAG_PERMILLE);
+}
+
+void PermilleMatcher::accept(StringSegment& segment, ParsedNumber& result) const {
+ result.flags |= FLAG_PERMILLE;
+ result.setCharsConsumed(segment);
+}
+
+
+PlusSignMatcher::PlusSignMatcher(const DecimalFormatSymbols& dfs, bool allowTrailing)
+ : SymbolMatcher(dfs.getConstSymbol(DecimalFormatSymbols::kPlusSignSymbol), unisets::PLUS_SIGN),
+ fAllowTrailing(allowTrailing) {
+}
+
+bool PlusSignMatcher::isDisabled(const ParsedNumber& result) const {
+ return !fAllowTrailing && result.seenNumber();
+}
+
+void PlusSignMatcher::accept(StringSegment& segment, ParsedNumber& result) const {
+ result.setCharsConsumed(segment);
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */