Coverage Report

Created: 2025-10-24 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/icu/icu4c/source/i18n/displayoptions.cpp
Line
Count
Source
1
// © 2022 and later: Unicode, Inc. and others.
2
// License & terms of use: http://www.unicode.org/copyright.html
3
4
#include "unicode/utypes.h"
5
6
#if !UCONFIG_NO_FORMATTING
7
8
#include "unicode/displayoptions.h"
9
#include "unicode/udisplayoptions.h"
10
#include "cstring.h"
11
12
U_NAMESPACE_BEGIN
13
14
0
DisplayOptions::Builder DisplayOptions::builder() { return {}; }
15
16
0
DisplayOptions::Builder DisplayOptions::copyToBuilder() const { return Builder(*this); }
17
18
0
DisplayOptions::DisplayOptions(const Builder &builder) {
19
0
    grammaticalCase = builder.grammaticalCase;
20
0
    nounClass = builder.nounClass;
21
0
    pluralCategory = builder.pluralCategory;
22
0
    capitalization = builder.capitalization;
23
0
    nameStyle = builder.nameStyle;
24
0
    displayLength = builder.displayLength;
25
0
    substituteHandling = builder.substituteHandling;
26
0
}
27
28
0
DisplayOptions::Builder::Builder() {
29
    // Sets default values.
30
0
    grammaticalCase = UDISPOPT_GRAMMATICAL_CASE_UNDEFINED;
31
0
    nounClass = UDISPOPT_NOUN_CLASS_UNDEFINED;
32
0
    pluralCategory = UDISPOPT_PLURAL_CATEGORY_UNDEFINED;
33
0
    capitalization = UDISPOPT_CAPITALIZATION_UNDEFINED;
34
0
    nameStyle = UDISPOPT_NAME_STYLE_UNDEFINED;
35
0
    displayLength = UDISPOPT_DISPLAY_LENGTH_UNDEFINED;
36
0
    substituteHandling = UDISPOPT_SUBSTITUTE_HANDLING_UNDEFINED;
37
0
}
38
39
0
DisplayOptions::Builder::Builder(const DisplayOptions &displayOptions) {
40
0
    grammaticalCase = displayOptions.grammaticalCase;
41
0
    nounClass = displayOptions.nounClass;
42
0
    pluralCategory = displayOptions.pluralCategory;
43
0
    capitalization = displayOptions.capitalization;
44
0
    nameStyle = displayOptions.nameStyle;
45
0
    displayLength = displayOptions.displayLength;
46
0
    substituteHandling = displayOptions.substituteHandling;
47
0
}
48
49
U_NAMESPACE_END
50
51
// C API ------------------------------------------------------------------- ***
52
53
U_NAMESPACE_USE
54
55
namespace {
56
57
const char *grammaticalCaseIds[] = {
58
    "undefined",           // 0
59
    "ablative",            // 1
60
    "accusative",          // 2
61
    "comitative",          // 3
62
    "dative",              // 4
63
    "ergative",            // 5
64
    "genitive",            // 6
65
    "instrumental",        // 7
66
    "locative",            // 8
67
    "locative_copulative", // 9
68
    "nominative",          // 10
69
    "oblique",             // 11
70
    "prepositional",       // 12
71
    "sociative",           // 13
72
    "vocative",            // 14
73
};
74
75
} // namespace
76
77
U_CAPI const char * U_EXPORT2
78
0
udispopt_getGrammaticalCaseIdentifier(UDisplayOptionsGrammaticalCase grammaticalCase) {
79
0
    if (grammaticalCase >= 0 && grammaticalCase < UPRV_LENGTHOF(grammaticalCaseIds)) {
80
0
        return grammaticalCaseIds[grammaticalCase];
81
0
    }
82
83
0
    return grammaticalCaseIds[0];
84
0
}
85
86
U_CAPI UDisplayOptionsGrammaticalCase U_EXPORT2
87
0
udispopt_fromGrammaticalCaseIdentifier(const char *identifier) {
88
0
    for (int32_t i = 0; i < UPRV_LENGTHOF(grammaticalCaseIds); i++) {
89
0
        if (uprv_strcmp(identifier, grammaticalCaseIds[i]) == 0) {
90
0
            return static_cast<UDisplayOptionsGrammaticalCase>(i);
91
0
        }
92
0
    }
93
94
0
    return UDISPOPT_GRAMMATICAL_CASE_UNDEFINED;
95
0
}
96
97
namespace {
98
99
const char *pluralCategoryIds[] = {
100
    "undefined", // 0
101
    "zero",      // 1
102
    "one",       // 2
103
    "two",       // 3
104
    "few",       // 4
105
    "many",      // 5
106
    "other",     // 6
107
};
108
109
} // namespace
110
111
U_CAPI const char * U_EXPORT2
112
0
udispopt_getPluralCategoryIdentifier(UDisplayOptionsPluralCategory pluralCategory) {
113
0
    if (pluralCategory >= 0 && pluralCategory < UPRV_LENGTHOF(pluralCategoryIds)) {
114
0
        return pluralCategoryIds[pluralCategory];
115
0
    }
116
117
0
    return pluralCategoryIds[0];
118
0
}
119
120
U_CAPI UDisplayOptionsPluralCategory U_EXPORT2
121
0
udispopt_fromPluralCategoryIdentifier(const char *identifier) {
122
0
    for (int32_t i = 0; i < UPRV_LENGTHOF(pluralCategoryIds); i++) {
123
0
        if (uprv_strcmp(identifier, pluralCategoryIds[i]) == 0) {
124
0
            return static_cast<UDisplayOptionsPluralCategory>(i);
125
0
        }
126
0
    }
127
128
0
    return UDISPOPT_PLURAL_CATEGORY_UNDEFINED;
129
0
}
130
131
namespace {
132
133
const char *nounClassIds[] = {
134
    "undefined", // 0
135
    "other",     // 1
136
    "neuter",    // 2
137
    "feminine",  // 3
138
    "masculine", // 4
139
    "animate",   // 5
140
    "inanimate", // 6
141
    "personal",  // 7
142
    "common",    // 8
143
};
144
145
} // namespace
146
147
U_CAPI const char * U_EXPORT2
148
0
udispopt_getNounClassIdentifier(UDisplayOptionsNounClass nounClass) {
149
0
    if (nounClass >= 0 && nounClass < UPRV_LENGTHOF(nounClassIds)) {
150
0
        return nounClassIds[nounClass];
151
0
    }
152
153
0
    return nounClassIds[0];
154
0
}
155
156
U_CAPI UDisplayOptionsNounClass U_EXPORT2
157
0
udispopt_fromNounClassIdentifier(const char *identifier) {
158
0
    for (int32_t i = 0; i < UPRV_LENGTHOF(nounClassIds); i++) {
159
0
        if (uprv_strcmp(identifier, nounClassIds[i]) == 0) {
160
0
            return static_cast<UDisplayOptionsNounClass>(i);
161
0
        }
162
0
    }
163
164
0
    return UDISPOPT_NOUN_CLASS_UNDEFINED;
165
0
}
166
167
#endif /* #if !UCONFIG_NO_FORMATTING */