]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/standardplural.cpp
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2015, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 *******************************************************************************
10 * created on: 2015dec14
11 * created by: Markus W. Scherer
14 #include "unicode/utypes.h"
16 #if !UCONFIG_NO_FORMATTING
18 #include "unicode/unistr.h"
20 #include "standardplural.h"
25 static const char *gKeywords
[StandardPlural::COUNT
] = {
26 "zero", "one", "two", "few", "many", "other"
29 const char *StandardPlural::getKeyword(Form p
) {
30 U_ASSERT(ZERO
<= p
&& p
< COUNT
);
34 int32_t StandardPlural::indexOrNegativeFromString(const char *keyword
) {
37 if (uprv_strcmp(keyword
, "ew") == 0) {
42 if (uprv_strcmp(keyword
, "any") == 0) {
47 if (uprv_strcmp(keyword
, "ther") == 0) {
49 } else if (uprv_strcmp(keyword
, "ne") == 0) {
54 if (uprv_strcmp(keyword
, "wo") == 0) {
59 if (uprv_strcmp(keyword
, "ero") == 0) {
69 static const UChar gZero
[] = { 0x7A, 0x65, 0x72, 0x6F };
70 static const UChar gOne
[] = { 0x6F, 0x6E, 0x65 };
71 static const UChar gTwo
[] = { 0x74, 0x77, 0x6F };
72 static const UChar gFew
[] = { 0x66, 0x65, 0x77 };
73 static const UChar gMany
[] = { 0x6D, 0x61, 0x6E, 0x79 };
74 static const UChar gOther
[] = { 0x6F, 0x74, 0x68, 0x65, 0x72 };
76 int32_t StandardPlural::indexOrNegativeFromString(const UnicodeString
&keyword
) {
77 switch (keyword
.length()) {
79 if (keyword
.compare(gOne
, 3) == 0) {
81 } else if (keyword
.compare(gTwo
, 3) == 0) {
83 } else if (keyword
.compare(gFew
, 3) == 0) {
88 if (keyword
.compare(gMany
, 4) == 0) {
90 } else if (keyword
.compare(gZero
, 4) == 0) {
95 if (keyword
.compare(gOther
, 5) == 0) {
105 int32_t StandardPlural::indexFromString(const char *keyword
, UErrorCode
&errorCode
) {
106 if (U_FAILURE(errorCode
)) { return OTHER
; }
107 int32_t i
= indexOrNegativeFromString(keyword
);
111 errorCode
= U_ILLEGAL_ARGUMENT_ERROR
;
116 int32_t StandardPlural::indexFromString(const UnicodeString
&keyword
, UErrorCode
&errorCode
) {
117 if (U_FAILURE(errorCode
)) { return OTHER
; }
118 int32_t i
= indexOrNegativeFromString(keyword
);
122 errorCode
= U_ILLEGAL_ARGUMENT_ERROR
;
129 #endif // !UCONFIG_NO_FORMATTING