tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

messageformat2_arguments.cpp (1982B)


      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 "messageformat2_function_registry_internal.h"
     17 #include "uvector.h" // U_ASSERT
     18 
     19 U_NAMESPACE_BEGIN
     20 
     21 namespace message2 {
     22 
     23    using namespace data_model;
     24 
     25    // ------------------------------------------------------
     26    // MessageArguments
     27 
     28    using Arguments = MessageArguments;
     29 
     30    const Formattable* Arguments::getArgument(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 = StandardFunctions::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 */