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