зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1713206
- Propagate ICU statuses to ICUErrors; r=platform-i18n-reviewers,dminor
Depends on D124963 Differential Revision: https://phabricator.services.mozilla.com/D124964
This commit is contained in:
Родитель
46c00b33ef
Коммит
12c9670cc5
|
@ -21,13 +21,10 @@ Collator::~Collator() {
|
|||
Result<UniquePtr<Collator>, ICUError> Collator::TryCreate(const char* aLocale) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UCollator* collator = ucol_open(aLocale, &status);
|
||||
if (U_SUCCESS(status)) {
|
||||
return MakeUnique<Collator>(collator);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
if (status == U_MEMORY_ALLOCATION_ERROR) {
|
||||
return Err(ICUError::OutOfMemory);
|
||||
}
|
||||
return Err(ICUError::InternalError);
|
||||
return MakeUnique<Collator>(collator);
|
||||
};
|
||||
|
||||
int32_t Collator::CompareStrings(Span<const char16_t> aSource,
|
||||
|
|
|
@ -97,7 +97,7 @@ static ICUResult FillBufferWithICUCall(Buffer& buffer,
|
|||
MOZ_ASSERT(length == length2);
|
||||
}
|
||||
if (!ICUSuccessForStringSpan(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
buffer.written(length);
|
||||
|
@ -127,7 +127,7 @@ static ICUResult FillVectorWithICUCall(Vector<CharType, InlineSize>& vector,
|
|||
MOZ_ASSERT(length == length2);
|
||||
}
|
||||
if (!ICUSuccessForStringSpan(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
mozilla::DebugOnly<bool> result = vector.resizeUninitialized(length);
|
||||
|
|
|
@ -39,9 +39,10 @@ Result<Ok, ICUError> NumberFormat::initialize(
|
|||
if (mNumberFormatter) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
mFormattedNumber = unumf_openResult(&status);
|
||||
if (U_SUCCESS(status)) {
|
||||
return Ok();
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
return Err(ICUError::InternalError);
|
||||
}
|
||||
|
@ -52,15 +53,13 @@ Result<int32_t, ICUError> NumberFormat::selectFormatted(
|
|||
MOZ_ASSERT(keyword && pluralRules);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
if (format(number).isErr()) {
|
||||
return Err(ICUError::InternalError);
|
||||
}
|
||||
MOZ_TRY(format(number));
|
||||
|
||||
int32_t utf16KeywordLength = uplrules_selectFormatted(
|
||||
pluralRules, mFormattedNumber, keyword, keywordSize, &status);
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
return utf16KeywordLength;
|
||||
|
@ -98,14 +97,14 @@ Result<std::u16string_view, ICUError> NumberFormat::formatResult() const {
|
|||
const UFormattedValue* formattedValue =
|
||||
unumf_resultAsValue(mFormattedNumber, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
int32_t utf16Length;
|
||||
const char16_t* utf16Str =
|
||||
ufmtval_getString(formattedValue, &utf16Length, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
return std::u16string_view(utf16Str, static_cast<size_t>(utf16Length));
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#include "ICU4CGlue.h"
|
||||
#include "NumberFormatFields.h"
|
||||
#include "NumberFormatFieldsUtil.h"
|
||||
#include "ScopedICUObject.h"
|
||||
|
@ -256,7 +257,7 @@ Result<std::u16string_view, ICUError> FormatResultToParts(
|
|||
|
||||
const UFormattedValue* formattedValue = unumf_resultAsValue(value, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
return FormatResultToParts(formattedValue, number, isNegative, formatForUnit,
|
||||
|
@ -271,19 +272,19 @@ Result<std::u16string_view, ICUError> FormatResultToParts(
|
|||
int32_t utf16Length;
|
||||
const char16_t* utf16Str = ufmtval_getString(value, &utf16Length, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
UConstrainedFieldPosition* fpos = ucfpos_open(&status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
ScopedICUObject<UConstrainedFieldPosition, ucfpos_close> toCloseFpos(fpos);
|
||||
|
||||
// We're only interested in UFIELD_CATEGORY_NUMBER fields.
|
||||
ucfpos_constrainCategory(fpos, UFIELD_CATEGORY_NUMBER, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
// Vacuum up fields in the overall formatted string.
|
||||
|
@ -292,7 +293,7 @@ Result<std::u16string_view, ICUError> FormatResultToParts(
|
|||
while (true) {
|
||||
bool hasMore = ufmtval_nextPosition(value, fpos, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
if (!hasMore) {
|
||||
break;
|
||||
|
@ -300,13 +301,13 @@ Result<std::u16string_view, ICUError> FormatResultToParts(
|
|||
|
||||
int32_t fieldName = ucfpos_getField(fpos, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
int32_t beginIndex, endIndex;
|
||||
ucfpos_getIndexes(fpos, &beginIndex, &endIndex, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
Maybe<NumberPartType> partType = GetPartTypeForNumberField(
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "mozilla/intl/NumberRangeFormat.h"
|
||||
|
||||
#include "mozilla/intl/ICU4CGlue.h"
|
||||
#include "mozilla/intl/NumberFormat.h"
|
||||
#include "mozilla/intl/NumberFormatFields.h"
|
||||
#include "NumberFormatFieldsUtil.h"
|
||||
|
@ -55,9 +56,10 @@ Result<Ok, ICUError> NumberRangeFormat::initialize(
|
|||
if (mNumberRangeFormatter) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
mFormattedNumberRange = unumrf_openResult(&status);
|
||||
if (U_SUCCESS(status)) {
|
||||
return Ok();
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
return Err(ICUError::InternalError);
|
||||
}
|
||||
|
@ -74,7 +76,7 @@ Result<int32_t, ICUError> NumberRangeFormat::selectForRange(
|
|||
int32_t utf16KeywordLength = uplrules_selectForRange(
|
||||
pluralRules, mFormattedNumberRange, keyword, keywordSize, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
return utf16KeywordLength;
|
||||
|
@ -112,14 +114,14 @@ Result<std::u16string_view, ICUError> NumberRangeFormat::formatResult() const {
|
|||
const UFormattedValue* formattedValue =
|
||||
unumrf_resultAsValue(mFormattedNumberRange, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
int32_t utf16Length;
|
||||
const char16_t* utf16Str =
|
||||
ufmtval_getString(formattedValue, &utf16Length, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
return std::u16string_view(utf16Str, static_cast<size_t>(utf16Length));
|
||||
|
@ -133,7 +135,7 @@ Result<std::u16string_view, ICUError> NumberRangeFormat::formatResultToParts(
|
|||
UNumberRangeIdentityResult identity =
|
||||
unumrf_resultGetIdentityResult(mFormattedNumberRange, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
bool isIdenticalNumber = identity != UNUM_IDENTITY_RESULT_NOT_EQUAL;
|
||||
|
@ -141,19 +143,19 @@ Result<std::u16string_view, ICUError> NumberRangeFormat::formatResultToParts(
|
|||
const UFormattedValue* formattedValue =
|
||||
unumrf_resultAsValue(mFormattedNumberRange, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
int32_t utf16Length;
|
||||
const char16_t* utf16Str =
|
||||
ufmtval_getString(formattedValue, &utf16Length, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
UConstrainedFieldPosition* fpos = ucfpos_open(&status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
ScopedICUObject<UConstrainedFieldPosition, ucfpos_close> toCloseFpos(fpos);
|
||||
|
||||
|
@ -165,7 +167,7 @@ Result<std::u16string_view, ICUError> NumberRangeFormat::formatResultToParts(
|
|||
if (isIdenticalNumber) {
|
||||
ucfpos_constrainCategory(fpos, UFIELD_CATEGORY_NUMBER, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,7 +182,7 @@ Result<std::u16string_view, ICUError> NumberRangeFormat::formatResultToParts(
|
|||
while (true) {
|
||||
bool hasMore = ufmtval_nextPosition(formattedValue, fpos, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
if (!hasMore) {
|
||||
break;
|
||||
|
@ -188,18 +190,18 @@ Result<std::u16string_view, ICUError> NumberRangeFormat::formatResultToParts(
|
|||
|
||||
int32_t category = ucfpos_getCategory(fpos, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
int32_t fieldName = ucfpos_getField(fpos, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
int32_t beginIndex, endIndex;
|
||||
ucfpos_getIndexes(fpos, &beginIndex, &endIndex, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
if (category == UFIELD_CATEGORY_NUMBER_RANGE_SPAN) {
|
||||
|
@ -232,12 +234,12 @@ Result<std::u16string_view, ICUError> NumberRangeFormat::formatResultToParts(
|
|||
Maybe<NumberPartType> partType = GetPartTypeForNumberField(
|
||||
UNumberFormatFields(fieldName), number, isNegative, mFormatForUnit);
|
||||
if (!partType || !fields.append(*partType, beginIndex, endIndex)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
}
|
||||
|
||||
if (!fields.toPartsVector(utf16Length, sourceMap, parts)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
// Find the approximately sign for ECMA-402.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "mozilla/intl/PluralRules.h"
|
||||
|
||||
#include "mozilla/intl/ICU4CGlue.h"
|
||||
#include "mozilla/intl/NumberFormat.h"
|
||||
#include "mozilla/intl/NumberRangeFormat.h"
|
||||
#include "mozilla/Utf8.h"
|
||||
|
@ -40,7 +41,7 @@ Result<UniquePtr<PluralRules>, ICUError> PluralRules::TryCreate(
|
|||
aLocale, aOptions.ToNumberRangeFormatOptions());
|
||||
|
||||
if (numberRangeFormat.isErr()) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(numberRangeFormat.unwrapErr());
|
||||
}
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
@ -51,7 +52,7 @@ Result<UniquePtr<PluralRules>, ICUError> PluralRules::TryCreate(
|
|||
uplrules_openForType(aLocale.data(), pluralType, &status);
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
return UniquePtr<PluralRules>(new PluralRules(
|
||||
|
@ -93,7 +94,7 @@ Result<EnumSet<PluralRules::Keyword>, ICUError> PluralRules::Categories()
|
|||
UErrorCode status = U_ZERO_ERROR;
|
||||
UEnumeration* enumeration = uplrules_getKeywords(mPluralRules, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
ScopedICUObject<UEnumeration, uenum_close> closeEnum(enumeration);
|
||||
|
@ -103,7 +104,7 @@ Result<EnumSet<PluralRules::Keyword>, ICUError> PluralRules::Categories()
|
|||
int32_t keywordLength;
|
||||
const char* keyword = uenum_next(enumeration, &keywordLength, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
return Err(ICUError::InternalError);
|
||||
return Err(ToICUError(status));
|
||||
}
|
||||
|
||||
if (!keyword) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче