Bug 1728104 - Part 3: Remove NumberFormatFields.h from exported headers. r=platform-i18n-reviewers,anba,dminor
authorYoshi Cheng-Hao Huang <allstars.chh@gmail.com>
Thu, 16 Sep 2021 14:47:03 +0000
changeset 592183 2bf981a5af72f2fd517ac5aff34c6d32d960bce6
parent 592182 e003632d9854593b290ccebc7e666bef7e909cc1
child 592184 e5f2a2c79161caf2d1b535a9dd2581615d6356ae
push id38794
push userccozmuta@mozilla.com
push dateThu, 16 Sep 2021 21:45:06 +0000
treeherdermozilla-central@4f9a1f599b43 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersplatform-i18n-reviewers, anba, dminor
bugs1728104
milestone94.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 1728104 - Part 3: Remove NumberFormatFields.h from exported headers. r=platform-i18n-reviewers,anba,dminor Differential Revision: https://phabricator.services.mozilla.com/D125757
intl/components/moz.build
intl/components/src/NumberFormat.cpp
intl/components/src/NumberFormat.h
intl/components/src/NumberRangeFormat.cpp
intl/components/src/RelativeTimeFormat.cpp
--- a/intl/components/moz.build
+++ b/intl/components/moz.build
@@ -8,17 +8,16 @@ EXPORTS.mozilla.intl = [
     "src/Collator.h",
     "src/DateTimeFormat.h",
     "src/DateTimePatternGenerator.h",
     "src/ICU4CGlue.h",
     "src/ICUError.h",
     "src/ListFormat.h",
     "src/LocaleCanonicalizer.h",
     "src/NumberFormat.h",
-    "src/NumberFormatFields.h",
     "src/NumberPart.h",
     "src/NumberRangeFormat.h",
     "src/PluralRules.h",
     "src/RelativeTimeFormat.h",
 ]
 
 UNIFIED_SOURCES += [
     "src/Calendar.cpp",
--- a/intl/components/src/NumberFormat.cpp
+++ b/intl/components/src/NumberFormat.cpp
@@ -42,16 +42,57 @@ Result<Ok, ICUError> NumberFormat::initi
     if (U_FAILURE(status)) {
       return Err(ToICUError(status));
     }
     return Ok();
   }
   return Err(ICUError::InternalError);
 }
 
