]>
Commit | Line | Data |
---|---|---|
2ca993e8 A |
1 | /* |
2 | * Copyright (C) 2015, International Business Machines | |
3 | * Corporation and others. All Rights Reserved. | |
4 | * | |
5 | * file name: pluralaffix.cpp | |
6 | */ | |
7 | ||
8 | #include "unicode/utypes.h" | |
9 | ||
10 | #if !UCONFIG_NO_FORMATTING | |
11 | ||
12 | #include "cstring.h" | |
13 | #include "digitaffix.h" | |
14 | #include "pluralaffix.h" | |
15 | ||
16 | U_NAMESPACE_BEGIN | |
17 | ||
18 | UBool | |
19 | PluralAffix::setVariant( | |
20 | const char *variant, const UnicodeString &value, UErrorCode &status) { | |
21 | DigitAffix *current = affixes.getMutable(variant, status); | |
22 | if (U_FAILURE(status)) { | |
23 | return FALSE; | |
24 | } | |
25 | current->remove(); | |
26 | current->append(value); | |
27 | return TRUE; | |
28 | } | |
29 | ||
30 | void | |
31 | PluralAffix::remove() { | |
32 | affixes.clear(); | |
33 | } | |
34 | ||
35 | void | |
36 | PluralAffix::appendUChar( | |
37 | const UChar value, int32_t fieldId) { | |
38 | PluralMapBase::Category index = PluralMapBase::NONE; | |
39 | for (DigitAffix *current = affixes.nextMutable(index); | |
40 | current != NULL; current = affixes.nextMutable(index)) { | |
41 | current->appendUChar(value, fieldId); | |
42 | } | |
43 | } | |
44 | ||
45 | void | |
46 | PluralAffix::append( | |
47 | const UnicodeString &value, int32_t fieldId) { | |
48 | PluralMapBase::Category index = PluralMapBase::NONE; | |
49 | for (DigitAffix *current = affixes.nextMutable(index); | |
50 | current != NULL; current = affixes.nextMutable(index)) { | |
51 | current->append(value, fieldId); | |
52 | } | |
53 | } | |
54 | ||
55 | void | |
56 | PluralAffix::append( | |
57 | const UChar *value, int32_t charCount, int32_t fieldId) { | |
58 | PluralMapBase::Category index = PluralMapBase::NONE; | |
59 | for (DigitAffix *current = affixes.nextMutable(index); | |
60 | current != NULL; current = affixes.nextMutable(index)) { | |
61 | current->append(value, charCount, fieldId); | |
62 | } | |
63 | } | |
64 | ||
65 | UBool | |
66 | PluralAffix::append( | |
67 | const PluralAffix &rhs, int32_t fieldId, UErrorCode &status) { | |
68 | if (U_FAILURE(status)) { | |
69 | return FALSE; | |
70 | } | |
71 | PluralMapBase::Category index = PluralMapBase::NONE; | |
72 | while(rhs.affixes.next(index) != NULL) { | |
73 | affixes.getMutableWithDefault(index, affixes.getOther(), status); | |
74 | } | |
75 | index = PluralMapBase::NONE; | |
76 | for (DigitAffix *current = affixes.nextMutable(index); | |
77 | current != NULL; current = affixes.nextMutable(index)) { | |
78 | current->append(rhs.affixes.get(index).toString(), fieldId); | |
79 | } | |
80 | return TRUE; | |
81 | } | |
82 | ||
83 | const DigitAffix & | |
84 | PluralAffix::getByCategory(const char *category) const { | |
85 | return affixes.get(category); | |
86 | } | |
87 | ||
88 | const DigitAffix & | |
89 | PluralAffix::getByCategory(const UnicodeString &category) const { | |
90 | return affixes.get(category); | |
91 | } | |
92 | ||
93 | UBool | |
94 | PluralAffix::hasMultipleVariants() const { | |
95 | // This works because OTHER is guaranteed to be the first enum value | |
96 | PluralMapBase::Category index = PluralMapBase::OTHER; | |
97 | return (affixes.next(index) != NULL); | |
98 | } | |
99 | ||
100 | U_NAMESPACE_END | |
101 | ||
102 | #endif /* #if !UCONFIG_NO_FORMATTING */ |