Bug 1728104 - Part 2: Add NumberPart.h. r=platform-i18n-reviewers,anba,dminor
authorYoshi Cheng-Hao Huang <allstars.chh@gmail.com>
Thu, 16 Sep 2021 14:47:02 +0000
changeset 592197 e003632d9854593b290ccebc7e666bef7e909cc1
parent 592196 2a14ebd378cab683cdb02c5cc8d238d5182d456b
child 592198 2bf981a5af72f2fd517ac5aff34c6d32d960bce6
push id149854
push userallstars.chh@gmail.com
push dateThu, 16 Sep 2021 14:49:43 +0000
treeherderautoland@e5f2a2c79161 [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 2: Add NumberPart.h. r=platform-i18n-reviewers,anba,dminor Differential Revision: https://phabricator.services.mozilla.com/D125684
intl/components/moz.build
intl/components/src/NumberFormatFields.h
intl/components/src/NumberFormatFieldsUtil.h
intl/components/src/NumberPart.h
intl/components/src/RelativeTimeFormat.h
js/src/builtin/intl/RelativeTimeFormat.h
--- a/intl/components/moz.build
+++ b/intl/components/moz.build
@@ -9,16 +9,17 @@ EXPORTS.mozilla.intl = [
     "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",
     "src/Collator.cpp",
--- a/intl/components/src/NumberFormatFields.h
+++ b/intl/components/src/NumberFormatFields.h
@@ -1,61 +1,24 @@
 /* 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/. */
 #ifndef intl_components_NumberFormatFields_h_
 #define intl_components_NumberFormatFields_h_
 #include "mozilla/intl/ICUError.h"
+#include "mozilla/intl/NumberPart.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/Result.h"
 #include "mozilla/Vector.h"
 
 struct UFormattedNumber;
 struct UFormattedValue;
 
 namespace mozilla::intl {
 
-enum class NumberPartType : int16_t {
-  ApproximatelySign,
-  Compact,
-  Currency,
-  Decimal,
-  ExponentInteger,
-  ExponentMinusSign,
-  ExponentSeparator,
-  Fraction,
-  Group,
-  Infinity,
-  Integer,
-  Literal,
-  MinusSign,
-  Nan,
-  Percent,
-  PlusSign,
-  Unit,
-};
-
-enum class NumberPartSource : int16_t { Shared, Start, End };
-
-// Because parts fully partition the formatted string, we only track the
-// index of the end of each part -- the beginning is implicitly the last
-// part's end.
-struct NumberPart {
-  NumberPartType type;
-  NumberPartSource source;
-  size_t endIndex;
-
-  bool operator==(const NumberPart& rhs) const {
-    return type == rhs.type && source == rhs.source && endIndex == rhs.endIndex;
-  }
-  bool operator!=(const NumberPart& rhs) const { return !(*this == rhs); }
-};
-
-using NumberPartVector = mozilla::Vector<NumberPart, 8>;
-
 struct NumberFormatField {
   uint32_t begin;
   uint32_t end;
   NumberPartType type;
 
   // Needed for vector-resizing scratch space.
   NumberFormatField() = default;
 
--- a/intl/components/src/NumberFormatFieldsUtil.h
+++ b/intl/components/src/NumberFormatFieldsUtil.h
@@ -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/. */
 #ifndef intl_components_NumberFormatFieldsUtil_h_
 #define intl_components_NumberFormatFieldsUtil_h_
 
+#include "mozilla/intl/NumberPart.h"
 #include "mozilla/Maybe.h"
 
 #include "unicode/unum.h"
 
 namespace mozilla::intl {
 
 Maybe<NumberPartType> GetPartTypeForNumberField(UNumberFormatFields fieldName,
                                                 Maybe<double> number,
new file mode 100644
--- /dev/null
+++ b/intl/components/src/NumberPart.h
@@ -0,0 +1,53 @@
+/* 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/. */
+#ifndef intl_components_NumberPart_h_
+#define intl_components_NumberPart_h_
+
+#include <cstddef>
+#include <cstdint>
+
+#include "mozilla/Vector.h"
+
+namespace mozilla::intl {
+
+enum class NumberPartType : int16_t {
+  ApproximatelySign,
+  Compact,
+  Currency,
+  Decimal,
+  ExponentInteger,
+  ExponentMinusSign,
+  ExponentSeparator,
+  Fraction,
+  Group,
+  Infinity,
+  Integer,
+  Literal,
+  MinusSign,
+  Nan,
+  Percent,
+  PlusSign,
+  Unit,
+};
+
+enum class NumberPartSource : int16_t { Shared, Start, End };
+
+// Because parts fully partition the formatted string, we only track the
+// index of the end of each part -- the beginning is implicitly the last
+// part's end.
+struct NumberPart {
+  NumberPartType type;
+  NumberPartSource source;
+  size_t endIndex;
+
+  bool operator==(const NumberPart& rhs) const {
+    return type == rhs.type && source == rhs.source && endIndex == rhs.endIndex;
+  }
+  bool operator!=(const NumberPart& rhs) const { return !(*this == rhs); }
+};
+
+using NumberPartVector = mozilla::Vector<NumberPart, 8>;
+
+}  // namespace mozilla::intl
+#endif
--- a/intl/components/src/RelativeTimeFormat.h
+++ b/intl/components/src/RelativeTimeFormat.h
@@ -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/. */
 #ifndef intl_components_RelativeTimeFormat_h_
 #define intl_components_RelativeTimeFormat_h_
 
 #include "mozilla/intl/ICU4CGlue.h"
 #include "mozilla/intl/ICUError.h"
-#include "mozilla/intl/NumberFormatFields.h"
+#include "mozilla/intl/NumberPart.h"
 
 #include "unicode/ureldatefmt.h"
 #include "unicode/utypes.h"
 
 namespace mozilla::intl {
 
 struct RelativeTimeFormatOptions {
   enum class Style { Short, Narrow, Long };
--- a/js/src/builtin/intl/RelativeTimeFormat.h
+++ b/js/src/builtin/intl/RelativeTimeFormat.h
@@ -2,17 +2,17 @@
  * vim: set ts=8 sts=2 et sw=2 tw=80:
  * 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/. */
 
 #ifndef builtin_intl_RelativeTimeFormat_h
 #define builtin_intl_RelativeTimeFormat_h
 
-#include "mozilla/intl/NumberFormatFields.h"
+#include "mozilla/intl/NumberPart.h"
 
 #include <stdint.h>
 
 #include "builtin/SelfHostingDefines.h"
 #include "gc/Barrier.h"
 #include "js/Class.h"
 #include "vm/NativeObject.h"
 #include "vm/Runtime.h"