+Result<std::u16string_view, ICUError> NumberFormat::formatToParts(
+    double number, NumberPartVector& parts) const {
+  if (!formatInternal(number)) {
+    return Err(ICUError::InternalError);
+  }
+
+  bool isNegative = !IsNaN(number) && IsNegative(number);
+
+  return FormatResultToParts(mFormattedNumber, Some(number), isNegative,
+                             mFormatForUnit, parts);
+}
+
+Result<std::u16string_view, ICUError> NumberFormat::formatToParts(
+    int64_t number, NumberPartVector& parts) const {
+  if (!formatInternal(number)) {
+    return Err(ICUError::InternalError);
+  }
+
+  return FormatResultToParts(mFormattedNumber, Nothing(), number < 0,
+                             mFormatForUnit, parts);
+}
+
+Result<std::u16string_view, ICUError> NumberFormat::formatToParts(
+    std::string_view number, NumberPartVector& parts) const {
+  if (!formatInternal(number)) {
+    return Err(ICUError::InternalError);
+  }
+
+  // Non-finite numbers aren't currently supported here. If we ever need to
+  // support those, the |Maybe<double>| argument must be computed here.
+  MOZ_ASSERT(number != "Infinity");
+  MOZ_ASSERT(number != "+Infinity");
+  MOZ_ASSERT(number != "-Infinity");
+  MOZ_ASSERT(number != "NaN");
+
+  bool isNegative = !number.empty() && number[0] == '-';
+
+  return FormatResultToParts(mFormattedNumber, Nothing(), isNegative,
+                             mFormatForUnit, parts);
+}
+
 Result<int32_t, ICUError> NumberFormat::selectFormatted(
     double number, char16_t* keyword, int32_t keywordSize,
     UPluralRules* pluralRules) const {
   MOZ_ASSERT(keyword && pluralRules);
   UErrorCode status = U_ZERO_ERROR;
 
   MOZ_TRY(format(number));
 
--- a/intl/components/src/NumberFormat.h
+++ b/intl/components/src/NumberFormat.h
@@ -10,17 +10,17 @@
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/intl/ICU4CGlue.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/PodOperations.h"
 #include "mozilla/Result.h"
 #include "mozilla/Utf8.h"
 #include "mozilla/Vector.h"
 #include "mozilla/intl/ICUError.h"
-#include "mozilla/intl/NumberFormatFields.h"
+#include "mozilla/intl/NumberPart.h"
 
 #include "unicode/ustring.h"
 #include "unicode/unum.h"
 #include "unicode/unumberformatter.h"
 
 struct UPluralRules;
 
 namespace mozilla::intl {
@@ -236,26 +236,17 @@ class NumberFormat final {
    * SpiderMonkey. Supporting utf-8 would require recalculating the offsets
    * in NumberPartVector from fixed width to variable width, which might be
    * tricky to get right and is work that won't be necessary if we switch to
    * ICU4X (see Bug 1707035).
    *
    * https://tc39.es/ecma402/#sec-partitionnumberpattern
    */
   Result<std::u16string_view, ICUError> formatToParts(
-      double number, NumberPartVector& parts) const {
-    if (!formatInternal(number)) {
-      return Err(ICUError::InternalError);
-    }
-
-    bool isNegative = !IsNaN(number) && IsNegative(number);
-
-    return FormatResultToParts(mFormattedNumber, Some(number), isNegative,
-                               mFormatForUnit, parts);
-  }
+      double number, NumberPartVector& parts) const;
 
   /**
    * Formats a double to the provider buffer (either utf-8 or utf-16)
    *
    * https://tc39.es/ecma402/#sec-formatnumberstring
    */
   template <typename B>
   Result<Ok, ICUError> format(double number, B& buffer) const {
@@ -290,24 +281,17 @@ class NumberFormat final {
    * SpiderMonkey. Supporting utf-8 would require recalculating the offsets
    * in NumberPartVector from fixed width to variable width, which might be
    * tricky to get right and is work that won't be necessary if we switch to
    * ICU4X (see Bug 1707035).
    *
    * https://tc39.es/ecma402/#sec-partitionnumberpattern
    */
   Result<std::u16string_view, ICUError> formatToParts(
-      int64_t number, NumberPartVector& parts) const {
-    if (!formatInternal(number)) {
-      return Err(ICUError::InternalError);
-    }
-
-    return FormatResultToParts(mFormattedNumber, Nothing(), number < 0,
-                               mFormatForUnit, parts);
-  }
+      int64_t number, NumberPartVector& parts) const;
 
   /**
    * Formats an int64_t to the provider buffer (either utf-8 or utf-16).
    *
    * https://tc39.es/ecma402/#sec-formatnumberstring
    */
   template <typename B>
   Result<Ok, ICUError> format(int64_t number, B& buffer) const {
@@ -343,33 +327,17 @@ class NumberFormat final {
    * SpiderMonkey. Supporting utf-8 would require recalculating the offsets
    * in NumberPartVector from fixed width to variable width, which might be
    * tricky to get right and is work that won't be necessary if we switch to
    * ICU4X (see Bug 1707035).
    *
    * https://tc39.es/ecma402/#sec-partitionnumberpattern
    */
   Result<std::u16string_view, ICUError> formatToParts(
-      std::string_view number, NumberPartVector& parts) const {
-    if (!formatInternal(number)) {
-      return Err(ICUError::InternalError);
-    }
-
-    // Non-finite numbers aren't currently supported here. If we ever need to
-    // support those, the |Maybe<double>| argument must be computed here.
-    MOZ_ASSERT(number != "Infinity");
-    MOZ_ASSERT(number != "+Infinity");
-    MOZ_ASSERT(number != "-Infinity");
-    MOZ_ASSERT(number != "NaN");
-
-    bool isNegative = !number.empty() && number[0] == '-';
-
-    return FormatResultToParts(mFormattedNumber, Nothing(), isNegative,
-                               mFormatForUnit, parts);
-  }
+      std::string_view number, NumberPartVector& parts) const;
 
   /**
    * Formats a string encoded decimal number to the provider buffer
    * (either utf-8 or utf-16).
    *
    * https://tc39.es/ecma402/#sec-formatnumberstring
    */
   template <typename B>
--- a/intl/components/src/NumberRangeFormat.cpp
+++ b/intl/components/src/NumberRangeFormat.cpp
@@ -1,17 +1,17 @@
 /* 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 "mozilla/intl/NumberRangeFormat.h"
 
 #include "mozilla/intl/ICU4CGlue.h"
 #include "mozilla/intl/NumberFormat.h"
-#include "mozilla/intl/NumberFormatFields.h"
+#include "NumberFormatFields.h"
 #include "NumberFormatFieldsUtil.h"
 #include "NumberFormatterSkeleton.h"
 #include "ScopedICUObject.h"
 
 #include "unicode/uformattedvalue.h"
 #include "unicode/unumberrangeformatter.h"
 #include "unicode/upluralrules.h"
 
--- a/intl/components/src/RelativeTimeFormat.cpp
+++ b/intl/components/src/RelativeTimeFormat.cpp
@@ -1,14 +1,15 @@
 /* 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 "mozilla/intl/RelativeTimeFormat.h"
 #include "mozilla/FloatingPoint.h"
 
+#include "NumberFormatFields.h"
 #include "ICU4CGlue.h"
 #include "ScopedICUObject.h"
 
 namespace mozilla::intl {
 
 /*static*/ Result<UniquePtr<RelativeTimeFormat>, ICUError>
 RelativeTimeFormat::TryCreate(const char* aLocale,
                               const RelativeTimeFormatOptions& aOptions) {