1 | // © 2016 and later: Unicode, Inc. and others. |
---|---|
2 | // License & terms of use: http://www.unicode.org/copyright.html |
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 | |
13 | U_NAMESPACE_BEGIN |
14 | |
15 | static const char * const gPluralForms[] = { |
16 | "other", "zero", "one", "two", "few", "many"}; |
17 | |
18 | PluralMapBase::Category |
19 | PluralMapBase::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 | |
28 | PluralMapBase::Category |
29 | PluralMapBase::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 | |
36 | const 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 | |
43 | U_NAMESPACE_END |
44 | |
45 |