]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/pluralmap.cpp
ICU-57166.0.1.tar.gz
[apple/icu.git] / icuSources / common / pluralmap.cpp
CommitLineData
2ca993e8
A
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
11U_NAMESPACE_BEGIN
12
13static const char * const gPluralForms[] = {
14 "other", "zero", "one", "two", "few", "many"};
15
16PluralMapBase::Category
17PluralMapBase::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
26PluralMapBase::Category
27PluralMapBase::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
34const 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
41U_NAMESPACE_END
42