]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/standardplural.cpp
2 *******************************************************************************
3 * Copyright (C) 2015, International Business Machines Corporation
4 * and others. All Rights Reserved.
5 *******************************************************************************
8 * created on: 2015dec14
9 * created by: Markus W. Scherer
12 #include "unicode/utypes.h"
14 #if !UCONFIG_NO_FORMATTING
16 #include "unicode/unistr.h"
18 #include "standardplural.h"
23 static const char *gKeywords
[StandardPlural::COUNT
] = {
24 "zero", "one", "two", "few", "many", "other"
27 const char *StandardPlural::getKeyword(Form p
) {
28 U_ASSERT(ZERO
<= p
&& p
< COUNT
);
32 int32_t StandardPlural::indexOrNegativeFromString(const char *keyword
) {
35 if (uprv_strcmp(keyword
, "ew") == 0) {
40 if (uprv_strcmp(keyword
, "any") == 0) {
45 if (uprv_strcmp(keyword
, "ther") == 0) {
47 } else if (uprv_strcmp(keyword
, "ne") == 0) {
52 if (uprv_strcmp(keyword
, "wo") == 0) {
57 if (uprv_strcmp(keyword
, "ero") == 0) {
67 static const UChar gZero
[] = { 0x7A, 0x65, 0x72, 0x6F };
68 static const UChar gOne
[] = { 0x6F, 0x6E, 0x65 };
69 static const UChar gTwo
[] = { 0x74, 0x77, 0x6F };
70 static const UChar gFew
[] = { 0x66, 0x65, 0x77 };
71 static const UChar gMany
[] = { 0x6D, 0x61, 0x6E, 0x79 };
72 static const UChar gOther
[] = { 0x6F, 0x74, 0x68, 0x65, 0x72 };
74 int32_t StandardPlural::indexOrNegativeFromString(const UnicodeString
&keyword
) {
75 switch (keyword
.length()) {
77 if (keyword
.compare(gOne
, 3) == 0) {
79 } else if (keyword
.compare(gTwo
, 3) == 0) {
81 } else if (keyword
.compare(gFew
, 3) == 0) {
86 if (keyword
.compare(gMany
, 4) == 0) {
88 } else if (keyword
.compare(gZero
, 4) == 0) {
93 if (keyword
.compare(gOther
, 5) == 0) {
103 int32_t StandardPlural::indexFromString(const char *keyword
, UErrorCode
&errorCode
) {
104 if (U_FAILURE(errorCode
)) { return OTHER
; }
105 int32_t i
= indexOrNegativeFromString(keyword
);
109 errorCode
= U_ILLEGAL_ARGUMENT_ERROR
;
114 int32_t StandardPlural::indexFromString(const UnicodeString
&keyword
, UErrorCode
&errorCode
) {
115 if (U_FAILURE(errorCode
)) { return OTHER
; }
116 int32_t i
= indexOrNegativeFromString(keyword
);
120 errorCode
= U_ILLEGAL_ARGUMENT_ERROR
;
127 #endif // !UCONFIG_NO_FORMATTING