• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 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
setVariant(const char * variant,const UnicodeString & value,UErrorCode & status)21 PluralAffix::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 
32 void
remove()33 PluralAffix::remove() {
34     affixes.clear();
35 }
36 
37 void
appendUChar(const UChar value,int32_t fieldId)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);
44     }
45 }
46 
47 void
append(const UnicodeString & value,int32_t fieldId)48 PluralAffix::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 
57 void
append(const UChar * value,int32_t charCount,int32_t fieldId)58 PluralAffix::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 
67 UBool
append(const PluralAffix & rhs,int32_t fieldId,UErrorCode & status)68 PluralAffix::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 
85 const DigitAffix &
getByCategory(const char * category) const86 PluralAffix::getByCategory(const char *category) const {
87     return affixes.get(category);
88 }
89 
90 const DigitAffix &
getByCategory(const UnicodeString & category) const91 PluralAffix::getByCategory(const UnicodeString &category) const {
92     return affixes.get(category);
93 }
94 
95 UBool
hasMultipleVariants() const96 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);
100 }
101 
102 U_NAMESPACE_END
103 
104 #endif /* #if !UCONFIG_NO_FORMATTING */
105