Skip to content

Commit

Permalink
Backed out 9 changesets (bug 1719746, bug 1735341) as requested by de…
Browse files Browse the repository at this point in the history
…v. CLOSED TREE

Backed out changeset f1b3e7dec7e2 (bug 1735341)
Backed out changeset e7675e3524da (bug 1719746)
Backed out changeset 05109157a4b5 (bug 1719746)
Backed out changeset b98f10477f44 (bug 1719746)
Backed out changeset dce9c0d6c79c (bug 1719746)
Backed out changeset 472767f43cad (bug 1719746)
Backed out changeset 4fa55bded471 (bug 1719746)
Backed out changeset 391c305dce1f (bug 1719746)
Backed out changeset 5f20632de2be (bug 1719746)
  • Loading branch information
Butkovits Atila committed Oct 14, 2021
1 parent 0f40775 commit 2784770
Show file tree
Hide file tree
Showing 28 changed files with 2,648 additions and 2,884 deletions.
2 changes: 1 addition & 1 deletion .clang-format-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build/clang-plugin/.*
config/gcc-stl-wrapper.template.h
config/msvc-stl-wrapper.template.h
# Generated code
intl/components/src/LocaleGenerated.cpp
js/src/builtin/intl/LanguageTagGenerated.cpp
js/src/builtin/intl/TimeZoneDataGenerated.h

# Don't want to reformat irregexp (third-party code)
Expand Down
77 changes: 2 additions & 75 deletions intl/components/gtest/TestLocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,85 +4,12 @@
#include "gtest/gtest.h"

#include "mozilla/intl/Locale.h"
#include "mozilla/Span.h"

#include "TestBuffer.h"
#include <stdint.h>
#include <string_view>

