1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
// © 2024 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
#include "unicode/utypes.h"
#ifndef U_HIDE_DEPRECATED_API
#ifndef MESSAGEFORMAT2_ERRORS_H
#define MESSAGEFORMAT2_ERRORS_H
#if U_SHOW_CPLUSPLUS_API
/**
* \file
* \brief C++ API: Formats messages using the draft MessageFormat 2.0.
*/
#if !UCONFIG_NO_FORMATTING
#if !UCONFIG_NO_MF2
#include "unicode/messageformat2_data_model_names.h"
#include "unicode/unistr.h"
#include "uvector.h"
U_NAMESPACE_BEGIN
namespace message2 {
using namespace data_model;
// Errors
// ----------
class DynamicErrors;
class StaticErrors;
// Internal class -- used as a private field in MessageFormatter
template <typename ErrorType>
class Error : public UObject {
public:
Error(ErrorType ty) : type(ty) {}
Error(ErrorType ty, const UnicodeString& s) : type(ty), contents(s) {}
virtual ~Error();
private:
friend class DynamicErrors;
friend class StaticErrors;
ErrorType type;
UnicodeString contents;
}; // class Error
enum StaticErrorType {
DuplicateDeclarationError,
DuplicateOptionName,
DuplicateVariant,
MissingSelectorAnnotation,
NonexhaustivePattern,
SyntaxError,
VariantKeyMismatchError
};
enum DynamicErrorType {
UnresolvedVariable,
FormattingError,
OperandMismatchError,
SelectorError,
UnknownFunction,
};
using StaticError = Error<StaticErrorType>;
using DynamicError = Error<DynamicErrorType>;
// These explicit instantiations have to come before the
// destructor definitions
template<>
Error<StaticErrorType>::~Error();
template<>
Error<DynamicErrorType>::~Error();
class StaticErrors : public UObject {
private:
friend class DynamicErrors;
LocalPointer<UVector> syntaxAndDataModelErrors;
bool dataModelError = false;
bool missingSelectorAnnotationError = false;
bool syntaxError = false;
public:
StaticErrors(UErrorCode&);
void setMissingSelectorAnnotation(UErrorCode&);
void setDuplicateOptionName(UErrorCode&);
void addSyntaxError(UErrorCode&);
bool hasDataModelError() const { return dataModelError; }
bool hasSyntaxError() const { return syntaxError; }
bool hasMissingSelectorAnnotationError() const { return missingSelectorAnnotationError; }
void addError(StaticError&&, UErrorCode&);
void checkErrors(UErrorCode&) const;
void clear();
const StaticError& first() const;
StaticErrors(const StaticErrors&, UErrorCode&);
StaticErrors(StaticErrors&&) noexcept;
virtual ~StaticErrors();
}; // class StaticErrors
class DynamicErrors : public UObject {
private:
const StaticErrors& staticErrors;
LocalPointer<UVector> resolutionAndFormattingErrors;
bool formattingError = false;
bool selectorError = false;
bool unknownFunctionError = false;
bool unresolvedVariableError = false;
public:
DynamicErrors(const StaticErrors&, UErrorCode&);
int32_t count() const;
void setSelectorError(const FunctionName&, UErrorCode&);
void setUnresolvedVariable(const VariableName&, UErrorCode&);
void setUnknownFunction(const FunctionName&, UErrorCode&);
void setFormattingError(const FunctionName&, UErrorCode&);
// Used when the name of the offending formatter is unknown
void setFormattingError(UErrorCode&);
void setOperandMismatchError(const FunctionName&, UErrorCode&);
bool hasDataModelError() const { return staticErrors.hasDataModelError(); }
bool hasFormattingError() const { return formattingError; }
bool hasSelectorError() const { return selectorError; }
bool hasSyntaxError() const { return staticErrors.hasSyntaxError(); }
bool hasUnknownFunctionError() const { return unknownFunctionError; }
bool hasMissingSelectorAnnotationError() const { return staticErrors.hasMissingSelectorAnnotationError(); }
bool hasUnresolvedVariableError() const { return unresolvedVariableError; }
void addError(DynamicError&&, UErrorCode&);
void checkErrors(UErrorCode&) const;
bool hasError() const;
bool hasStaticError() const;
const DynamicError& first() const;
virtual ~DynamicErrors();
}; // class DynamicErrors
} // namespace message2
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_MF2 */
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // MESSAGEFORMAT2_ERRORS_H
#endif // U_HIDE_DEPRECATED_API
// eof
|