xref: /aosp_15_r20/external/icu/libicu/cts_headers/messageformat2_macros.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1 // © 2024 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 #ifndef U_HIDE_DEPRECATED_API
7 
8 #ifndef MESSAGEFORMAT2_MACROS_H
9 #define MESSAGEFORMAT2_MACROS_H
10 
11 #if U_SHOW_CPLUSPLUS_API
12 
13 #if !UCONFIG_NO_FORMATTING
14 
15 #if !UCONFIG_NO_MF2
16 
17 #include "unicode/format.h"
18 #include "unicode/unistr.h"
19 #include "plurrule_impl.h"
20 
21 U_NAMESPACE_BEGIN
22 
23 namespace message2 {
24 
25 using namespace pluralimpl;
26 
27 // Tokens for parser and serializer
28 
29 // Syntactically significant characters
30 #define LEFT_CURLY_BRACE ((UChar32)0x007B)
31 #define RIGHT_CURLY_BRACE ((UChar32)0x007D)
32 #define HTAB ((UChar32)0x0009)
33 #define CR ((UChar32)0x000D)
34 #define LF ((UChar32)0x000A)
35 #define IDEOGRAPHIC_SPACE ((UChar32)0x3000)
36 
37 #define PIPE ((UChar32)0x007C)
38 #define EQUALS ((UChar32)0x003D)
39 #define DOLLAR ((UChar32)0x0024)
40 #define COLON ((UChar32)0x003A)
41 #define PLUS ((UChar32)0x002B)
42 #define HYPHEN ((UChar32)0x002D)
43 #define PERIOD ((UChar32)0x002E)
44 #define UNDERSCORE ((UChar32)0x005F)
45 
46 #define LOWERCASE_E ((UChar32)0x0065)
47 #define UPPERCASE_E ((UChar32)0x0045)
48 
49 // Reserved sigils
50 #define BANG ((UChar32)0x0021)
51 #define AT ((UChar32)0x0040)
52 #define PERCENT ((UChar32)0x0025)
53 #define CARET ((UChar32)0x005E)
54 #define AMPERSAND ((UChar32)0x0026)
55 #define LESS_THAN ((UChar32)0x003C)
56 #define GREATER_THAN ((UChar32)0x003E)
57 #define QUESTION ((UChar32)0x003F)
58 #define TILDE ((UChar32)0x007E)
59 
60 // Fallback
61 #define REPLACEMENT ((UChar32) 0xFFFD)
62 
63 // MessageFormat2 uses four keywords: `.input`, `.local`, `.when`, and `.match`.
64 
65 static constexpr UChar32 ID_INPUT[] = {
66     0x2E, 0x69, 0x6E, 0x70, 0x75, 0x74, 0 /* ".input" */
67 };
68 
69 static constexpr UChar32 ID_LOCAL[] = {
70     0x2E, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0 /* ".local" */
71 };
72 
73 static constexpr UChar32 ID_MATCH[] = {
74     0x2E, 0x6D, 0x61, 0x74, 0x63, 0x68, 0 /* ".match" */
75 };
76 
77 // Returns immediately if `errorCode` indicates failure
78 #define CHECK_ERROR(errorCode)                                                                          \
79     if (U_FAILURE(errorCode)) {                                                                         \
80         return;                                                                                         \
81     }
82 
83 // Returns immediately if `errorCode` indicates failure
84 #define NULL_ON_ERROR(errorCode)                                                                          \
85     if (U_FAILURE(errorCode)) {                                                                         \
86         return nullptr;                                                                                         \
87     }
88 
89 // Returns immediately if `errorCode` indicates failure
90 #define THIS_ON_ERROR(errorCode)                                                                          \
91     if (U_FAILURE(errorCode)) {                                                                         \
92         return *this; \
93     }
94 
95 // Returns immediately if `errorCode` indicates failure
96 #define EMPTY_ON_ERROR(errorCode)                                                                          \
97     if (U_FAILURE(errorCode)) {                                                                         \
98         return {}; \
99     }
100 
101 } // namespace message2
102 U_NAMESPACE_END
103 
104 #endif /* #if !UCONFIG_NO_MF2 */
105 
106 #endif /* #if !UCONFIG_NO_FORMATTING */
107 
108 #endif /* U_SHOW_CPLUSPLUS_API */
109 
110 #endif // MESSAGEFORMAT2_MACROS_H
111 
112 #endif // U_HIDE_DEPRECATED_API
113 // eof
114