Skip to content

Commit 577c25c

Browse files
committed
Cleanup
1 parent 267de90 commit 577c25c

File tree

4 files changed

+19
-31
lines changed

4 files changed

+19
-31
lines changed

icu4c/source/i18n/messageformat2.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,11 @@ static UnicodeString reserialize(const UnicodeString& s) {
165165
} else {
166166
U_ASSERT(result.isEvaluated());
167167

168-
// Need to create a new InternalValue such that the inner
169-
// FunctionValue does _not_ return true for wasSetFromLiteral()
168+
// The FunctionValue representing the right-hand side of this declaration
169+
// might have a wasSetFromLiteral() method that returns true (i.e. if it's a BaseValue);
170+
// But that value is being assigned to a variable here, so we need to
171+
// ensure that wasSetFromLiteral() returns false.
172+
// We accomplish this by wrapping it in a VariableValue.
170173
const FunctionValue* inner = result.getValue(status);
171174
U_ASSERT(U_SUCCESS(status)); // Already checked that result is evaluated
172175
LocalPointer<FunctionValue> variableValue(static_cast<FunctionValue*>(VariableValue::create(inner, status)));
@@ -303,13 +306,13 @@ static UnicodeString reserialize(const UnicodeString& s) {
303306
// Function options and context
304307
// ----------------------------
305308
static UMFBidiOption getBidiOption(const UnicodeString& s) {
306-
if (s == u"ltr") {
309+
if (s == options::LTR) {
307310
return U_MF_BIDI_OPTION_LTR;
308311
}
309-
if (s == u"rtl") {
312+
if (s == options::RTL) {
310313
return U_MF_BIDI_OPTION_RTL;
311314
}
312-
if (s == u"auto") {
315+
if (s == options::AUTO) {
313316
return U_MF_BIDI_OPTION_AUTO;
314317
}
315318
return U_MF_BIDI_OPTION_INHERIT; // inherit is default
@@ -541,17 +544,19 @@ void MessageFormatter::formatPattern(MessageContext& context,
541544
result += partVal.asFallback();
542545
result += RIGHT_CURLY_BRACE;
543546
} else {
544-
// Do final formatting (e.g. formatting numbers as strings)
547+
// Get the `FunctionValue` corresponding to this part
545548
const FunctionValue* val = partVal.getValue(status);
546-
// Shouldn't be null or a fallback
549+
// It shouldn't be null or a fallback
547550
U_ASSERT(U_SUCCESS(status));
548551

549552
// See comment in matchSelectorKeys()
550553
bool badSelectOption = !checkSelectOption(*val);
554+
555+
// Format the `FunctionValue` to a string
551556
UnicodeString fmt = val->formatToString(status);
552557

558+
// Apply bidi isolation to the formatted result
553559
UMFDirectionality dir = val->getDirection();
554-
555560
result += bidiIsolate(val->getDirectionAnnotation(), dir, fmt);
556561

557562
if (badSelectOption) {
@@ -675,12 +680,6 @@ void MessageFormatter::matchSelectorKeys(const UVector& keys,
675680
const FunctionValue* rvVal = rv.getValue(status);
676681

677682
// This condition can't be checked in the selector.
678-
// Effectively, there are two different kinds of "bad option" errors:
679-
// one that can be recovered from (used for select=$var) and one that
680-
// can't (used for bad digit size options and other cases).
681-
// The checking of the recoverable error has to be done here; otherwise,
682-
// the "bad option" signaled by the selector implementation would cause
683-
// fallback output to be used when formatting the `*` pattern.
684683
bool badSelectOption = !checkSelectOption(*rvVal);
685684

686685
U_ASSERT(U_SUCCESS(status));

icu4c/source/i18n/messageformat2_evaluation.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ namespace message2 {
166166
UnicodeString formatToString(UErrorCode& status) const override { return underlyingValue->formatToString(status); }
167167
const Formattable& unwrap() const override { return underlyingValue->unwrap(); }
168168
const FunctionOptions& getResolvedOptions() const override { return underlyingValue->getResolvedOptions(); }
169-
const Locale& getLocale() const override { return underlyingValue->getLocale(); }
170169
UMFDirectionality getDirection() const override { return underlyingValue->getDirection(); }
171170
UMFBidiOption getDirectionAnnotation() const override { return underlyingValue->getDirectionAnnotation(); }
172171
UBool isSelectable() const override { return underlyingValue->isSelectable(); }

icu4c/source/i18n/messageformat2_function_registry.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,8 @@ MFFunctionRegistry::~MFFunctionRegistry() {
258258

259259
// Specific function implementations
260260

261-
// Strings and numbers have different behaviors here.
262-
// See https://github.com/unicode-org/message-format-wg/issues/970
263261
UMFDirectionality
264-
numberOutputDirectionalityFromUDir(UMFBidiOption uDir, const Locale& locale) {
262+
outputDirectionalityFromUDir(UMFBidiOption uDir, const Locale& locale) {
265263
switch (uDir) {
266264
case U_MF_BIDI_OPTION_LTR:
267265
return U_MF_DIRECTIONALITY_LTR;
@@ -741,7 +739,7 @@ StandardFunctions::NumberValue::NumberValue(const Number& parent,
741739
innerValue = arg.unwrap();
742740
functionName = UnicodeString(parent.isInteger ? "integer" : "number");
743741
inputDir = context.getDirection();
744-
dir = numberOutputDirectionalityFromUDir(inputDir, locale);
742+
dir = outputDirectionalityFromUDir(inputDir, locale);
745743

746744
number::LocalizedNumberFormatter realFormatter;
747745
realFormatter = formatterForOptions(parent, locale, opts, errorCode);
@@ -1079,7 +1077,7 @@ StandardFunctions::DateTimeValue::DateTimeValue(DateTime::DateTimeType type,
10791077
break;
10801078
}
10811079
inputDir = context.getDirection();
1082-
dir = numberOutputDirectionalityFromUDir(inputDir, locale);
1080+
dir = outputDirectionalityFromUDir(inputDir, locale);
10831081

10841082
const Formattable* source = &innerValue;
10851083

@@ -1466,6 +1464,7 @@ UnicodeString StandardFunctions::StringValue::formatToString(UErrorCode& errorCo
14661464
return formattedString;
14671465
}
14681466

1467+
/*
14691468
// Strings and numbers have different behaviors here.
14701469
// See https://github.com/unicode-org/message-format-wg/issues/970
14711470
UMFDirectionality stringOutputDirectionFromInput(UMFBidiOption inputDir) {
@@ -1481,6 +1480,7 @@ UMFDirectionality stringOutputDirectionFromInput(UMFBidiOption inputDir) {
14811480
14821481
return U_MF_DIRECTIONALITY_LTR;
14831482
}
1483+
*/
14841484

14851485
StandardFunctions::StringValue::StringValue(const FunctionContext& context,
14861486
const FunctionValue& val,
@@ -1491,7 +1491,7 @@ StandardFunctions::StringValue::StringValue(const FunctionContext& context,
14911491
innerValue = val.unwrap();
14921492
functionName = UnicodeString("string");
14931493
inputDir = context.getDirection();
1494-
dir = stringOutputDirectionFromInput(inputDir);
1494+
dir = outputDirectionalityFromUDir(inputDir, locale);
14951495
// No options
14961496
// Convert to string
14971497
formattedString = formattableToString(context.getLocale(), innerValue, status);

icu4c/source/i18n/unicode/messageformat2_function_registry.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,16 +441,6 @@ namespace message2 {
441441
* @deprecated This API is for technology preview only.
442442
*/
443443
virtual const FunctionOptions& getResolvedOptions() const { return opts; }
444-
/**
445-
* Returns the locale that this value was annotated with (or the default
446-
* locale for the formatter if there was no locale annotation.)
447-
*
448-
* @return The locale for this value.
449-
*
450-
* @internal ICU 78 technology preview
451-
* @deprecated This API is for technology preview only.
452-
*/
453-
virtual const Locale& getLocale() const { return locale; }
454444
/**
455445
* Returns the directionality of this value, i.e. the directionality
456446
* that its formatted result should have.

0 commit comments

Comments
 (0)