1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 * Copyright (C) 2015, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 * file name: pluralaffix.cpp
10 #include "unicode/utypes.h"
12 #if !UCONFIG_NO_FORMATTING
15 #include "digitaffix.h"
16 #include "pluralaffix.h"
21 PluralAffix::setVariant(
22 const char *variant, const UnicodeString &value, UErrorCode &status) {
23 DigitAffix *current = affixes.getMutable(variant, status);
24 if (U_FAILURE(status)) {
28 current->append(value);
33 PluralAffix::remove() {
38 PluralAffix::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);
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);
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);
69 const PluralAffix &rhs, int32_t fieldId, UErrorCode &status) {
70 if (U_FAILURE(status)) {
73 PluralMapBase::Category index = PluralMapBase::NONE;
74 while(rhs.affixes.next(index) != NULL) {
75 affixes.getMutableWithDefault(index, affixes.getOther(), status);
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);
86 PluralAffix::getByCategory(const char *category) const {
87 return affixes.get(category);
91 PluralAffix::getByCategory(const UnicodeString &category) const {
92 return affixes.get(category);
96 PluralAffix::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);
104 #endif /* #if !UCONFIG_NO_FORMATTING */