diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /intl/icu/source/i18n/measure.cpp | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'intl/icu/source/i18n/measure.cpp')
-rw-r--r-- | intl/icu/source/i18n/measure.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/intl/icu/source/i18n/measure.cpp b/intl/icu/source/i18n/measure.cpp new file mode 100644 index 0000000000..bffa44215e --- /dev/null +++ b/intl/icu/source/i18n/measure.cpp @@ -0,0 +1,74 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html +/* +********************************************************************** +* Copyright (c) 2004-2014, International Business Machines +* Corporation and others. All Rights Reserved. +********************************************************************** +* Author: Alan Liu +* Created: April 26, 2004 +* Since: ICU 3.0 +********************************************************************** +*/ +#include "utypeinfo.h" // for 'typeid' to work + +#include "unicode/utypes.h" + +#if !UCONFIG_NO_FORMATTING + +#include "unicode/measure.h" +#include "unicode/measunit.h" + +U_NAMESPACE_BEGIN + +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Measure) + +Measure::Measure() {} + +Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit, + UErrorCode& ec) : + number(_number), unit(adoptedUnit) { + if (U_SUCCESS(ec) && + (!number.isNumeric() || adoptedUnit == 0)) { + ec = U_ILLEGAL_ARGUMENT_ERROR; + } +} + +Measure::Measure(const Measure& other) : + UObject(other), unit(0) { + *this = other; +} + +Measure& Measure::operator=(const Measure& other) { + if (this != &other) { + delete unit; + number = other.number; + unit = other.unit->clone(); + } + return *this; +} + +Measure *Measure::clone() const { + return new Measure(*this); +} + +Measure::~Measure() { + delete unit; +} + +UBool Measure::operator==(const UObject& other) const { + if (this == &other) { // Same object, equal + return TRUE; + } + if (typeid(*this) != typeid(other)) { // Different types, not equal + return FALSE; + } + const Measure &m = static_cast<const Measure&>(other); + return number == m.number && + ((unit == NULL) == (m.unit == NULL)) && + (unit == NULL || *unit == *m.unit); +} + +U_NAMESPACE_END + +#endif // !UCONFIG_NO_FORMATTING |