Line data Source code
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
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 :
18 : U_NAMESPACE_BEGIN
19 :
20 : UBool
21 0 : PluralAffix::setVariant(
22 : const char *variant, const UnicodeString &value, UErrorCode &status) {
23 0 : DigitAffix *current = affixes.getMutable(variant, status);
24 0 : if (U_FAILURE(status)) {
25 0 : return FALSE;
26 : }
27 0 : current->remove();
28 0 : current->append(value);
29 0 : return TRUE;
30 : }
31 :
32 : void
33 0 : PluralAffix::remove() {
34 0 : affixes.clear();
35 0 : }
36 :
37 : void
38 0 : PluralAffix::appendUChar(
39 : const UChar value, int32_t fieldId) {
40 0 : PluralMapBase::Category index = PluralMapBase::NONE;
41 0 : for (DigitAffix *current = affixes.nextMutable(index);
42 0 : current != NULL; current = affixes.nextMutable(index)) {
43 0 : current->appendUChar(value, fieldId);
44 : }
45 0 : }
46 :
47 : void
48 0 : PluralAffix::append(
49 : const UnicodeString &value, int32_t fieldId) {
50 0 : PluralMapBase::Category index = PluralMapBase::NONE;
51 0 : for (DigitAffix *current = affixes.nextMutable(index);
52 0 : current != NULL; current = affixes.nextMutable(index)) {
53 0 : current->append(value, fieldId);
54 : }
55 0 : }
56 :
57 : void
58 0 : PluralAffix::append(
59 : const UChar *value, int32_t charCount, int32_t fieldId) {
60 0 : PluralMapBase::Category index = PluralMapBase::NONE;
61 0 : for (DigitAffix *current = affixes.nextMutable(index);
62 0 : current != NULL; current = affixes.nextMutable(index)) {
63 0 : current->append(value, charCount, fieldId);
64 : }
65 0 : }
66 :
67 : UBool
68 0 : PluralAffix::append(
69 : const PluralAffix &rhs, int32_t fieldId, UErrorCode &status) {
70 0 : if (U_FAILURE(status)) {
71 0 : return FALSE;
72 : }
73 0 : PluralMapBase::Category index = PluralMapBase::NONE;
74 0 : while(rhs.affixes.next(index) != NULL) {
75 0 : affixes.getMutableWithDefault(index, affixes.getOther(), status);
76 : }
77 0 : index = PluralMapBase::NONE;
78 0 : for (DigitAffix *current = affixes.nextMutable(index);
79 0 : current != NULL; current = affixes.nextMutable(index)) {
80 0 : current->append(rhs.affixes.get(index).toString(), fieldId);
81 : }
82 0 : return TRUE;
83 : }
84 :
85 : const DigitAffix &
86 0 : PluralAffix::getByCategory(const char *category) const {
87 0 : return affixes.get(category);
88 : }
89 :
90 : const DigitAffix &
91 0 : PluralAffix::getByCategory(const UnicodeString &category) const {
92 0 : return affixes.get(category);
93 : }
94 :
95 : UBool
96 0 : PluralAffix::hasMultipleVariants() const {
97 : // This works because OTHER is guaranteed to be the first enum value
98 0 : PluralMapBase::Category index = PluralMapBase::OTHER;
99 0 : return (affixes.next(index) != NULL);
100 : }
101 :
102 : U_NAMESPACE_END
103 :
104 : #endif /* #if !UCONFIG_NO_FORMATTING */
|