зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1736834 - Part 6: Use Maybe instead of nullptr to represent absent Unicode extensions. r=platform-i18n-reviewers,dminor
Use `Maybe` and return `Span` instead of raw `const char*`. Differential Revision: https://phabricator.services.mozilla.com/D129042
This commit is contained in:
Родитель
d5261e082c
Коммит
9e6104f1a2
|
@ -21,8 +21,7 @@ TEST(IntlLocale, LocaleSettersAndGetters)
|
|||
ASSERT_TRUE(locale.language().equalTo("fr"));
|
||||
ASSERT_TRUE(locale.region().equalTo("CA"));
|
||||
ASSERT_TRUE(locale.script().equalTo("Latn"));
|
||||
ASSERT_EQ(MakeStringSpan(locale.unicodeExtension()),
|
||||
MakeStringSpan("u-ca-gregory"));
|
||||
ASSERT_EQ(locale.unicodeExtension().value(), MakeStringSpan("u-ca-gregory"));
|
||||
|
||||
TestBuffer<char> buffer;
|
||||
ASSERT_TRUE(locale.toString(buffer).isOk());
|
||||
|
|
|
@ -158,12 +158,12 @@ ptrdiff_t Locale::unicodeExtensionIndex() const {
|
|||
return -1;
|
||||
}
|
||||
|
||||
const char* Locale::unicodeExtension() const {
|
||||
Maybe<Span<const char>> Locale::unicodeExtension() const {
|
||||
ptrdiff_t index = unicodeExtensionIndex();
|
||||
if (index >= 0) {
|
||||
return extensions()[index].get();
|
||||
return Some(MakeStringSpan(extensions()[index].get()));
|
||||
}
|
||||
return nullptr;
|
||||
return Nothing();
|
||||
}
|
||||
|
||||
ICUResult Locale::setUnicodeExtension(Span<const char> extension) {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/intl/ICUError.h"
|
||||
#include "mozilla/intl/ICU4CGlue.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Span.h"
|
||||
#include "mozilla/TextUtils.h"
|
||||
#include "mozilla/TypedEnumBits.h"
|
||||
|
@ -252,9 +253,9 @@ class MOZ_STACK_CLASS Locale final {
|
|||
const char* privateuse() const { return privateuse_.get(); }
|
||||
|
||||
/**
|
||||
* Return the Unicode extension subtag or nullptr if not present.
|
||||
* Return the Unicode extension subtag or Nothing if not present.
|
||||
*/
|
||||
const char* unicodeExtension() const;
|
||||
Maybe<Span<const char>> unicodeExtension() const;
|
||||
|
||||
private:
|
||||
ptrdiff_t unicodeExtensionIndex() const;
|
||||
|
|
|
@ -411,10 +411,11 @@ bool js::intl::ApplyUnicodeExtensionToTag(
|
|||
|
||||
const char* unicodeExtensionEnd = nullptr;
|
||||
const char* unicodeExtensionKeywords = nullptr;
|
||||
if (const char* unicodeExtension = tag.unicodeExtension()) {
|
||||
unicodeExtensionEnd = unicodeExtension + strlen(unicodeExtension);
|
||||
if (auto unicodeExtension = tag.unicodeExtension()) {
|
||||
const char* unicodeExtensionBegin = unicodeExtension->data();
|
||||
unicodeExtensionEnd = unicodeExtensionBegin + unicodeExtension->size();
|
||||
|
||||
SepKeywordIterator<char> iter(unicodeExtension, unicodeExtensionEnd);
|
||||
SepKeywordIterator<char> iter(unicodeExtensionBegin, unicodeExtensionEnd);
|
||||
|
||||
// Find the start of the first keyword.
|
||||
unicodeExtensionKeywords = iter.next();
|
||||
|
@ -423,7 +424,7 @@ bool js::intl::ApplyUnicodeExtensionToTag(
|
|||
const char* attributesEnd = unicodeExtensionKeywords
|
||||
? unicodeExtensionKeywords
|
||||
: unicodeExtensionEnd;
|
||||
if (!newExtension.append(unicodeExtension + 1, attributesEnd)) {
|
||||
if (!newExtension.append(unicodeExtensionBegin + 1, attributesEnd)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче