2018-02-08 08:49:50 +00:00
|
|
|
// © 2018 and later: Unicode, Inc. and others.
|
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
2018-04-23 23:02:26 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2018-02-08 08:49:50 +00:00
|
|
|
|
2018-02-13 02:23:52 +00:00
|
|
|
// Allow implicit conversion from char16_t* to UnicodeString for this file:
|
|
|
|
// Helpful in toString methods and elsewhere.
|
2018-02-09 06:30:40 +00:00
|
|
|
#define UNISTR_FROM_STRING_EXPLICIT
|
|
|
|
|
2018-03-21 05:17:28 +00:00
|
|
|
#include <typeinfo>
|
|
|
|
#include <array>
|
2018-02-08 08:49:50 +00:00
|
|
|
#include "number_types.h"
|
|
|
|
#include "number_patternstring.h"
|
|
|
|
#include "numparse_types.h"
|
|
|
|
#include "numparse_impl.h"
|
|
|
|
#include "numparse_symbols.h"
|
|
|
|
#include "numparse_decimal.h"
|
|
|
|
#include "unicode/numberformatter.h"
|
2018-02-13 02:23:52 +00:00
|
|
|
#include "cstr.h"
|
2018-03-21 05:17:28 +00:00
|
|
|
#include "number_mapper.h"
|
2018-05-16 22:46:40 +00:00
|
|
|
#include "static_unicode_sets.h"
|
2018-02-08 09:59:35 +00:00
|
|
|
|
2018-02-08 08:49:50 +00:00
|
|
|
using namespace icu;
|
|
|
|
using namespace icu::number;
|
|
|
|
using namespace icu::number::impl;
|
|
|
|
using namespace icu::numparse;
|
|
|
|
using namespace icu::numparse::impl;
|
|
|
|
|
|
|
|
|
2018-05-03 09:13:46 +00:00
|
|
|
NumberParseMatcher::~NumberParseMatcher() = default;
|
|
|
|
|
|
|
|
|
2018-02-08 08:49:50 +00:00
|
|
|
NumberParserImpl*
|
|
|
|
NumberParserImpl::createSimpleParser(const Locale& locale, const UnicodeString& patternString,
|
|
|
|
parse_flags_t parseFlags, UErrorCode& status) {
|
|
|
|
|
2018-03-21 06:30:29 +00:00
|
|
|
LocalPointer<NumberParserImpl> parser(new NumberParserImpl(parseFlags));
|
2018-02-08 08:49:50 +00:00
|
|
|
DecimalFormatSymbols symbols(locale, status);
|
|
|
|
|
2019-05-21 22:36:25 +00:00
|
|
|
parser->fLocalMatchers.ignorables = {parseFlags};
|
2018-02-10 15:49:02 +00:00
|
|
|
IgnorablesMatcher& ignorables = parser->fLocalMatchers.ignorables;
|
2018-02-09 02:35:02 +00:00
|
|
|
|
2018-03-21 05:17:28 +00:00
|
|
|
DecimalFormatSymbols dfs(locale, status);
|
2018-05-29 01:59:42 +00:00
|
|
|
dfs.setSymbol(DecimalFormatSymbols::kCurrencySymbol, u"IU$");
|
|
|
|
dfs.setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, u"ICU");
|
2018-03-21 05:17:28 +00:00
|
|
|
CurrencySymbols currencySymbols({u"ICU", status}, locale, dfs, status);
|
2018-02-08 08:49:50 +00:00
|
|
|
|
|
|
|
ParsedPatternInfo patternInfo;
|
|
|
|
PatternParser::parseToPatternInfo(patternString, patternInfo, status);
|
2018-02-10 15:49:02 +00:00
|
|
|
|
2018-02-13 02:23:52 +00:00
|
|
|
// The following statements set up the affix matchers.
|
|
|
|
AffixTokenMatcherSetupData affixSetupData = {
|
2018-05-24 04:35:16 +00:00
|
|
|
currencySymbols, symbols, ignorables, locale, parseFlags};
|
2018-02-13 02:23:52 +00:00
|
|
|
parser->fLocalMatchers.affixTokenMatcherWarehouse = {&affixSetupData};
|
|
|
|
parser->fLocalMatchers.affixMatcherWarehouse = {&parser->fLocalMatchers.affixTokenMatcherWarehouse};
|
|
|
|
parser->fLocalMatchers.affixMatcherWarehouse.createAffixMatchers(
|
|
|
|
patternInfo, *parser, ignorables, parseFlags, status);
|
2018-02-08 08:49:50 +00:00
|
|
|
|
|
|
|
Grouper grouper = Grouper::forStrategy(UNUM_GROUPING_AUTO);
|
|
|
|
grouper.setLocaleData(patternInfo, locale);
|
|
|
|
|
2018-02-09 05:47:49 +00:00
|
|
|
parser->addMatcher(parser->fLocalMatchers.ignorables);
|
|
|
|
parser->addMatcher(parser->fLocalMatchers.decimal = {symbols, grouper, parseFlags});
|
|
|
|
parser->addMatcher(parser->fLocalMatchers.minusSign = {symbols, false});
|
|
|
|
parser->addMatcher(parser->fLocalMatchers.plusSign = {symbols, false});
|
|
|
|
parser->addMatcher(parser->fLocalMatchers.percent = {symbols});
|
|
|
|
parser->addMatcher(parser->fLocalMatchers.permille = {symbols});
|
|
|
|
parser->addMatcher(parser->fLocalMatchers.nan = {symbols});
|
2018-02-09 06:30:40 +00:00
|
|
|
parser->addMatcher(parser->fLocalMatchers.infinity = {symbols});
|
|
|
|
parser->addMatcher(parser->fLocalMatchers.padding = {u"@"});
|
2018-02-09 06:57:37 +00:00
|
|
|
parser->addMatcher(parser->fLocalMatchers.scientific = {symbols, grouper});
|
2018-05-24 04:35:16 +00:00
|
|
|
parser->addMatcher(parser->fLocalMatchers.currency = {currencySymbols, symbols, parseFlags, status});
|
2019-02-06 22:38:36 +00:00
|
|
|
parser->addMatcher(parser->fLocalValidators.number = {});
|
2018-02-08 08:49:50 +00:00
|
|
|
|
|
|
|
parser->freeze();
|
2018-03-21 05:17:28 +00:00
|
|
|
return parser.orphan();
|
2018-02-08 08:49:50 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 05:17:28 +00:00
|
|
|
NumberParserImpl*
|
|
|
|
NumberParserImpl::createParserFromProperties(const number::impl::DecimalFormatProperties& properties,
|
|
|
|
const DecimalFormatSymbols& symbols, bool parseCurrency,
|
2018-03-21 06:33:37 +00:00
|
|
|
UErrorCode& status) {
|
2018-03-21 05:17:28 +00:00
|
|
|
Locale locale = symbols.getLocale();
|
2018-04-07 11:10:08 +00:00
|
|
|
PropertiesAffixPatternProvider localPAPP;
|
|
|
|
CurrencyPluralInfoAffixProvider localCPIAP;
|
|
|
|
AffixPatternProvider* affixProvider;
|
|
|
|
if (properties.currencyPluralInfo.fPtr.isNull()) {
|
|
|
|
localPAPP.setTo(properties, status);
|
|
|
|
affixProvider = &localPAPP;
|
|
|
|
} else {
|
2018-04-11 23:14:06 +00:00
|
|
|
localCPIAP.setTo(*properties.currencyPluralInfo.fPtr, properties, status);
|
2018-04-07 11:10:08 +00:00
|
|
|
affixProvider = &localCPIAP;
|
|
|
|
}
|
|
|
|
if (affixProvider == nullptr || U_FAILURE(status)) { return nullptr; }
|
2018-03-21 05:17:28 +00:00
|
|
|
CurrencyUnit currency = resolveCurrency(properties, locale, status);
|
|
|
|
CurrencySymbols currencySymbols(currency, locale, symbols, status);
|
|
|
|
bool isStrict = properties.parseMode.getOrDefault(PARSE_MODE_STRICT) == PARSE_MODE_STRICT;
|
|
|
|
Grouper grouper = Grouper::forProperties(properties);
|
|
|
|
int parseFlags = 0;
|
2018-04-07 11:10:08 +00:00
|
|
|
if (affixProvider == nullptr || U_FAILURE(status)) { return nullptr; }
|
2018-03-21 05:17:28 +00:00
|
|
|
if (!properties.parseCaseSensitive) {
|
|
|
|
parseFlags |= PARSE_FLAG_IGNORE_CASE;
|
|
|
|
}
|
|
|
|
if (properties.parseIntegerOnly) {
|
|
|
|
parseFlags |= PARSE_FLAG_INTEGER_ONLY;
|
|
|
|
}
|
|
|
|
if (properties.signAlwaysShown) {
|
|
|
|
parseFlags |= PARSE_FLAG_PLUS_SIGN_ALLOWED;
|
|
|
|
}
|
|
|
|
if (isStrict) {
|
|
|
|
parseFlags |= PARSE_FLAG_STRICT_GROUPING_SIZE;
|
|
|
|
parseFlags |= PARSE_FLAG_STRICT_SEPARATORS;
|
|
|
|
parseFlags |= PARSE_FLAG_USE_FULL_AFFIXES;
|
|
|
|
parseFlags |= PARSE_FLAG_EXACT_AFFIX;
|
2019-05-21 22:36:25 +00:00
|
|
|
parseFlags |= PARSE_FLAG_STRICT_IGNORABLES;
|
2018-03-21 05:17:28 +00:00
|
|
|
} else {
|
|
|
|
parseFlags |= PARSE_FLAG_INCLUDE_UNPAIRED_AFFIXES;
|
|
|
|
}
|
|
|
|
if (grouper.getPrimary() <= 0) {
|
|
|
|
parseFlags |= PARSE_FLAG_GROUPING_DISABLED;
|
|
|
|
}
|
2018-04-07 11:10:08 +00:00
|
|
|
if (parseCurrency || affixProvider->hasCurrencySign()) {
|
2018-03-21 05:17:28 +00:00
|
|
|
parseFlags |= PARSE_FLAG_MONETARY_SEPARATORS;
|
|
|
|
}
|
2018-05-24 04:35:16 +00:00
|
|
|
if (!parseCurrency) {
|
|
|
|
parseFlags |= PARSE_FLAG_NO_FOREIGN_CURRENCY;
|
|
|
|
}
|
2018-03-21 05:17:28 +00:00
|
|
|
|
2018-03-21 06:30:29 +00:00
|
|
|
LocalPointer<NumberParserImpl> parser(new NumberParserImpl(parseFlags));
|
2018-03-21 05:17:28 +00:00
|
|
|
|
2019-05-21 22:36:25 +00:00
|
|
|
parser->fLocalMatchers.ignorables = {parseFlags};
|
2018-03-21 09:48:55 +00:00
|
|
|
IgnorablesMatcher& ignorables = parser->fLocalMatchers.ignorables;
|
|
|
|
|
2018-03-21 05:17:28 +00:00
|
|
|
//////////////////////
|
|
|
|
/// AFFIX MATCHERS ///
|
|
|
|
//////////////////////
|
|
|
|
|
|
|
|
// The following statements set up the affix matchers.
|
|
|
|
AffixTokenMatcherSetupData affixSetupData = {
|
2018-05-24 04:35:16 +00:00
|
|
|
currencySymbols, symbols, ignorables, locale, parseFlags};
|
2018-03-21 05:17:28 +00:00
|
|
|
parser->fLocalMatchers.affixTokenMatcherWarehouse = {&affixSetupData};
|
|
|
|
parser->fLocalMatchers.affixMatcherWarehouse = {&parser->fLocalMatchers.affixTokenMatcherWarehouse};
|
|
|
|
parser->fLocalMatchers.affixMatcherWarehouse.createAffixMatchers(
|
2018-04-07 11:10:08 +00:00
|
|
|
*affixProvider, *parser, ignorables, parseFlags, status);
|
2018-03-21 05:17:28 +00:00
|
|
|
|
|
|
|
////////////////////////
|
|
|
|
/// CURRENCY MATCHER ///
|
|
|
|
////////////////////////
|
|
|
|
|
2018-04-07 11:10:08 +00:00
|
|
|
if (parseCurrency || affixProvider->hasCurrencySign()) {
|
2018-05-24 04:35:16 +00:00
|
|
|
parser->addMatcher(parser->fLocalMatchers.currency = {currencySymbols, symbols, parseFlags, status});
|
2018-03-21 05:17:28 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 06:49:24 +00:00
|
|
|
///////////////
|
|
|
|
/// PERCENT ///
|
|
|
|
///////////////
|
|
|
|
|
|
|
|
// ICU-TC meeting, April 11, 2018: accept percent/permille only if it is in the pattern,
|
|
|
|
// and to maintain regressive behavior, divide by 100 even if no percent sign is present.
|
2018-09-20 21:47:25 +00:00
|
|
|
if (!isStrict && affixProvider->containsSymbolType(AffixPatternType::TYPE_PERCENT, status)) {
|
2018-04-12 06:49:24 +00:00
|
|
|
parser->addMatcher(parser->fLocalMatchers.percent = {symbols});
|
|
|
|
}
|
2018-09-20 21:47:25 +00:00
|
|
|
if (!isStrict && affixProvider->containsSymbolType(AffixPatternType::TYPE_PERMILLE, status)) {
|
2018-04-12 06:49:24 +00:00
|
|
|
parser->addMatcher(parser->fLocalMatchers.permille = {symbols});
|
|
|
|
}
|
|
|
|
|
2018-03-21 05:17:28 +00:00
|
|
|
///////////////////////////////
|
|
|
|
/// OTHER STANDARD MATCHERS ///
|
|
|
|
///////////////////////////////
|
|
|
|
|
|
|
|
if (!isStrict) {
|
|
|
|
parser->addMatcher(parser->fLocalMatchers.plusSign = {symbols, false});
|
|
|
|
parser->addMatcher(parser->fLocalMatchers.minusSign = {symbols, false});
|
|
|
|
}
|
2018-04-06 09:35:16 +00:00
|
|
|
parser->addMatcher(parser->fLocalMatchers.nan = {symbols});
|
2018-03-21 05:17:28 +00:00
|
|
|
parser->addMatcher(parser->fLocalMatchers.infinity = {symbols});
|
|
|
|
UnicodeString padString = properties.padString;
|
|
|
|
if (!padString.isBogus() && !ignorables.getSet()->contains(padString)) {
|
|
|
|
parser->addMatcher(parser->fLocalMatchers.padding = {padString});
|
|
|
|
}
|
|
|
|
parser->addMatcher(parser->fLocalMatchers.ignorables);
|
|
|
|
parser->addMatcher(parser->fLocalMatchers.decimal = {symbols, grouper, parseFlags});
|
2018-04-18 06:03:29 +00:00
|
|
|
// NOTE: parseNoExponent doesn't disable scientific parsing if we have a scientific formatter
|
|
|
|
if (!properties.parseNoExponent || properties.minimumExponentDigits > 0) {
|
2018-03-21 05:17:28 +00:00
|
|
|
parser->addMatcher(parser->fLocalMatchers.scientific = {symbols, grouper});
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
/// VALIDATORS ///
|
|
|
|
//////////////////
|
|
|
|
|
|
|
|
parser->addMatcher(parser->fLocalValidators.number = {});
|
|
|
|
if (isStrict) {
|
|
|
|
parser->addMatcher(parser->fLocalValidators.affix = {});
|
|
|
|
}
|
|
|
|
if (parseCurrency) {
|
|
|
|
parser->addMatcher(parser->fLocalValidators.currency = {});
|
|
|
|
}
|
|
|
|
if (properties.decimalPatternMatchRequired) {
|
|
|
|
bool patternHasDecimalSeparator =
|
|
|
|
properties.decimalSeparatorAlwaysShown || properties.maximumFractionDigits != 0;
|
|
|
|
parser->addMatcher(parser->fLocalValidators.decimalSeparator = {patternHasDecimalSeparator});
|
|
|
|
}
|
2018-04-14 05:54:53 +00:00
|
|
|
// The multiplier takes care of scaling percentages.
|
2018-04-14 09:45:39 +00:00
|
|
|
Scale multiplier = scaleFromProperties(properties);
|
2018-04-14 05:54:53 +00:00
|
|
|
if (multiplier.isValid()) {
|
|
|
|
parser->addMatcher(parser->fLocalValidators.multiplier = {multiplier});
|
2018-04-03 04:38:16 +00:00
|
|
|
}
|
2018-03-21 05:17:28 +00:00
|
|
|
|
|
|
|
parser->freeze();
|
|
|
|
return parser.orphan();
|
|
|
|
}
|
2018-03-14 10:41:27 +00:00
|
|
|
|
2018-03-21 06:30:29 +00:00
|
|
|
NumberParserImpl::NumberParserImpl(parse_flags_t parseFlags)
|
|
|
|
: fParseFlags(parseFlags) {
|
2018-02-08 08:49:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NumberParserImpl::~NumberParserImpl() {
|
|
|
|
fNumMatchers = 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 06:36:07 +00:00
|
|
|
void NumberParserImpl::addMatcher(NumberParseMatcher& matcher) {
|
2018-02-08 08:49:50 +00:00
|
|
|
if (fNumMatchers + 1 > fMatchers.getCapacity()) {
|
|
|
|
fMatchers.resize(fNumMatchers * 2, fNumMatchers);
|
|
|
|
}
|
2018-02-09 05:47:49 +00:00
|
|
|
fMatchers[fNumMatchers] = &matcher;
|
2018-02-08 08:49:50 +00:00
|
|
|
fNumMatchers++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NumberParserImpl::freeze() {
|
|
|
|
fFrozen = true;
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:05:20 +00:00
|
|
|
parse_flags_t NumberParserImpl::getParseFlags() const {
|
|
|
|
return fParseFlags;
|
|
|
|
}
|
|
|
|
|
2018-02-08 09:59:35 +00:00
|
|
|
void NumberParserImpl::parse(const UnicodeString& input, bool greedy, ParsedNumber& result,
|
|
|
|
UErrorCode& status) const {
|
|
|
|
return parse(input, 0, greedy, result, status);
|
|
|
|
}
|
|
|
|
|
2018-02-09 05:47:49 +00:00
|
|
|
void NumberParserImpl::parse(const UnicodeString& input, int32_t start, bool greedy, ParsedNumber& result,
|
|
|
|
UErrorCode& status) const {
|
2018-04-19 09:29:39 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-08 09:59:35 +00:00
|
|
|
U_ASSERT(fFrozen);
|
|
|
|
// TODO: Check start >= 0 and start < input.length()
|
2018-03-30 04:28:53 +00:00
|
|
|
StringSegment segment(input, 0 != (fParseFlags & PARSE_FLAG_IGNORE_CASE));
|
2018-02-08 09:59:35 +00:00
|
|
|
segment.adjustOffset(start);
|
|
|
|
if (greedy) {
|
2019-02-06 22:38:36 +00:00
|
|
|
parseGreedy(segment, result, status);
|
|
|
|
} else if (0 != (fParseFlags & PARSE_FLAG_ALLOW_INFINITE_RECURSION)) {
|
|
|
|
// Start at 1 so that recursionLevels never gets to 0
|
|
|
|
parseLongestRecursive(segment, result, 1, status);
|
2018-02-08 09:59:35 +00:00
|
|
|
} else {
|
2019-02-06 22:38:36 +00:00
|
|
|
// Arbitrary recursion safety limit: 100 levels.
|
|
|
|
parseLongestRecursive(segment, result, -100, status);
|
2018-02-08 09:59:35 +00:00
|
|
|
}
|
|
|
|
for (int32_t i = 0; i < fNumMatchers; i++) {
|
|
|
|
fMatchers[i]->postProcess(result);
|
|
|
|
}
|
2018-03-31 03:10:44 +00:00
|
|
|
result.postProcess();
|
2018-02-08 09:59:35 +00:00
|
|
|
}
|
|
|
|
|
2019-02-06 22:38:36 +00:00
|
|
|
void NumberParserImpl::parseGreedy(StringSegment& segment, ParsedNumber& result,
|
2018-02-08 09:59:35 +00:00
|
|
|
UErrorCode& status) const {
|
2019-02-06 22:38:36 +00:00
|
|
|
// Note: this method is not recursive in order to avoid stack overflow.
|
|
|
|
for (int i = 0; i <fNumMatchers;) {
|
|
|
|
// Base Case
|
|
|
|
if (segment.length() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-21 06:30:29 +00:00
|
|
|
const NumberParseMatcher* matcher = fMatchers[i];
|
|
|
|
if (!matcher->smokeTest(segment)) {
|
2019-02-06 22:38:36 +00:00
|
|
|
// Matcher failed smoke test: try the next one
|
|
|
|
i++;
|
2018-02-08 09:59:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-02-06 22:38:36 +00:00
|
|
|
int32_t initialOffset = segment.getOffset();
|
2018-02-08 09:59:35 +00:00
|
|
|
matcher->match(segment, result, status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (segment.getOffset() != initialOffset) {
|
2019-02-06 22:38:36 +00:00
|
|
|
// Greedy heuristic: accept the match and loop back
|
|
|
|
i = 0;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
// Matcher did not match: try the next one
|
|
|
|
i++;
|
|
|
|
continue;
|
2018-02-08 09:59:35 +00:00
|
|
|
}
|
2019-02-06 22:38:36 +00:00
|
|
|
UPRV_UNREACHABLE;
|
2018-02-08 09:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: If we get here, the greedy parse completed without consuming the entire string.
|
|
|
|
}
|
|
|
|
|
|
|
|
void NumberParserImpl::parseLongestRecursive(StringSegment& segment, ParsedNumber& result,
|
2019-02-06 22:38:36 +00:00
|
|
|
int32_t recursionLevels,
|
2018-02-08 09:59:35 +00:00
|
|
|
UErrorCode& status) const {
|
|
|
|
// Base Case
|
|
|
|
if (segment.length() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-06 22:38:36 +00:00
|
|
|
// Safety against stack overflow
|
|
|
|
if (recursionLevels == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-08 09:59:35 +00:00
|
|
|
// TODO: Give a nice way for the matcher to reset the ParsedNumber?
|
|
|
|
ParsedNumber initial(result);
|
|
|
|
ParsedNumber candidate;
|
|
|
|
|
|
|
|
int initialOffset = segment.getOffset();
|
|
|
|
for (int32_t i = 0; i < fNumMatchers; i++) {
|
|
|
|
const NumberParseMatcher* matcher = fMatchers[i];
|
2018-03-21 06:30:29 +00:00
|
|
|
if (!matcher->smokeTest(segment)) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-02-08 09:59:35 +00:00
|
|
|
|
|
|
|
// In a non-greedy parse, we attempt all possible matches and pick the best.
|
|
|
|
for (int32_t charsToConsume = 0; charsToConsume < segment.length();) {
|
|
|
|
charsToConsume += U16_LENGTH(segment.codePointAt(charsToConsume));
|
|
|
|
|
|
|
|
// Run the matcher on a segment of the current length.
|
|
|
|
candidate = initial;
|
|
|
|
segment.setLength(charsToConsume);
|
|
|
|
bool maybeMore = matcher->match(segment, candidate, status);
|
|
|
|
segment.resetLength();
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the entire segment was consumed, recurse.
|
|
|
|
if (segment.getOffset() - initialOffset == charsToConsume) {
|
2019-02-06 22:38:36 +00:00
|
|
|
parseLongestRecursive(segment, candidate, recursionLevels + 1, status);
|
2018-02-08 09:59:35 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (candidate.isBetterThan(result)) {
|
|
|
|
result = candidate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since the segment can be re-used, reset the offset.
|
|
|
|
// This does not have an effect if the matcher did not consume any chars.
|
|
|
|
segment.setOffset(initialOffset);
|
|
|
|
|
|
|
|
// Unless the matcher wants to see the next char, continue to the next matcher.
|
|
|
|
if (!maybeMore) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString NumberParserImpl::toString() const {
|
|
|
|
UnicodeString result(u"<NumberParserImpl matchers:[");
|
|
|
|
for (int32_t i = 0; i < fNumMatchers; i++) {
|
|
|
|
result.append(u' ');
|
2018-02-13 02:23:52 +00:00
|
|
|
result.append(fMatchers[i]->toString());
|
2018-02-08 09:59:35 +00:00
|
|
|
}
|
|
|
|
result.append(u" ]>", -1);
|
|
|
|
return result;
|
|
|
|
}
|
2018-02-08 08:49:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|