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