namespace mozilla::intl {

TEST(IntlLocale, LocaleSettersAndGetters)
{
Locale locale;
locale.setLanguage("fr");
locale.setRegion("CA");
locale.setScript("Latn");
ASSERT_TRUE(locale.setUnicodeExtension("u-ca-gregory"));
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"));

TestBuffer<char> buffer;
ASSERT_TRUE(locale.toString(buffer).isOk());
ASSERT_TRUE(buffer.verboseMatches("fr-Latn-CA-u-ca-gregory"));

// No setters for variants or other extensions...
Locale locale2;
ASSERT_TRUE(LocaleParser::tryParse(
MakeStringSpan("fr-CA-fonipa-t-es-AR-h0-hybrid"), locale2)
.isOk());
ASSERT_EQ(MakeStringSpan(locale2.variants()[0].get()),
MakeStringSpan("fonipa"));
ASSERT_EQ(MakeStringSpan(locale2.extensions()[0].get()),
MakeStringSpan("t-es-AR-h0-hybrid"));
locale2.clearVariants();
ASSERT_EQ(locale2.variants().length(), 0UL);
}

TEST(IntlLocale, LocaleParser)
{
const char* tags[] = {
"en-US", "en-GB", "es-AR", "it", "zh-Hans-CN",
"de-AT", "pl", "fr-FR", "de-AT", "sr-Cyrl-SR",
"nb-NO", "fr-FR", "mk", "uk", "und-PL",
"und-Latn-AM", "ug-Cyrl", "sr-ME", "mn-Mong", "lif-Limb",
"gan", "zh-Hant", "yue-Hans", "unr", "unr-Deva",
"und-Thai-CN", "ug-Cyrl", "en-Latn-DE", "pl-FR", "de-CH",
"tuq", "sr-ME", "ng", "klx", "kk-Arab",
"en-Cyrl", "und-Cyrl-UK", "und-Arab", "und-Arab-FO"};

Locale locale;
for (const auto* tag : tags) {
ASSERT_TRUE(LocaleParser::tryParse(MakeStringSpan(tag), locale).isOk());
}
}

TEST(IntlLocale, LikelySubtags)
{
Locale locale;
ASSERT_TRUE(LocaleParser::tryParse(MakeStringSpan("zh"), locale).isOk());
ASSERT_TRUE(locale.addLikelySubtags());
TestBuffer<char> buffer;
ASSERT_TRUE(locale.toString(buffer).isOk());
ASSERT_TRUE(buffer.verboseMatches("zh-Hans-CN"));
ASSERT_TRUE(locale.removeLikelySubtags());
buffer.clear();
ASSERT_TRUE(locale.toString(buffer).isOk());
ASSERT_TRUE(buffer.verboseMatches("zh"));
}

TEST(IntlLocale, Canonicalize)
{
Locale locale;
ASSERT_TRUE(
LocaleParser::tryParse(MakeStringSpan("nob-bokmal"), locale).isOk());
ASSERT_TRUE(locale.canonicalize().isOk());
TestBuffer<char> buffer;
ASSERT_TRUE(locale.toString(buffer).isOk());
ASSERT_TRUE(buffer.verboseMatches("nb"));
}

// These tests are dependent on the machine that this test is being run on.
TEST(IntlLocale, SystemDependentTests)
{
Expand Down
2 changes: 0 additions & 2 deletions intl/components/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ UNIFIED_SOURCES += [
"src/ICU4CGlue.cpp",
"src/ICU4CLibrary.cpp",
"src/ListFormat.cpp",
"src/Locale.cpp",
"src/LocaleCanonicalizer.cpp",
"src/LocaleGenerated.cpp",
"src/MeasureUnit.cpp",
"src/NumberFormat.cpp",
"src/NumberFormatFields.cpp",
Expand Down
2 changes: 1 addition & 1 deletion intl/components/src/DateTimeFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class DateTimeFormat final {
// Write the formatted date into the u16Buffer.
PatternVector u16Vec;

auto result = FillBufferWithICUCall(
auto result = FillVectorWithICUCall(
u16Vec, [this, &aUnixEpoch](UChar* target, int32_t length,
UErrorCode* status) {
return udat_format(mDateFormat, aUnixEpoch, target, length,
Expand Down
36 changes: 36 additions & 0 deletions intl/components/src/DateTimePatternGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ class DateTimePatternGenerator final {
});
}

/**
* Given a skeleton (a string with unordered datetime fields), get a best
* pattern that will fit for that locale. This pattern will be filled into the
* buffer. e.g. The skeleton "yMd" would return the pattern "M/d/y" for en-US,
* or "dd/MM/y" for en-GB.
*/
template <size_t S>
ICUResult GetBestPattern(Span<const char16_t> aSkeleton,
Vector<char16_t, S>& aVector,
EnumSet<PatternMatchOption> options = {}) {
return FillVectorWithICUCall(
aVector, [&](UChar* target, int32_t length, UErrorCode* status) {
return udatpg_getBestPatternWithOptions(
mGenerator.GetMut(), aSkeleton.data(),
static_cast<int32_t>(aSkeleton.Length()),
toUDateTimePatternMatchOptions(options), target, length, status);
});
}

/**
* Get a skeleton (a string with unordered datetime fields) from a pattern.
* For example, both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
Expand All @@ -92,6 +111,23 @@ class DateTimePatternGenerator final {
});
}

/**
* Get a skeleton (a string with unordered datetime fields) from a pattern.
* For example, both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
*/
template <typename V, size_t N, typename A>
static ICUResult GetSkeleton(Span<const char16_t> aPattern,
Vector<V, N, A>& aVector) {
// At one time udatpg_getSkeleton required a UDateTimePatternGenerator*, but
// now it is valid to pass in a nullptr.
return FillVectorWithICUCall(
aVector, [&](UChar* target, int32_t length, UErrorCode* status) {
return udatpg_getSkeleton(nullptr, aPattern.data(),
static_cast<int32_t>(aPattern.Length()),
target, length, status);
});
}

/**
* TODO(Bug 1686965) - Temporarily get the underlying ICU object while
* migrating to the unified API. This should be removed when completing the
Expand Down
6 changes: 3 additions & 3 deletions intl/components/src/ICU4CGlue.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ class VectorToBufferAdaptor {
};

/**
* An overload of FillBufferWithICUCall that accepts a mozilla::Vector rather
* than a Buffer.
* A variant of FillBufferWithICUCall that accepts a mozilla::Vector rather than
* a Buffer.
*/
template <typename ICUStringFunction, size_t InlineSize, typename CharType>
static ICUResult FillBufferWithICUCall(Vector<CharType, InlineSize>& vector,
static ICUResult FillVectorWithICUCall(Vector<CharType, InlineSize>& vector,
const ICUStringFunction& strFn) {
VectorToBufferAdaptor buffer(vector);
return FillBufferWithICUCall(buffer, strFn);
Expand Down
Loading

0 comments on commit 2784770

Please sign in to comment.