*
* WARNING: MaybeStackArray only works with primitive (plain-old data) types.
* It does NOT know how to call a destructor! If you work with classes with
- * destructors, consider LocalArray in localpointer.h or MemoryPool.
+ * destructors, consider:
+ *
+ * - LocalArray in localpointer.h if you know the length ahead of time
+ * - MaybeStackVector if you know the length at runtime
*/
template<typename T, int32_t stackCapacity>
class MaybeStackArray {
/**
* An internal Vector-like implementation based on MemoryPool.
*
+ * Heap-allocates each element and stores pointers.
+ *
* To append an item to the vector, use emplaceBack.
*
* MaybeStackVector<MyType> vector;
return this->fPool.getAlias();
}
+ /**
+ * Array item access (read-only).
+ * No index bounds check.
+ * @param i array index
+ * @return reference to the array item
+ */
+ const T* operator[](ptrdiff_t i) const {
+ return this->fPool[i];
+ }
+
/**
* Array item access (writable).
* No index bounds check.
* @param i array index
* @return reference to the array item
*/
- T* operator[](ptrdiff_t i) const {
+ T* operator[](ptrdiff_t i) {
return this->fPool[i];
}
#include "cstring.h"
#include "uinvchar.h"
#include "charstr.h"
-
-static constexpr char16_t kDefaultCurrency[] = u"XXX";
-static constexpr char kDefaultCurrency8[] = "XXX";
+#include "measunit_impl.h"
U_NAMESPACE_BEGIN
}
// malloc error: fall back to the undefined currency
result = binarySearch(
- gSubTypes, gOffsets[fTypeId], gOffsets[fTypeId + 1], "XXX");
+ gSubTypes, gOffsets[fTypeId], gOffsets[fTypeId + 1], kDefaultCurrency8);
U_ASSERT(result != -1);
}
fSubTypeId = result - gOffsets[fTypeId];
Type getType() const {
if (fMatch <= 0) {
UPRV_UNREACHABLE;
- } else if (fMatch < kCompoundPartOffset) {
+ }
+ if (fMatch < kCompoundPartOffset) {
return TYPE_SI_PREFIX;
- } else if (fMatch < kPowerPartOffset) {
+ }
+ if (fMatch < kPowerPartOffset) {
return TYPE_COMPOUND_PART;
- } else if (fMatch < kSimpleUnitOffset) {
+ }
+ if (fMatch < kSimpleUnitOffset) {
return TYPE_POWER_PART;
- } else if (fMatch == kSimpleUnitOffset) {
+ }
+ if (fMatch == kSimpleUnitOffset) {
return TYPE_ONE;
- } else {
- return TYPE_SIMPLE_UNIT;
}
+ return TYPE_SIMPLE_UNIT;
}
UMeasureSIPrefix getSIPrefix() const {
}
if (impl.units.length() == 0) {
return {};
- } else if (impl.units.length() == 1) {
+ }
+ if (impl.units.length() == 1) {
return *impl.units[0];
- } else {
- status = U_ILLEGAL_ARGUMENT_ERROR;
- return {};
}
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return {};
}
-MeasureUnit SingleUnitImpl::build(UErrorCode& status) {
+MeasureUnit SingleUnitImpl::build(UErrorCode& status) const {
MeasureUnitImpl temp;
temp.append(*this, status);
return std::move(temp).build(status);
U_NAMESPACE_BEGIN
+static const char16_t kDefaultCurrency[] = u"XXX";
+static const char kDefaultCurrency8[] = "XXX";
+
+
/**
* A struct representing a single unit (optional SI prefix and dimensionality).
*/
static SingleUnitImpl forMeasureUnit(const MeasureUnit& measureUnit, UErrorCode& status);
/** Transform this SingleUnitImpl into a MeasureUnit, simplifying if possible. */
- MeasureUnit build(UErrorCode& status);
+ MeasureUnit build(UErrorCode& status) const;
/** Compare this SingleUnitImpl to another SingleUnitImpl. */
int32_t compareTo(const SingleUnitImpl& other) const {
if (dimensionality < 0 && other.dimensionality > 0) {
// Positive dimensions first
return 1;
- } else if (dimensionality > 0 && other.dimensionality < 0) {
+ }
+ if (dimensionality > 0 && other.dimensionality < 0) {
return -1;
- } else if (index < other.index) {
+ }
+ if (index < other.index) {
return -1;
- } else if (index > other.index) {
+ }
+ if (index > other.index) {
return 1;
- } else if (siPrefix < other.siPrefix) {
+ }
+ if (siPrefix < other.siPrefix) {
return -1;
- } else if (siPrefix > other.siPrefix) {
+ }
+ if (siPrefix > other.siPrefix) {
return 1;
- } else {
- return 0;
}
+ return 0;
}
/**