@@ -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// ----------------------------
305308static 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));
0 commit comments