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

Unified Diff: source/i18n/standardplural.cpp

Issue 1621943002: ICU 56 step 4: Apply post-56 fixes for measure/date format (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@56goog
Patch Set: Created 4 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/standardplural.h ('k') | source/i18n/timezone.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/i18n/standardplural.cpp
diff --git a/source/i18n/standardplural.cpp b/source/i18n/standardplural.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..456e9390ca7c2d14ae8c85faed94c03744221c02
--- /dev/null
+++ b/source/i18n/standardplural.cpp
@@ -0,0 +1,127 @@
+/*
+ *******************************************************************************
+ * Copyright (C) 2015, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ *******************************************************************************
+ * standardplural.cpp
+ *
+ * created on: 2015dec14
+ * created by: Markus W. Scherer
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/unistr.h"
+#include "cstring.h"
+#include "standardplural.h"
+#include "uassert.h"
+
+U_NAMESPACE_BEGIN
+
+static const char *gKeywords[StandardPlural::COUNT] = {
+ "zero", "one", "two", "few", "many", "other"
+};
+
+const char *StandardPlural::getKeyword(Form p) {
+ U_ASSERT(ZERO <= p && p < COUNT);
+ return gKeywords[p];
+}
+
+int32_t StandardPlural::indexOrNegativeFromString(const char *keyword) {
+ switch (*keyword++) {
+ case 'f':
+ if (uprv_strcmp(keyword, "ew") == 0) {
+ return FEW;
+ }
+ break;
+ case 'm':
+ if (uprv_strcmp(keyword, "any") == 0) {
+ return MANY;
+ }
+ break;
+ case 'o':
+ if (uprv_strcmp(keyword, "ther") == 0) {
+ return OTHER;
+ } else if (uprv_strcmp(keyword, "ne") == 0) {
+ return ONE;
+ }
+ break;
+ case 't':
+ if (uprv_strcmp(keyword, "wo") == 0) {
+ return TWO;
+ }
+ break;
+ case 'z':
+ if (uprv_strcmp(keyword, "ero") == 0) {
+ return ZERO;
+ }
+ break;
+ default:
+ break;
+ }
+ return -1;
+}
+
+static const UChar gZero[] = { 0x7A, 0x65, 0x72, 0x6F };
+static const UChar gOne[] = { 0x6F, 0x6E, 0x65 };
+static const UChar gTwo[] = { 0x74, 0x77, 0x6F };
+static const UChar gFew[] = { 0x66, 0x65, 0x77 };
+static const UChar gMany[] = { 0x6D, 0x61, 0x6E, 0x79 };
+static const UChar gOther[] = { 0x6F, 0x74, 0x68, 0x65, 0x72 };
+
+int32_t StandardPlural::indexOrNegativeFromString(const UnicodeString &keyword) {
+ switch (keyword.length()) {
+ case 3:
+ if (keyword.compare(gOne, 3) == 0) {
+ return ONE;
+ } else if (keyword.compare(gTwo, 3) == 0) {
+ return TWO;
+ } else if (keyword.compare(gFew, 3) == 0) {
+ return FEW;
+ }
+ break;
+ case 4:
+ if (keyword.compare(gMany, 4) == 0) {
+ return MANY;
+ } else if (keyword.compare(gZero, 4) == 0) {
+ return ZERO;
+ }
+ break;
+ case 5:
+ if (keyword.compare(gOther, 5) == 0) {
+ return OTHER;
+ }
+ break;
+ default:
+ break;
+ }
+ return -1;
+}
+
+int32_t StandardPlural::indexFromString(const char *keyword, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return OTHER; }
+ int32_t i = indexOrNegativeFromString(keyword);
+ if (i >= 0) {
+ return i;
+ } else {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return OTHER;
+ }
+}
+
+int32_t StandardPlural::indexFromString(const UnicodeString &keyword, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return OTHER; }
+ int32_t i = indexOrNegativeFromString(keyword);
+ if (i >= 0) {
+ return i;
+ } else {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return OTHER;
+ }
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_FORMATTING
« no previous file with comments | « source/i18n/standardplural.h ('k') | source/i18n/timezone.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698