]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/pluralaffix.cpp
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / pluralaffix.cpp
CommitLineData
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
16U_NAMESPACE_BEGIN
17
18UBool
19PluralAffix::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
30void
31PluralAffix::remove() {
32 affixes.clear();
33}
34
35void
36PluralAffix::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
45void
46PluralAffix::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
55void
56PluralAffix::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
65UBool
66PluralAffix::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
83const DigitAffix &
84PluralAffix::getByCategory(const char *category) const {
85 return affixes.get(category);
86}
87
88const DigitAffix &
89PluralAffix::getByCategory(const UnicodeString &category) const {
90 return affixes.get(category);
91}
92
93UBool
94PluralAffix::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
100U_NAMESPACE_END
101
102#endif /* #if !UCONFIG_NO_FORMATTING */