mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-19 23:07:33 +09:00
Issue #1971 - Part 2: Update ICU source to 63.2.
This commit is contained in:
parent
8df84683be
commit
1e69214382
3160 changed files with 275815 additions and 234203 deletions
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2016 and later: Unicode, Inc. and others.
|
||||
// © 2016 and later: Unicode, Inc. and others.
|
||||
// License & terms of use: http://www.unicode.org/copyright.html
|
||||
/*
|
||||
**********************************************************************
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
#include "unicode/decimfmt.h"
|
||||
#include "uresimp.h"
|
||||
#include "unicode/ures.h"
|
||||
#include "unicode/ustring.h"
|
||||
#include "ureslocs.h"
|
||||
#include "cstring.h"
|
||||
#include "mutex.h"
|
||||
|
|
@ -41,11 +42,14 @@
|
|||
#include "standardplural.h"
|
||||
#include "unifiedcache.h"
|
||||
|
||||
#define MEAS_UNIT_COUNT 138
|
||||
#define WIDTH_INDEX_COUNT (UMEASFMT_WIDTH_NARROW + 1)
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
static constexpr int32_t PER_UNIT_INDEX = StandardPlural::COUNT;
|
||||
static constexpr int32_t PATTERN_COUNT = PER_UNIT_INDEX + 1;
|
||||
static constexpr int32_t MEAS_UNIT_COUNT = 142; // see assertion in MeasureFormatCacheData constructor
|
||||
static constexpr int32_t WIDTH_INDEX_COUNT = UMEASFMT_WIDTH_NARROW + 1;
|
||||
|
||||
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(MeasureFormat)
|
||||
|
||||
// Used to format durations like 5:47 or 21:35:42.
|
||||
|
|
@ -99,8 +103,6 @@ static UMeasureFormatWidth getRegularWidth(UMeasureFormatWidth width) {
|
|||
*/
|
||||
class MeasureFormatCacheData : public SharedObject {
|
||||
public:
|
||||
static const int32_t PER_UNIT_INDEX = StandardPlural::COUNT;
|
||||
static const int32_t PATTERN_COUNT = PER_UNIT_INDEX + 1;
|
||||
|
||||
/**
|
||||
* Redirection data from root-bundle, top-level sideways aliases.
|
||||
|
|
@ -109,7 +111,7 @@ public:
|
|||
*/
|
||||
UMeasureFormatWidth widthFallback[WIDTH_INDEX_COUNT];
|
||||
/** Measure unit -> format width -> array of patterns ("{0} meters") (plurals + PER_UNIT_INDEX) */
|
||||
SimpleFormatter *patterns[MEAS_UNIT_COUNT][WIDTH_INDEX_COUNT][PATTERN_COUNT];
|
||||
SimpleFormatter* patterns[MEAS_UNIT_COUNT][WIDTH_INDEX_COUNT][PATTERN_COUNT];
|
||||
const UChar* dnams[MEAS_UNIT_COUNT][WIDTH_INDEX_COUNT];
|
||||
SimpleFormatter perFormatters[WIDTH_INDEX_COUNT];
|
||||
|
||||
|
|
@ -145,24 +147,25 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
NumberFormat *currencyFormats[WIDTH_INDEX_COUNT];
|
||||
NumberFormat *integerFormat;
|
||||
NumericDateFormatters *numericDateFormatters;
|
||||
NumberFormat* currencyFormats[WIDTH_INDEX_COUNT];
|
||||
NumberFormat* integerFormat;
|
||||
NumericDateFormatters* numericDateFormatters;
|
||||
|
||||
MeasureFormatCacheData(const MeasureFormatCacheData &other);
|
||||
MeasureFormatCacheData &operator=(const MeasureFormatCacheData &other);
|
||||
};
|
||||
|
||||
MeasureFormatCacheData::MeasureFormatCacheData() {
|
||||
MeasureFormatCacheData::MeasureFormatCacheData()
|
||||
: integerFormat(nullptr), numericDateFormatters(nullptr) {
|
||||
// Please update MEAS_UNIT_COUNT if it gets out of sync with the true count!
|
||||
U_ASSERT(MEAS_UNIT_COUNT == MeasureUnit::getIndexCount());
|
||||
|
||||
for (int32_t i = 0; i < WIDTH_INDEX_COUNT; ++i) {
|
||||
widthFallback[i] = UMEASFMT_WIDTH_COUNT;
|
||||
}
|
||||
for (int32_t i = 0; i < UPRV_LENGTHOF(currencyFormats); ++i) {
|
||||
currencyFormats[i] = NULL;
|
||||
}
|
||||
uprv_memset(patterns, 0, sizeof(patterns));
|
||||
uprv_memset(dnams, 0, sizeof(dnams));
|
||||
integerFormat = NULL;
|
||||
numericDateFormatters = NULL;
|
||||
memset(&patterns[0][0][0], 0, sizeof(patterns));
|
||||
memset(&dnams[0][0], 0, sizeof(dnams));
|
||||
memset(currencyFormats, 0, sizeof(currencyFormats));
|
||||
}
|
||||
|
||||
MeasureFormatCacheData::~MeasureFormatCacheData() {
|
||||
|
|
@ -235,6 +238,9 @@ struct UnitDataSink : public ResourceSink {
|
|||
|
||||
void setFormatterIfAbsent(int32_t index, const ResourceValue &value,
|
||||
int32_t minPlaceholders, UErrorCode &errorCode) {
|
||||
U_ASSERT(unitIndex < MEAS_UNIT_COUNT);
|
||||
U_ASSERT(width < WIDTH_INDEX_COUNT);
|
||||
U_ASSERT(index < PATTERN_COUNT);
|
||||
SimpleFormatter **patterns = &cacheData.patterns[unitIndex][width][0];
|
||||
if (U_SUCCESS(errorCode) && patterns[index] == NULL) {
|
||||
if (minPlaceholders >= 0) {
|
||||
|
|
@ -248,6 +254,8 @@ struct UnitDataSink : public ResourceSink {
|
|||
}
|
||||
|
||||
void setDnamIfAbsent(const ResourceValue &value, UErrorCode& errorCode) {
|
||||
U_ASSERT(unitIndex < MEAS_UNIT_COUNT);
|
||||
U_ASSERT(width < WIDTH_INDEX_COUNT);
|
||||
if (cacheData.dnams[unitIndex][width] == NULL) {
|
||||
int32_t length;
|
||||
cacheData.dnams[unitIndex][width] = value.getString(length, errorCode);
|
||||
|
|
@ -265,7 +273,7 @@ struct UnitDataSink : public ResourceSink {
|
|||
setDnamIfAbsent(value, errorCode);
|
||||
} else if (uprv_strcmp(key, "per") == 0) {
|
||||
// For example, "{0}/h".
|
||||
setFormatterIfAbsent(MeasureFormatCacheData::PER_UNIT_INDEX, value, 1, errorCode);
|
||||
setFormatterIfAbsent(PER_UNIT_INDEX, value, 1, errorCode);
|
||||
} else {
|
||||
// The key must be one of the plural form strings. For example:
|
||||
// one{"{0} hr"}
|
||||
|
|
@ -288,10 +296,8 @@ struct UnitDataSink : public ResourceSink {
|
|||
return;
|
||||
}
|
||||
|
||||
if (value.getType() == URES_STRING) {
|
||||
// Units like "coordinate" that don't have plural variants
|
||||
setFormatterIfAbsent(StandardPlural::OTHER, value, 0, errorCode);
|
||||
} else if (value.getType() == URES_TABLE) {
|
||||
// We no longer handle units like "coordinate" here (which do not have plural variants)
|
||||
if (value.getType() == URES_TABLE) {
|
||||
// Units that have plural variants
|
||||
ResourceTable patternTableTable = value.getTable(errorCode);
|
||||
if (U_FAILURE(errorCode)) { return; }
|
||||
|
|
@ -333,6 +339,8 @@ struct UnitDataSink : public ResourceSink {
|
|||
consumeCompoundPattern(key, value, errorCode);
|
||||
}
|
||||
}
|
||||
} else if (uprv_strcmp(key, "coordinate") == 0) {
|
||||
// special handling but we need to determine what that is
|
||||
} else {
|
||||
type = key;
|
||||
ResourceTable subtypeTable = value.getTable(errorCode);
|
||||
|
|
@ -610,7 +618,7 @@ MeasureFormat::MeasureFormat(
|
|||
: cache(NULL),
|
||||
numberFormat(NULL),
|
||||
pluralRules(NULL),
|
||||
width(w),
|
||||
fWidth(w),
|
||||
listFormatter(NULL) {
|
||||
initMeasureFormat(locale, w, NULL, status);
|
||||
}
|
||||
|
|
@ -623,7 +631,7 @@ MeasureFormat::MeasureFormat(
|
|||
: cache(NULL),
|
||||
numberFormat(NULL),
|
||||
pluralRules(NULL),
|
||||
width(w),
|
||||
fWidth(w),
|
||||
listFormatter(NULL) {
|
||||
initMeasureFormat(locale, w, nfToAdopt, status);
|
||||
}
|
||||
|
|
@ -633,7 +641,7 @@ MeasureFormat::MeasureFormat(const MeasureFormat &other) :
|
|||
cache(other.cache),
|
||||
numberFormat(other.numberFormat),
|
||||
pluralRules(other.pluralRules),
|
||||
width(other.width),
|
||||
fWidth(other.fWidth),
|
||||
listFormatter(NULL) {
|
||||
cache->addRef();
|
||||
numberFormat->addRef();
|
||||
|
|
@ -651,7 +659,7 @@ MeasureFormat &MeasureFormat::operator=(const MeasureFormat &other) {
|
|||
SharedObject::copyPtr(other.cache, cache);
|
||||
SharedObject::copyPtr(other.numberFormat, numberFormat);
|
||||
SharedObject::copyPtr(other.pluralRules, pluralRules);
|
||||
width = other.width;
|
||||
fWidth = other.fWidth;
|
||||
delete listFormatter;
|
||||
if (other.listFormatter != NULL) {
|
||||
listFormatter = new ListFormatter(*other.listFormatter);
|
||||
|
|
@ -665,7 +673,7 @@ MeasureFormat::MeasureFormat() :
|
|||
cache(NULL),
|
||||
numberFormat(NULL),
|
||||
pluralRules(NULL),
|
||||
width(UMEASFMT_WIDTH_SHORT),
|
||||
fWidth(UMEASFMT_WIDTH_SHORT),
|
||||
listFormatter(NULL) {
|
||||
}
|
||||
|
||||
|
|
@ -695,7 +703,7 @@ UBool MeasureFormat::operator==(const Format &other) const {
|
|||
// don't have to check it here.
|
||||
|
||||
// differing widths aren't equivalent
|
||||
if (width != rhs.width) {
|
||||
if (fWidth != rhs.fWidth) {
|
||||
return FALSE;
|
||||
}
|
||||
// Width the same check locales.
|
||||
|
|
@ -756,10 +764,11 @@ UnicodeString &MeasureFormat::formatMeasurePerUnit(
|
|||
if (U_FAILURE(status)) {
|
||||
return appendTo;
|
||||
}
|
||||
MeasureUnit *resolvedUnit =
|
||||
MeasureUnit::resolveUnitPerUnit(measure.getUnit(), perUnit);
|
||||
if (resolvedUnit != NULL) {
|
||||
Measure newMeasure(measure.getNumber(), resolvedUnit, status);
|
||||
bool isResolved = false;
|
||||
MeasureUnit resolvedUnit =
|
||||
MeasureUnit::resolveUnitPerUnit(measure.getUnit(), perUnit, &isResolved);
|
||||
if (isResolved) {
|
||||
Measure newMeasure(measure.getNumber(), new MeasureUnit(resolvedUnit), status);
|
||||
return formatMeasure(
|
||||
newMeasure, **numberFormat, appendTo, pos, status);
|
||||
}
|
||||
|
|
@ -796,7 +805,7 @@ UnicodeString &MeasureFormat::formatMeasures(
|
|||
if (measureCount == 1) {
|
||||
return formatMeasure(measures[0], **numberFormat, appendTo, pos, status);
|
||||
}
|
||||
if (width == UMEASFMT_WIDTH_NUMERIC) {
|
||||
if (fWidth == UMEASFMT_WIDTH_NUMERIC) {
|
||||
Formattable hms[3];
|
||||
int32_t bitMap = toHMS(measures, measureCount, hms, status);
|
||||
if (bitMap > 0) {
|
||||
|
|
@ -830,7 +839,7 @@ UnicodeString &MeasureFormat::formatMeasures(
|
|||
}
|
||||
|
||||
UnicodeString MeasureFormat::getUnitDisplayName(const MeasureUnit& unit, UErrorCode& /*status*/) const {
|
||||
UMeasureFormatWidth width = getRegularWidth(this->width);
|
||||
UMeasureFormatWidth width = getRegularWidth(fWidth);
|
||||
const UChar* const* styleToDnam = cache->dnams[unit.getIndex()];
|
||||
const UChar* dnam = styleToDnam[width];
|
||||
if (dnam == NULL) {
|
||||
|
|
@ -886,11 +895,11 @@ void MeasureFormat::initMeasureFormat(
|
|||
return;
|
||||
}
|
||||
}
|
||||
width = w;
|
||||
fWidth = w;
|
||||
delete listFormatter;
|
||||
listFormatter = ListFormatter::createInstance(
|
||||
locale,
|
||||
listStyles[getRegularWidth(width)],
|
||||
listStyles[getRegularWidth(fWidth)],
|
||||
status);
|
||||
}
|
||||
|
||||
|
|
@ -913,7 +922,7 @@ UBool MeasureFormat::setMeasureFormatLocale(const Locale &locale, UErrorCode &st
|
|||
if (U_FAILURE(status) || locale == getLocale(status)) {
|
||||
return FALSE;
|
||||
}
|
||||
initMeasureFormat(locale, width, NULL, status);
|
||||
initMeasureFormat(locale, fWidth, NULL, status);
|
||||
return U_SUCCESS(status);
|
||||
}
|
||||
|
||||
|
|
@ -947,7 +956,7 @@ UnicodeString &MeasureFormat::formatMeasure(
|
|||
if (isCurrency(amtUnit)) {
|
||||
UChar isoCode[4];
|
||||
u_charsToUChars(amtUnit.getSubtype(), isoCode, 4);
|
||||
return cache->getCurrencyFormat(width)->format(
|
||||
return cache->getCurrencyFormat(fWidth)->format(
|
||||
new CurrencyAmount(amtNumber, isoCode, status),
|
||||
appendTo,
|
||||
pos,
|
||||
|
|
@ -956,7 +965,7 @@ UnicodeString &MeasureFormat::formatMeasure(
|
|||
UnicodeString formattedNumber;
|
||||
StandardPlural::Form pluralForm = QuantityFormatter::selectPlural(
|
||||
amtNumber, nf, **pluralRules, formattedNumber, pos, status);
|
||||
const SimpleFormatter *formatter = getPluralFormatter(amtUnit, width, pluralForm, status);
|
||||
const SimpleFormatter *formatter = getPluralFormatter(amtUnit, fWidth, pluralForm, status);
|
||||
return QuantityFormatter::format(*formatter, formattedNumber, appendTo, pos, status);
|
||||
}
|
||||
|
||||
|
|
@ -1007,7 +1016,6 @@ UnicodeString &MeasureFormat::formatNumeric(
|
|||
return appendTo;
|
||||
break;
|
||||
}
|
||||
return appendTo;
|
||||
}
|
||||
|
||||
static void appendRange(
|
||||
|
|
@ -1053,9 +1061,13 @@ UnicodeString &MeasureFormat::formatNumeric(
|
|||
}
|
||||
|
||||
// Format time. draft becomes something like '5:30:45'
|
||||
// #13606: DateFormat is not thread-safe, but MeasureFormat advertises itself as thread-safe.
|
||||
FieldPosition smallestFieldPosition(smallestField);
|
||||
UnicodeString draft;
|
||||
static UMutex dateFmtMutex = U_MUTEX_INITIALIZER;
|
||||
umtx_lock(&dateFmtMutex);
|
||||
dateFmt.format(date, draft, smallestFieldPosition, status);
|
||||
umtx_unlock(&dateFmtMutex);
|
||||
|
||||
// If we find field for smallest amount replace it with the formatted
|
||||
// smallest amount from above taking care to replace the integer part
|
||||
|
|
@ -1092,8 +1104,7 @@ UnicodeString &MeasureFormat::formatNumeric(
|
|||
const SimpleFormatter *MeasureFormat::getFormatterOrNull(
|
||||
const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index) const {
|
||||
width = getRegularWidth(width);
|
||||
SimpleFormatter *const (*unitPatterns)[MeasureFormatCacheData::PATTERN_COUNT] =
|
||||
&cache->patterns[unit.getIndex()][0];
|
||||
SimpleFormatter *const (*unitPatterns)[PATTERN_COUNT] = &cache->patterns[unit.getIndex()][0];
|
||||
if (unitPatterns[width][index] != NULL) {
|
||||
return unitPatterns[width][index];
|
||||
}
|
||||
|
|
@ -1161,8 +1172,7 @@ int32_t MeasureFormat::withPerUnitAndAppend(
|
|||
if (U_FAILURE(status)) {
|
||||
return offset;
|
||||
}
|
||||
const SimpleFormatter *perUnitFormatter =
|
||||
getFormatterOrNull(perUnit, width, MeasureFormatCacheData::PER_UNIT_INDEX);
|
||||
const SimpleFormatter *perUnitFormatter = getFormatterOrNull(perUnit, fWidth, PER_UNIT_INDEX);
|
||||
if (perUnitFormatter != NULL) {
|
||||
const UnicodeString *params[] = {&formatted};
|
||||
perUnitFormatter->formatAndAppend(
|
||||
|
|
@ -1174,9 +1184,9 @@ int32_t MeasureFormat::withPerUnitAndAppend(
|
|||
status);
|
||||
return offset;
|
||||
}
|
||||
const SimpleFormatter *perFormatter = getPerFormatter(width, status);
|
||||
const SimpleFormatter *perFormatter = getPerFormatter(fWidth, status);
|
||||
const SimpleFormatter *pattern =
|
||||
getPluralFormatter(perUnit, width, StandardPlural::ONE, status);
|
||||
getPluralFormatter(perUnit, fWidth, StandardPlural::ONE, status);
|
||||
if (U_FAILURE(status)) {
|
||||
return offset;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue