Bug 1465042 - Rename Locale::IsValid to ::IsWellFormed. r=jfkthame
authorZibi Braniecki <zbraniecki@mozilla.com>
Thu, 23 Aug 2018 18:21:38 +0000
changeset 433150 0a5bf0b74a096eefd8b386cdc1a14033f6031801
parent 433149 15ae8f3946b48c38be495fee53bd2fb049ad898b
child 433151 c80c839f05d114bf913657266bac1d85d99171ee
push id34500
push usertoros@mozilla.com
push dateFri, 24 Aug 2018 09:42:33 +0000
treeherdermozilla-central@043aff7fda61 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1465042
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1465042 - Rename Locale::IsValid to ::IsWellFormed. r=jfkthame Differential Revision: https://phabricator.services.mozilla.com/D4025
intl/locale/LocaleService.cpp
intl/locale/MozLocale.cpp
intl/locale/MozLocale.h
intl/locale/tests/gtest/TestLocaleService.cpp
intl/locale/tests/gtest/TestMozLocale.cpp
--- a/intl/locale/LocaleService.cpp
+++ b/intl/locale/LocaleService.cpp
@@ -518,18 +518,18 @@ LocaleService::FilterMatches(const nsTAr
 
 void
 LocaleService::NegotiateLanguages(const nsTArray<nsCString>& aRequested,
                                   const nsTArray<nsCString>& aAvailable,
                                   const nsACString& aDefaultLocale,
                                   LangNegStrategy aStrategy,
                                   nsTArray<nsCString>& aRetVal)
 {
-  MOZ_ASSERT(aDefaultLocale.IsEmpty() || Locale(aDefaultLocale).IsValid(),
-    "If specified, default locale must be a valid BCP47 language tag.");
+  MOZ_ASSERT(aDefaultLocale.IsEmpty() || Locale(aDefaultLocale).IsWellFormed(),
+    "If specified, default locale must be a well-formed BCP47 language tag.");
 
   if (aStrategy == LangNegStrategy::Lookup && aDefaultLocale.IsEmpty()) {
     NS_WARNING("Default locale should be specified when using lookup strategy.");
   }
 
   FilterMatches(aRequested, aAvailable, aStrategy, aRetVal);
 
   if (aStrategy == LangNegStrategy::Lookup) {
--- a/intl/locale/MozLocale.cpp
+++ b/intl/locale/MozLocale.cpp
@@ -18,17 +18,17 @@ using namespace mozilla::intl;
  */
 Locale::Locale(const nsACString& aLocale)
 {
   MOZ_ASSERT(!aLocale.IsEmpty(), "Locale string cannot be empty");
 
   int32_t position = 0;
 
   if (!IsASCII(aLocale)) {
-    mIsValid = false;
+    mIsWellFormed = false;
     return;
   }
 
   nsAutoCString normLocale(aLocale);
   normLocale.ReplaceChar('_', '-');
 
   /**
    * BCP47 language tag:
@@ -55,25 +55,25 @@ Locale::Locale(const nsACString& aLocale
    * and intentionally skips positions (like `extlang`) which may be added later.
    *
    *  language-extlangs-script-region-variant-extension-privateuse
    *  --- 0 -- --- 1 -- -- 2 - -- 3 - -- 4 -- --- x --- ---- 6 ---
    */
   for (const nsACString& subTag : normLocale.Split('-')) {
     auto slen = subTag.Length();
     if (slen > 8) {
-      mIsValid = false;
+      mIsWellFormed = false;
       return;
     } else if (position == 6) {
       ToLowerCase(*mPrivateUse.AppendElement(subTag));
     } else if (subTag.LowerCaseEqualsLiteral("x")) {
       position = 6;
     } else if (position == 0) {
       if (slen < 2 || slen > 3) {
-        mIsValid = false;
+        mIsWellFormed = false;
         return;
       }
       mLanguage = subTag;
       ToLowerCase(mLanguage);
       position = 2;
     } else if (position <= 2 && slen == 4) {
       mScript = subTag;
       ToLowerCase(mScript);
@@ -92,17 +92,17 @@ Locale::Locale(const nsACString& aLocale
   }
 }
 
 const nsCString
 Locale::AsString() const
 {
   nsCString tag;
 
-  if (!mIsValid) {
+  if (!mIsWellFormed) {
     tag.AppendLiteral("und");
     return tag;
   }
 
   tag.Append(mLanguage);
 
   if (!mScript.IsEmpty()) {
     tag.AppendLiteral("-");
@@ -156,17 +156,17 @@ const nsTArray<nsCString>&
 Locale::GetVariants() const
 {
   return mVariants;
 }
 
 bool
 Locale::Matches(const Locale& aOther, bool aThisRange, bool aOtherRange) const
 {
-  if (!IsValid() || !aOther.IsValid()) {
+  if (!IsWellFormed() || !aOther.IsWellFormed()) {
     return false;
   }
 
   if ((!aThisRange || !mLanguage.IsEmpty()) &&
       (!aOtherRange || !aOther.mLanguage.IsEmpty()) &&
       !mLanguage.Equals(aOther.mLanguage)) {
     return false;
   }
--- a/intl/locale/MozLocale.h
+++ b/intl/locale/MozLocale.h
@@ -55,34 +55,34 @@ class Locale {
      * The constructor expects the input to be a well-formed BCP47-style locale string.
      *
      * Two operations are performed on the well-formed language tags:
      *
      *  * Case normalization to conform with BCP47 (e.g. "eN-uS" -> "en-US")
      *  * Underscore delimiters replaced with dashed (e.g. "en_US" -> "en-US")
      *
      * If the input language tag string is not well-formed, the Locale will be
-     * created with its flag `mValid` set to false which will make the Locale never match.
+     * created with its flag `mWellFormed` set to false which will make the Locale never match.
      */
     explicit Locale(const nsACString& aLocale);
     explicit Locale(const char* aLocale)
       : Locale(nsDependentCString(aLocale))
       { };
 
     const nsACString& GetLanguage() const;
     const nsACString& GetScript() const;
     const nsACString& GetRegion() const;
     const nsTArray<nsCString>& GetVariants() const;
 
     /**
      * Returns a `true` if the locale is well-formed, such that the
      * Locale object can validly be matched against others.
      */
-    bool IsValid() const {
-      return mIsValid;
+    bool IsWellFormed() const {
+      return mIsWellFormed;
     }
 
     /**
      * Returns a canonicalized language tag string of the locale.
      */
     const nsCString AsString() const;
 
     /**
@@ -124,41 +124,42 @@ class Locale {
      */
     void ClearRegion();
 
     /**
      * Marks the locale as invalid which in turns makes
      * it to be skipped by most LocaleService operations.
      */
     void Invalidate() {
-      mIsValid = false;
+      mIsWellFormed = false;
     }
 
     /**
      * Compares two locales expecting all fields to match each other.
      */
     bool operator== (const Locale& aOther) {
-      // Note: invalid Locale objects are never treated as equal to anything
-      // (even other invalid ones).
-      return IsValid() &&
-             aOther.IsValid() &&
+      // Note: non-well-formed Locale objects are never
+      // treated as equal to anything
+      // (even other non-well-formed ones).
+      return IsWellFormed() &&
+             aOther.IsWellFormed() &&
              mLanguage.Equals(aOther.mLanguage) &&
              mScript.Equals(aOther.mScript) &&
              mRegion.Equals(aOther.mRegion) &&
              mVariants == aOther.mVariants &&
              mPrivateUse == aOther.mPrivateUse;
     }
 
   private:
     nsAutoCStringN<3> mLanguage;
     nsAutoCStringN<4> mScript;
     nsAutoCStringN<2> mRegion;
     nsTArray<nsCString> mVariants;
     nsTArray<nsCString> mPrivateUse;
-    bool mIsValid = true;
+    bool mIsWellFormed = true;
 };
 
 } // intl
 } // namespace mozilla
 
 DECLARE_USE_COPY_CONSTRUCTORS(mozilla::intl::Locale)
 
 #endif /* mozilla_intl_MozLocale_h__ */
--- a/intl/locale/tests/gtest/TestLocaleService.cpp
+++ b/intl/locale/tests/gtest/TestLocaleService.cpp
@@ -78,16 +78,16 @@ TEST(Intl_Locale_LocaleService, GetPacka
   ASSERT_TRUE(len > 0);
 }
 
 TEST(Intl_Locale_LocaleService, GetDefaultLocale) {
   nsAutoCString locStr;
   LocaleService::GetInstance()->GetDefaultLocale(locStr);
 
   ASSERT_FALSE(locStr.IsEmpty());
-  ASSERT_TRUE(Locale(locStr).IsValid());
+  ASSERT_TRUE(Locale(locStr).IsWellFormed());
 }
 
 TEST(Intl_Locale_LocaleService, IsAppLocaleRTL) {
   // For now we can only test if the method doesn't crash.
   LocaleService::GetInstance()->IsAppLocaleRTL();
   ASSERT_TRUE(true);
 }
--- a/intl/locale/tests/gtest/TestMozLocale.cpp
+++ b/intl/locale/tests/gtest/TestMozLocale.cpp
@@ -68,48 +68,48 @@ TEST(Intl_Locale_Locale, Variants) {
 
   // Make sure that we canonicalize and sort variant tags
   ASSERT_TRUE(loc.AsString().Equals("en-US-basiceng-unifon"));
 }
 
 TEST(Intl_Locale_Locale, PrivateUse) {
   Locale loc = Locale("x-test");
 
-  ASSERT_TRUE(loc.IsValid());
+  ASSERT_TRUE(loc.IsWellFormed());
   ASSERT_TRUE(loc.GetLanguage().Equals(""));
   ASSERT_TRUE(loc.GetScript().Equals(""));
   ASSERT_TRUE(loc.GetRegion().Equals(""));
   ASSERT_TRUE(loc.GetVariants().Length() == 0);
 
   ASSERT_TRUE(loc.AsString().Equals("x-test"));
 
   Locale loc2 = Locale("fr-x-test");
 
-  ASSERT_TRUE(loc2.IsValid());
+  ASSERT_TRUE(loc2.IsWellFormed());
   ASSERT_TRUE(loc2.GetLanguage().Equals("fr"));
   ASSERT_TRUE(loc2.GetScript().Equals(""));
   ASSERT_TRUE(loc2.GetRegion().Equals(""));
   ASSERT_TRUE(loc2.GetVariants().Length() == 0);
 
   ASSERT_TRUE(loc2.AsString().Equals("fr-x-test"));
 
   // Make sure that we canonicalize private use tags
   // and preserve their order.
   Locale loc3 = Locale("fr-x-foo-bAr-BaZ");
 
-  ASSERT_TRUE(loc3.IsValid());
+  ASSERT_TRUE(loc3.IsWellFormed());
   ASSERT_TRUE(loc3.AsString().Equals("fr-x-foo-bar-baz"));
 }
 
 TEST(Intl_Locale_Locale, InvalidLocale) {
   Locale loc = Locale("en-verylongsubtag");
-  ASSERT_FALSE(loc.IsValid());
+  ASSERT_FALSE(loc.IsWellFormed());
 
   Locale loc2 = Locale("p-te");
-  ASSERT_FALSE(loc2.IsValid());
+  ASSERT_FALSE(loc2.IsWellFormed());
 }
 
 TEST(Intl_Locale_Locale, ClearRegion) {
   Locale loc = Locale("en-US");
   loc.ClearRegion();
   ASSERT_TRUE(loc.AsString().Equals("en"));
 }