]> git.saurik.com Git - apple/icu.git/blob - icuSources/common/pluralmap.cpp
ICU-57163.0.1.tar.gz
[apple/icu.git] / icuSources / common / pluralmap.cpp
1 /*
2 * Copyright (C) 2015, International Business Machines Corporation and
3 * others. All Rights Reserved.
4 */
5
6 #include "unicode/unistr.h"
7 #include "charstr.h"
8 #include "cstring.h"
9 #include "pluralmap.h"
10
11 U_NAMESPACE_BEGIN
12
13 static const char * const gPluralForms[] = {
14 "other", "zero", "one", "two", "few", "many"};
15
16 PluralMapBase::Category
17 PluralMapBase::toCategory(const char *pluralForm) {
18 for (int32_t i = 0; i < UPRV_LENGTHOF(gPluralForms); ++i) {
19 if (uprv_strcmp(pluralForm, gPluralForms[i]) == 0) {
20 return static_cast<Category>(i);
21 }
22 }
23 return NONE;
24 }
25
26 PluralMapBase::Category
27 PluralMapBase::toCategory(const UnicodeString &pluralForm) {
28 CharString cCategory;
29 UErrorCode status = U_ZERO_ERROR;
30 cCategory.appendInvariantChars(pluralForm, status);
31 return U_FAILURE(status) ? NONE : toCategory(cCategory.data());
32 }
33
34 const char *PluralMapBase::getCategoryName(Category c) {
35 int32_t index = c;
36 return (index < 0 || index >= UPRV_LENGTHOF(gPluralForms)) ?
37 NULL : gPluralForms[index];
38 }
39
40
41 U_NAMESPACE_END
42