diff --git a/icu4c/source/i18n/standardplural.cpp b/icu4c/source/i18n/standardplural.cpp index 651a9bcc3a..34127a42c3 100644 --- a/icu4c/source/i18n/standardplural.cpp +++ b/icu4c/source/i18n/standardplural.cpp @@ -13,6 +13,7 @@ #if !UCONFIG_NO_FORMATTING +#include "unicode/unistr.h" #include "cstring.h" #include "standardplural.h" #include "uassert.h" @@ -63,6 +64,42 @@ int32_t StandardPlural::indexOrNegativeFromString(const char *keyword) { 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); diff --git a/icu4c/source/i18n/standardplural.h b/icu4c/source/i18n/standardplural.h index 174f2a4a4a..8a8de21884 100644 --- a/icu4c/source/i18n/standardplural.h +++ b/icu4c/source/i18n/standardplural.h @@ -18,6 +18,8 @@ U_NAMESPACE_BEGIN +class UnicodeString; + /** * Standard CLDR plural form/category constants. * See http://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules @@ -47,6 +49,14 @@ public: return static_cast