| 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 |
#if !UCONFIG_NO_NORMALIZATION |
| 7 |
|
| 8 |
#if !UCONFIG_NO_FORMATTING |
| 9 |
|
| 10 |
#if !UCONFIG_NO_MF2 |
| 11 |
|
| 12 |
#include "unicode/messageformat2.h" |
| 13 |
#include "unicode/messageformat2_arguments.h" |
| 14 |
#include "unicode/messageformat2_data_model_names.h" |
| 15 |
#include "messageformat2_evaluation.h" |
| 16 |
#include "uvector.h" // U_ASSERT |
| 17 |
|
| 18 |
U_NAMESPACE_BEGIN |
| 19 |
|
| 20 |
namespace message2 { |
| 21 |
|
| 22 |
using namespace data_model; |
| 23 |
|
| 24 |
// ------------------------------------------------------ |
| 25 |
// MessageArguments |
| 26 |
|
| 27 |
using Arguments = MessageArguments; |
| 28 |
|
| 29 |
const Formattable* Arguments::getArgument(const MessageFormatter& context, |
| 30 |
const VariableName& arg, |
| 31 |
UErrorCode& errorCode) const { |
| 32 |
if (U_SUCCESS(errorCode)) { |
| 33 |
U_ASSERT(argsLen == 0 || arguments.isValid()); |
| 34 |
for (int32_t i = 0; i < argsLen; i++) { |
| 35 |
UnicodeString normalized = context.normalizeNFC(argumentNames[i]); |
| 36 |
// arg already assumed to be normalized |
| 37 |
if (normalized == arg) { |
| 38 |
return &arguments[i]; |
| 39 |
} |
| 40 |
} |
| 41 |
errorCode = U_ILLEGAL_ARGUMENT_ERROR; |
| 42 |
} |
| 43 |
return nullptr; |
| 44 |
} |
| 45 |
|
| 46 |
MessageArguments::~MessageArguments() {} |
| 47 |
|
| 48 |
// Message arguments |
| 49 |
// ----------------- |
| 50 |
|
| 51 |
MessageArguments& MessageArguments::operator=(MessageArguments&& other) noexcept { |
| 52 |
U_ASSERT(other.arguments.isValid() || other.argsLen == 0); |
| 53 |
argsLen = other.argsLen; |
| 54 |
if (argsLen != 0) { |
| 55 |
argumentNames.adoptInstead(other.argumentNames.orphan()); |
| 56 |
arguments.adoptInstead(other.arguments.orphan()); |
| 57 |
} |
| 58 |
return *this; |
| 59 |
} |
| 60 |
|
| 61 |
} // namespace message2 |
| 62 |
|
| 63 |
U_NAMESPACE_END |
| 64 |
|
| 65 |
#endif /* #if !UCONFIG_NO_MF2 */ |
| 66 |
|
| 67 |
#endif /* #if !UCONFIG_NO_FORMATTING */ |
| 68 |
|
| 69 |
#endif /* #if !UCONFIG_NO_NORMALIZATION */ |