X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/0f5d89e82340278ed3d7d50029f37cab2c41a57e..1a147d096ae81f4c8262f7bfc56bd19fc2dee932:/icuSources/i18n/numparse_scientific.cpp?ds=sidebyside diff --git a/icuSources/i18n/numparse_scientific.cpp b/icuSources/i18n/numparse_scientific.cpp index 611695e5..e4285d62 100644 --- a/icuSources/i18n/numparse_scientific.cpp +++ b/icuSources/i18n/numparse_scientific.cpp @@ -28,6 +28,10 @@ inline const UnicodeSet& plusSignSet() { return *unisets::get(unisets::PLUS_SIGN); } +inline const UnicodeSet& ignorablesSet() { // + return *unisets::get(unisets::STRICT_IGNORABLES); +} + } // namespace @@ -56,11 +60,17 @@ bool ScientificMatcher::match(StringSegment& segment, ParsedNumber& result, UErr return false; } + // Only accept one exponent per string. + if (0 != (result.flags & FLAG_HAS_EXPONENT)) { + return false; + } + // First match the scientific separator, and then match another number after it. // NOTE: This is guarded by the smoke test; no need to check fExponentSeparatorString length again. int overlap1 = segment.getCommonPrefixLength(fExponentSeparatorString); if (overlap1 == fExponentSeparatorString.length()) { // Full exponent separator match. + int32_t exponentStart = segment.getOffset(); // // First attempt to get a code point, returning true if we can't get one. if (segment.length() == overlap1) { @@ -69,6 +79,9 @@ bool ScientificMatcher::match(StringSegment& segment, ParsedNumber& result, UErr segment.adjustOffset(overlap1); // Allow a sign, and then try to match digits. + while (segment.length() > 0 && segment.startsWith(ignorablesSet())) { // + segment.adjustOffsetByCodePoint(); + } int8_t exponentSign = 1; if (segment.startsWith(minusSignSet())) { exponentSign = -1; @@ -80,7 +93,7 @@ bool ScientificMatcher::match(StringSegment& segment, ParsedNumber& result, UErr int32_t overlap2 = segment.getCommonPrefixLength(fCustomMinusSign); if (overlap2 != fCustomMinusSign.length()) { // Partial custom sign match; un-match the exponent separator. - segment.adjustOffset(-overlap1); + segment.setOffset(exponentStart); return true; } exponentSign = -1; @@ -90,11 +103,14 @@ bool ScientificMatcher::match(StringSegment& segment, ParsedNumber& result, UErr int32_t overlap2 = segment.getCommonPrefixLength(fCustomPlusSign); if (overlap2 != fCustomPlusSign.length()) { // Partial custom sign match; un-match the exponent separator. - segment.adjustOffset(-overlap1); + segment.setOffset(exponentStart); return true; } segment.adjustOffset(overlap2); } + while (segment.length() > 0 && segment.startsWith(ignorablesSet())) { // + segment.adjustOffsetByCodePoint(); + } // We are supposed to accept E0 after NaN, so we need to make sure result.quantity is available. bool wasBogus = result.quantity.bogus; @@ -108,7 +124,7 @@ bool ScientificMatcher::match(StringSegment& segment, ParsedNumber& result, UErr result.flags |= FLAG_HAS_EXPONENT; } else { // No exponent digits were matched; un-match the exponent separator. - segment.adjustOffset(-overlap1); + segment.setOffset(exponentStart); } return digitsReturnValue;