1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 
4 // This file is in common instead of i18n because it is needed by ucurr.cpp.
5 
6 #include "unicode/utypes.h"
7 
8 #if !UCONFIG_NO_FORMATTING
9 #ifndef __STATIC_UNICODE_SETS_H__
10 #define __STATIC_UNICODE_SETS_H__
11 
12 #include "unicode/uniset.h"
13 #include "unicode/unistr.h"
14 
15 U_NAMESPACE_BEGIN
16 namespace unisets {
17 
18 enum Key {
19     // NONE is used to indicate null in chooseFrom().
20     // EMPTY is used to get an empty UnicodeSet.
21     NONE = -1,
22     EMPTY = 0,
23 
24     // Ignorables
25     DEFAULT_IGNORABLES,
26     STRICT_IGNORABLES,
27 
28     // Separators
29     // Notes:
30     // - COMMA is a superset of STRICT_COMMA
31     // - PERIOD is a superset of SCRICT_PERIOD
32     // - ALL_SEPARATORS is the union of COMMA, PERIOD, and OTHER_GROUPING_SEPARATORS
33     // - STRICT_ALL_SEPARATORS is the union of STRICT_COMMA, STRICT_PERIOD, and OTHER_GRP_SEPARATORS
34     COMMA,
35     PERIOD,
36     STRICT_COMMA,
37     STRICT_PERIOD,
38     OTHER_GROUPING_SEPARATORS,
39     ALL_SEPARATORS,
40     STRICT_ALL_SEPARATORS,
41 
42     // Symbols
43     MINUS_SIGN,
44     PLUS_SIGN,
45     PERCENT_SIGN,
46     PERMILLE_SIGN,
47     INFINITY_KEY, // INFINITY is defined in cmath
48 
49     // Currency Symbols
50     DOLLAR_SIGN,
51     POUND_SIGN,
52     RUPEE_SIGN,
53     YEN_SIGN, // not in CLDR data, but Currency.java wants it
54 
55     // Other
56     DIGITS,
57 
58     // Combined Separators with Digits (for lead code points)
59     DIGITS_OR_ALL_SEPARATORS,
60     DIGITS_OR_STRICT_ALL_SEPARATORS,
61 
62     // The number of elements in the enum.
63     COUNT
64 };
65 
66 /**
67  * Gets the static-allocated UnicodeSet according to the provided key. The
68  * pointer will be deleted during u_cleanup(); the caller should NOT delete it.
69  *
70  * Exported as U_COMMON_API for ucurr.cpp
71  *
72  * @param key The desired UnicodeSet according to the enum in this file.
73  * @return The requested UnicodeSet. Guaranteed to be frozen and non-null, but
74  *         may be empty if an error occurred during data loading.
75  */
76 U_COMMON_API const UnicodeSet* get(Key key);
77 
78 /**
79  * Checks if the UnicodeSet given by key1 contains the given string.
80  *
81  * Exported as U_COMMON_API for numparse_decimal.cpp
82  *
83  * @param str The string to check.
84  * @param key1 The set to check.
85  * @return key1 if the set contains str, or NONE if not.
86  */
87 U_COMMON_API Key chooseFrom(UnicodeString str, Key key1);
88 
89 /**
90  * Checks if the UnicodeSet given by either key1 or key2 contains the string.
91  *
92  * Exported as U_COMMON_API for numparse_decimal.cpp
93  *
94  * @param str The string to check.
95  * @param key1 The first set to check.
96  * @param key2 The second set to check.
97  * @return key1 if that set contains str; key2 if that set contains str; or
98  *         NONE if neither set contains str.
99  */
100 U_COMMON_API Key chooseFrom(UnicodeString str, Key key1, Key key2);
101 
102 // Unused in C++:
103 // Key chooseCurrency(UnicodeString str);
104 // Used instead:
105 static const struct {
106     Key key;
107     UChar32 exemplar;
108 } kCurrencyEntries[] = {
109     {DOLLAR_SIGN, u'$'},
110     {POUND_SIGN, u'£'},
111     {RUPEE_SIGN, u'₨'},
112     {YEN_SIGN, u'¥'},
113 };
114 
115 } // namespace unisets
116 U_NAMESPACE_END
117 
118 #endif //__STATIC_UNICODE_SETS_H__
119 #endif /* #if !UCONFIG_NO_FORMATTING */
120