Skip to content

Commit 7e421d4

Browse files
committed
Move definition of UMFErrorHandlingBehavior out of MessageFormatter::Builder into MessageFormatter
1 parent 8de960f commit 7e421d4

File tree

4 files changed

+36
-34
lines changed

4 files changed

+36
-34
lines changed

icu4c/source/i18n/messageformat2_formatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace message2 {
8383

8484
MessageFormatter::Builder&
8585
MessageFormatter::Builder::setErrorHandlingBehavior(
86-
MessageFormatter::Builder::UMFErrorHandlingBehavior type) {
86+
MessageFormatter::UMFErrorHandlingBehavior type) {
8787
switch (type) {
8888
case U_MF_STRICT: {
8989
signalErrors = true;

icu4c/source/i18n/unicode/messageformat2.h

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,31 @@ namespace message2 {
139139
*/
140140
const MFDataModel& getDataModel() const;
141141

142+
/**
143+
* Used in conjunction with the
144+
* MessageFormatter::Builder::`setErrorHandlingBehavior()` method.
145+
*
146+
* @internal ICU 76 technology preview
147+
* @deprecated This API is for technology preview only.
148+
*/
149+
typedef enum UMFErrorHandlingBehavior {
150+
/**
151+
* Suppress errors and return best-effort output.
152+
*
153+
* @internal ICU 76 technology preview
154+
* @deprecated This API is for technology preview only.
155+
*/
156+
U_MF_BEST_EFFORT = 0,
157+
/**
158+
* Signal all MessageFormat errors using the UErrorCode
159+
* argument.
160+
*
161+
* @internal ICU 76 technology preview
162+
* @deprecated This API is for technology preview only.
163+
*/
164+
U_MF_STRICT
165+
} UMFErrorHandlingBehavior;
166+
142167
/**
143168
* The mutable Builder class allows each part of the MessageFormatter to be initialized
144169
* separately; calling its `build()` method yields an immutable MessageFormatter.
@@ -171,29 +196,6 @@ namespace message2 {
171196

172197
void clearState();
173198
public:
174-
/**
175-
* Used in conjunction with the `setErrorHandlingBehavior()` method.
176-
*
177-
* @internal ICU 76 technology preview
178-
* @deprecated This API is for technology preview only.
179-
*/
180-
typedef enum UMFErrorHandlingBehavior {
181-
/**
182-
* Suppress errors and return best-effort output.
183-
*
184-
* @internal ICU 76 technology preview
185-
* @deprecated This API is for technology preview only.
186-
*/
187-
U_MF_BEST_EFFORT = 0,
188-
/**
189-
* Signal all MessageFormat errors using the UErrorCode
190-
* argument.
191-
*
192-
* @internal ICU 76 technology preview
193-
* @deprecated This API is for technology preview only.
194-
*/
195-
U_MF_STRICT
196-
} UMFErrorHandlingBehavior;
197199
/**
198200
* Sets the locale to use for formatting.
199201
*

icu4c/source/test/intltest/messageformat2test.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,21 @@ void TestMessageFormat2::testFormatterAPI() {
7575
// if there's a syntax error
7676
UnicodeString pattern = "{{}";
7777
MessageFormatter::Builder mfBuilder(errorCode);
78-
mfBuilder.setErrorHandlingBehavior(MessageFormatter::Builder::U_MF_BEST_EFFORT); // This shouldn't matter, since there's a syntax error
78+
mfBuilder.setErrorHandlingBehavior(MessageFormatter::U_MF_BEST_EFFORT); // This shouldn't matter, since there's a syntax error
7979
mfBuilder.setPattern(pattern, parseError, errorCode);
8080
MessageFormatter mf = mfBuilder.build(errorCode);
8181
U_ASSERT(errorCode == U_MF_SYNTAX_ERROR);
8282

8383
/*
8484
Parsing is done when setPattern() is called,
85-
so setErrorHandlingBehavior(MessageFormatter::Builder::U_MF_STRICT) or setSuppressErrors must be called
85+
so setErrorHandlingBehavior(MessageFormatter::U_MF_STRICT) or setSuppressErrors must be called
8686
_before_ setPattern() to get the right behavior,
8787
and if either method is called after setting a pattern,
8888
setPattern() has to be called again.
8989
*/
9090
// Should get the same behavior with strict errors
9191
errorCode.reset();
92-
mfBuilder.setErrorHandlingBehavior(MessageFormatter::Builder::U_MF_STRICT);
92+
mfBuilder.setErrorHandlingBehavior(MessageFormatter::U_MF_STRICT);
9393
// Force re-parsing, as above comment
9494
mfBuilder.setPattern(pattern, parseError, errorCode);
9595
mf = mfBuilder.build(errorCode);
@@ -99,7 +99,7 @@ void TestMessageFormat2::testFormatterAPI() {
9999
pattern = "{{{$x}}}";
100100
errorCode.reset();
101101
// Check that a pattern with a resolution error gives fallback output
102-
mfBuilder.setErrorHandlingBehavior(MessageFormatter::Builder::U_MF_BEST_EFFORT);
102+
mfBuilder.setErrorHandlingBehavior(MessageFormatter::U_MF_BEST_EFFORT);
103103
mfBuilder.setPattern(pattern, parseError, errorCode);
104104
mf = mfBuilder.build(errorCode);
105105
U_ASSERT(U_SUCCESS(errorCode));
@@ -108,7 +108,7 @@ void TestMessageFormat2::testFormatterAPI() {
108108
U_ASSERT(result == "{$x}");
109109

110110
// Check that we do get an error with strict errors
111-
mfBuilder.setErrorHandlingBehavior(MessageFormatter::Builder::U_MF_STRICT);
111+
mfBuilder.setErrorHandlingBehavior(MessageFormatter::U_MF_STRICT);
112112
mf = mfBuilder.build(errorCode);
113113
U_ASSERT(U_SUCCESS(errorCode));
114114
result = mf.formatToString(MessageArguments(), errorCode);
@@ -118,15 +118,15 @@ void TestMessageFormat2::testFormatterAPI() {
118118
errorCode.reset();
119119
pattern = "hello";
120120
mfBuilder.setPattern(pattern, parseError, errorCode);
121-
mfBuilder.setErrorHandlingBehavior(MessageFormatter::Builder::U_MF_BEST_EFFORT);
121+
mfBuilder.setErrorHandlingBehavior(MessageFormatter::U_MF_BEST_EFFORT);
122122
mf = mfBuilder.build(errorCode);
123123
U_ASSERT(U_SUCCESS(errorCode));
124124
result = mf.formatToString(MessageArguments(), errorCode);
125125
U_ASSERT(U_SUCCESS(errorCode));
126126
U_ASSERT(result == "hello");
127127

128128
// Check that behavior is the same with strict errors
129-
mfBuilder.setErrorHandlingBehavior(MessageFormatter::Builder::U_MF_STRICT);
129+
mfBuilder.setErrorHandlingBehavior(MessageFormatter::U_MF_STRICT);
130130
mf = mfBuilder.build(errorCode);
131131
U_ASSERT(U_SUCCESS(errorCode));
132132
result = mf.formatToString(MessageArguments(), errorCode);
@@ -286,7 +286,7 @@ void TestMessageFormat2::testAPICustomFunctions() {
286286
MessageFormatter::Builder mfBuilder(errorCode);
287287
UnicodeString result;
288288
// This fails, because we did not provide a function registry:
289-
MessageFormatter mf = mfBuilder.setErrorHandlingBehavior(MessageFormatter::Builder::U_MF_STRICT)
289+
MessageFormatter mf = mfBuilder.setErrorHandlingBehavior(MessageFormatter::U_MF_STRICT)
290290
.setPattern("Hello {$name :person formality=informal}",
291291
parseError, errorCode)
292292
.setLocale(locale)

icu4c/source/test/intltest/messageformat2test_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class TestUtils {
230230
}
231231
// Initially, set error behavior to strict.
232232
// We'll re-run to check for errors.
233-
mfBuilder.setErrorHandlingBehavior(MessageFormatter::Builder::U_MF_STRICT);
233+
mfBuilder.setErrorHandlingBehavior(MessageFormatter::U_MF_STRICT);
234234
MessageFormatter mf = mfBuilder.build(errorCode);
235235
UnicodeString result;
236236

@@ -279,7 +279,7 @@ class TestUtils {
279279
// Re-run the formatter if there was an error,
280280
// in order to get best-effort output
281281
errorCode.reset();
282-
mfBuilder.setErrorHandlingBehavior(MessageFormatter::Builder::U_MF_BEST_EFFORT);
282+
mfBuilder.setErrorHandlingBehavior(MessageFormatter::U_MF_BEST_EFFORT);
283283
mf = mfBuilder.build(errorCode);
284284
if (U_SUCCESS(errorCode)) {
285285
result = mf.formatToString(MessageArguments(testCase.getArguments(), errorCode), errorCode);

0 commit comments

Comments
 (0)