Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Unified Diff: source/i18n/plurfmt.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/i18n/numfmt.cpp ('k') | source/i18n/plurrule.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/i18n/plurfmt.cpp
diff --git a/source/i18n/plurfmt.cpp b/source/i18n/plurfmt.cpp
index 6ffd8206a8a0b59c7aa7d78d9220f7bd82196d6b..7f6cd86e4c8babb4c0ff03250baebe2988624d91 100644
--- a/source/i18n/plurfmt.cpp
+++ b/source/i18n/plurfmt.cpp
@@ -1,6 +1,6 @@
/*
*******************************************************************************
-* Copyright (C) 2009-2013, International Business Machines Corporation and
+* Copyright (C) 2009-2014, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
@@ -15,6 +15,7 @@
#include "unicode/utypes.h"
#include "cmemory.h"
#include "messageimpl.h"
+#include "nfrule.h"
#include "plurrule_impl.h"
#include "uassert.h"
#include "uhash.h"
@@ -481,6 +482,77 @@ int32_t PluralFormat::findSubMessage(const MessagePattern& pattern, int32_t part
return msgStart;
}
+void PluralFormat::parseType(const UnicodeString& source, const NFRule *rbnfLenientScanner, Formattable& result, FieldPosition& pos) const {
+ // If no pattern was applied, return null.
+ if (msgPattern.countParts() == 0) {
+ pos.setBeginIndex(-1);
+ pos.setEndIndex(-1);
+ return;
+ }
+ int partIndex = 0;
+ int currMatchIndex;
+ int count=msgPattern.countParts();
+ int startingAt = pos.getBeginIndex();
+ if (startingAt < 0) {
+ startingAt = 0;
+ }
+
+ // The keyword is null until we need to match against a non-explicit, not-"other" value.
+ // Then we get the keyword from the selector.
+ // (In other words, we never call the selector if we match against an explicit value,
+ // or if the only non-explicit keyword is "other".)
+ UnicodeString keyword;
+ UnicodeString matchedWord;
+ const UnicodeString& pattern = msgPattern.getPatternString();
+ int matchedIndex = -1;
+ // Iterate over (ARG_SELECTOR ARG_START message ARG_LIMIT) tuples
+ // until the end of the plural-only pattern.
+ while (partIndex < count) {
+ const MessagePattern::Part* partSelector = &msgPattern.getPart(partIndex++);
+ if (partSelector->getType() != UMSGPAT_PART_TYPE_ARG_SELECTOR) {
+ // Bad format
+ continue;
+ }
+
+ const MessagePattern::Part* partStart = &msgPattern.getPart(partIndex++);
+ if (partStart->getType() != UMSGPAT_PART_TYPE_MSG_START) {
+ // Bad format
+ continue;
+ }
+
+ const MessagePattern::Part* partLimit = &msgPattern.getPart(partIndex++);
+ if (partLimit->getType() != UMSGPAT_PART_TYPE_MSG_LIMIT) {
+ // Bad format
+ continue;
+ }
+
+ UnicodeString currArg = pattern.tempSubString(partStart->getLimit(), partLimit->getIndex() - partStart->getLimit());
+ if (rbnfLenientScanner != NULL) {
+ // If lenient parsing is turned ON, we've got some time consuming parsing ahead of us.
+ int32_t length = -1;
+ currMatchIndex = rbnfLenientScanner->findTextLenient(source, currArg, startingAt, &length);
+ }
+ else {
+ currMatchIndex = source.indexOf(currArg);
+ }
+ if (currMatchIndex >= 0 && currMatchIndex >= matchedIndex && currArg.length() > matchedWord.length()) {
+ matchedIndex = currMatchIndex;
+ matchedWord = currArg;
+ keyword = pattern.tempSubString(partStart->getLimit(), partLimit->getIndex() - partStart->getLimit());
+ }
+ }
+ if (matchedIndex >= 0) {
+ pos.setBeginIndex(matchedIndex);
+ pos.setEndIndex(matchedIndex + matchedWord.length());
+ result.setString(keyword);
+ return;
+ }
+
+ // Not found!
+ pos.setBeginIndex(-1);
+ pos.setEndIndex(-1);
+}
+
PluralFormat::PluralSelector::~PluralSelector() {}
PluralFormat::PluralSelectorAdapter::~PluralSelectorAdapter() {
« no previous file with comments | « source/i18n/numfmt.cpp ('k') | source/i18n/plurrule.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698