Граф коммитов

48 Коммитов

Автор SHA1 Сообщение Дата
André Bargull 4741c41fed Bug 1648137 - Part 18: Add decimal number and formatToParts support to NumberRangeFormat. r=platform-i18n-reviewers,nordzilla
These new functions match the similarily named functions on `intl::NumberFormat`.

Also add some assertions to `NumberFormat::formatToParts()` when called with
decimal number strings to ensure non-finite number strings aren't used here,
because we always pass `Nothing()` for the number in this method.

Differential Revision: https://phabricator.services.mozilla.com/D119758
2021-08-24 09:34:52 +00:00
André Bargull 777449a2c5 Bug 1648137 - Part 17: Add separate number range options struct. r=platform-i18n-reviewers,nordzilla
`NumberFormatterSkeleton::toRangeFormatter()` receives the two additional options
as extra parameters, because that's simpler to implement compared to storing the
`NumberRangeFormatOptions` struct in `NumberFormatterSkeleton`. We can revisit
this approach should `NumberRangeFormatOptions` ever get more additional options.

Differential Revision: https://phabricator.services.mozilla.com/D119757
2021-08-24 09:34:52 +00:00
André Bargull 982d8dbbbf Bug 1648137 - Part 15: Record the source of a number part. r=platform-i18n-reviewers,nordzilla
Add `NumberPartSource` to `NumberPart` in preparation for part 18.

Also changes the underlying type of `NumberPartType` to `int16_t` to ensure the
size of `NumberPart` doesn't change on 32-bit platforms when adding
`NumberPartSource`. (Note: `sizeof(NumberPart)` is 16 on 64-platforms with or
without this change.)

Differential Revision: https://phabricator.services.mozilla.com/D119755
2021-08-24 09:34:51 +00:00
André Bargull 52d6dde648 Bug 1648137 - Part 14: Make NumberPart a proper struct. r=platform-i18n-reviewers,dminor
In the next part of this patch stack, we want to record the "source" of a
number part. The source is used when formatting number ranges to record if the
formatted number part belongs to the start resp. end of the number range.

Differential Revision: https://phabricator.services.mozilla.com/D119754
2021-08-24 09:34:50 +00:00
André Bargull 59f5314db5 Bug 1648137 - Part 13: Move GetPartTypeForNumberField into NumberFormatFields.h. r=platform-i18n-reviewers,dminor
Change `GetPartTypeForNumberField` to a free function so a later part in this
patch stack can call it when processing number ranges.

Differential Revision: https://phabricator.services.mozilla.com/D119753
2021-08-24 09:34:50 +00:00
André Bargull e6e2c90a1e Bug 1648137 - Part 12: Add support for formatting number strings. r=tcampbell
The "Intl.NumberFormat v3 API" proposal adds support to format arbitrarily large
decimal numbers. For example it's now possible to format the decimal number
1e1000 by passing the string `"1e1000"` to the `format` function.

`ToIntlMathematicalValue()` preprocesses the number as follows:
- Non-finite values (NaN and infinities) are always stored as `double` values.
- Positive and negative zero are also stored as `double` values.
- Non-decimal strings like `"0x10"` are stored as BigInts, because ICU only
  supports decimal number strings.
- An error is thrown if the exponent is too large to workaround ICU limitations.

Normalising non-finite values and ±0 is done in preparation for part 17.

Differential Revision: https://phabricator.services.mozilla.com/D119752
2021-08-24 09:34:50 +00:00
André Bargull 93782a6021 Bug 1648137 - Part 9: Add support for roundingPriority option to intl::NumberFormat. r=platform-i18n-reviewers,dminor
The rounding priority names match the names in the Intl proposal.

Differential Revision: https://phabricator.services.mozilla.com/D119749
2021-08-24 09:34:49 +00:00
André Bargull e1b120bd3d Bug 1648137 - Part 7: Add support for new useGrouping value options to intl::NumberFormat. r=platform-i18n-reviewers,dminor
Change `mUseGrouping` to `mGrouping` and use an `enum` to represent the two
new additional modes "Always" and "Min2".

Differential Revision: https://phabricator.services.mozilla.com/D119747
2021-08-24 09:34:48 +00:00
André Bargull 83a11eb7f8 Bug 1648137 - Part 5: Add support for roundingIncrement, roundingMode, and trailingZeroDisplay options to intl::NumberFormat. r=platform-i18n-reviewers,dminor
First set of new options added in the "Intl.NumberFormat v3 API" proposal.

- All ICU rounding modes are added. (The Intl proposal doesn't support "HalfOdd".)
- The rounding mode names match the names in the Intl proposal, which are
  different compared to the ICU names.
- Significant digits options are ignored when rounding increment is used. This is
  an ICU limitation. The Intl proposal will throw an error if both options are
  used at the same time.

Differential Revision: https://phabricator.services.mozilla.com/D119745
2021-08-24 09:34:47 +00:00
André Bargull b921491f4b Bug 1648137 - Part 2: Add PluralRules::SelectRange(). r=dminor,platform-i18n-reviewers,nordzilla
Add `intl::NumberRangeFormat` based on the existing `intl::NumberFormat` class
and use it to implement `intl::PluralRules::SelectRange()`.

Most ICU number range formatting functions are still draft APIs and therefore
are guarded by `#ifndef U_HIDE_DRAFT_API`. Instead of requiring `mozilla::intl`
users to also use `U_HIDE_DRAFT_API`, add two additional preprocessor definitions
(`MOZ_INTL_PLURAL_RULES_HAS_SELECT_RANGE` and `MOZ_INTL_HAS_NUMBER_RANGE_FORMAT`).

When `MOZ_INTL_HAS_NUMBER_RANGE_FORMAT` isn't defined, `intl::NumberRangeFormat`
is an empty class. We could also hide the complete class if the preprocessor
guard isn't defined, but the other approach results in fewer `#ifdef` guards.

Differential Revision: https://phabricator.services.mozilla.com/D119742
2021-08-24 09:34:46 +00:00
André Bargull d2bbf86876 Bug 1726123 - Part 5: Add missing "js/" includes outside of SM. r=arai
In preparation for the next part, add missing includes to "js/" public headers.

Differential Revision: https://phabricator.services.mozilla.com/D122843
2021-08-17 15:45:39 +00:00
Greg Tatum b41f145a38 Bug 1719550 - Add support for BCP 47 extensions to mozilla::intl::Collator; r=platform-i18n-reviewers,nordzilla
SpiderMonkey requires the BCP 47 locale extensions, which involves iterating
over the keywords in ICU, and mapping them to the BCP 47 version. Specifically,
this will change the "phonebook" keyword to "phonebk". This should hopefully
expose a simpler API to SpiderMonkey, the only consumer.

Differential Revision: https://phabricator.services.mozilla.com/D120903
2021-08-10 16:01:15 +00:00
Greg Tatum c2cf97af11 Bug 1719550 - Build an initial unified mozilla::intl::Collator; r=platform-i18n-reviewers,nordzilla
This collator attempts to match the options bag from the Intl.Collator API
from ECMA-402. It is built to be compatible and consistent across both Gecko
code and SpiderMonkey code. Its behavior is designed to match ECMA-402.

Differential Revision: https://phabricator.services.mozilla.com/D120494
2021-08-10 16:01:15 +00:00
Narcis Beleuzu daed5248e2 Backed out 12 changesets (bug 1719550) for bustages on TestCollator.cpp . CLOSED TREE
Backed out changeset 3b2735a29138 (bug 1719550)
Backed out changeset 5e2019335244 (bug 1719550)
Backed out changeset 105676dd2d6f (bug 1719550)
Backed out changeset b4b0d58778e9 (bug 1719550)
Backed out changeset 3ef5792020bb (bug 1719550)
Backed out changeset 389a77da6ddc (bug 1719550)
Backed out changeset 48f39b5ef77f (bug 1719550)
Backed out changeset bd125cc5b9b4 (bug 1719550)
Backed out changeset a8b778ca2375 (bug 1719550)
Backed out changeset b14702168fb9 (bug 1719550)
Backed out changeset 7b46b5cc7424 (bug 1719550)
Backed out changeset 6b04162618a1 (bug 1719550)
2021-08-10 17:46:34 +03:00
Greg Tatum 1fb2daab2a Bug 1719550 - Add support for BCP 47 extensions to mozilla::intl::Collator; r=platform-i18n-reviewers,nordzilla
SpiderMonkey requires the BCP 47 locale extensions, which involves iterating
over the keywords in ICU, and mapping them to the BCP 47 version. Specifically,
this will change the "phonebook" keyword to "phonebk". This should hopefully
expose a simpler API to SpiderMonkey, the only consumer.

Differential Revision: https://phabricator.services.mozilla.com/D120903
2021-08-10 11:46:34 +00:00
Greg Tatum 0087d035b9 Bug 1719550 - Build an initial unified mozilla::intl::Collator; r=platform-i18n-reviewers,nordzilla
This collator attempts to match the options bag from the Intl.Collator API
from ECMA-402. It is built to be compatible and consistent across both Gecko
code and SpiderMonkey code. Its behavior is designed to match ECMA-402.

Differential Revision: https://phabricator.services.mozilla.com/D120494
2021-08-10 11:46:34 +00:00
Dan Minor 26b1e33737 Bug 1715595 - Use char rather than uint8_t for utf-8 in unified components r=platform-i18n-reviewers,gregtatum
Differential Revision: https://phabricator.services.mozilla.com/D120508
2021-07-23 14:58:00 +00:00
Erik Nordin 0990d59463 Bug 1719758 - Test result values before unwrapping in TestPluralRules r=platform-i18n-reviewers,dminor
Modifies TestPluralRules.cpp to assert that all result values are okay
before unwrapping them. Previously the test suite would crash if an
error result was unwrapped. Now it will fail the test and report the
failure.

Differential Revision: https://phabricator.services.mozilla.com/D119465
2021-07-09 17:49:38 +00:00
Greg Tatum 8c72f6e6ae Bug 1715979 - Do not leak ICU objects in mozilla:intl component moves; r=nordzilla
Differential Revision: https://phabricator.services.mozilla.com/D117569
2021-06-29 15:25:44 +00:00
Erik Nordin ed5c7b4262 Bug 1718345 - Add PluralRules tests for three-letter langids r=platform-i18n-reviewers,dminor
Differential Revision: https://phabricator.services.mozilla.com/D118869
2021-06-28 16:24:03 +00:00
André Bargull 90a85eee9f Bug 1284868: Adjust field widths for hour/minute/second when the user requested 2-digit representation. r=dminor
Change `DateTimePatternGenerator::GetBestPattern()` to call `udatpg_getBestPatternWithOptions()`,
so we can adjust the computed pattern to use 2-digit representation when it was requested by the
user.

Differential Revision: https://phabricator.services.mozilla.com/D118728
2021-06-28 13:20:44 +00:00
Dan Minor eeaf61de24 Bug 1715982 - Fix initial capacity of NumberPartVector; r=anba
Differential Revision: https://phabricator.services.mozilla.com/D117540
2021-06-11 21:22:15 +00:00
Greg Tatum 07cc89dd24 Bug 1711902 - Add Calendar::GetCanonicalTimeZoneID; r=dminor
This finishes the UCalendar unification in DateTimeFormat.cpp

Differential Revision: https://phabricator.services.mozilla.com/D116158
2021-06-10 20:14:17 +00:00
Greg Tatum db78fe91b5 Bug 1711902 - Unify most of UCalendar in SpiderMonkey; r=dminor,anba
This adds a bigger unification primitive of an Enumeration iterator over the
UEnumeration ICU type.

Differential Revision: https://phabricator.services.mozilla.com/D116157
2021-06-10 20:14:17 +00:00
Greg Tatum 23873163d1 Bug 1711902 - Unify the DateTimePatternGenerator in SpiderMonkey; r=dminor,anba
Differential Revision: https://phabricator.services.mozilla.com/D115731
2021-06-10 20:14:17 +00:00
Greg Tatum cb9860735f Bug 1711902 - Remove UDateFormat from SpiderMonkey; r=dminor,anba
This patch starts the work of unifying the DateTimeFormat. It removes the uses
of UDateFormat.

Differential Revision: https://phabricator.services.mozilla.com/D115730
2021-06-10 20:14:16 +00:00
Greg Tatum efe295fd94 Bug 1711902 - Add a FormatBuffer for use in SpiderMonkey; r=anba
Differential Revision: https://phabricator.services.mozilla.com/D116911
2021-06-10 20:14:16 +00:00
Erik Nordin 875656873e Bug 1704509 - Add Unified PuralRules Impl For SpiderMonkey r=anba,dminor
- Adds mozilla::intl::PluralRules
    - Modifies SpiderMonkey code to use PluralRules.
    - Adds gtest suite for PluralRules

Differential Revision: https://phabricator.services.mozilla.com/D115783
2021-06-09 19:04:54 +00:00
Greg Tatum bf5ee6077d Bug 1705156 - Add a unified DateTimeFormat component; r=dminor,anba
This patch adds a DateTimeFormat class for use in the unified
internationalization API. Currently it's only targeting the
ICU code in the Fluent API. The plan is to use it in the Fluent DOM
code, as well as in SpiderMonkey as a centralized API for performing
datetime formatting.

Differential Revision: https://phabricator.services.mozilla.com/D114114
2021-05-27 23:03:43 +00:00
Dan Minor 0452666d00 Bug 1701695 - Add NumberFormat::TryCreate; r=tcampbell
This adds a fallible factory method to create new NumberFormat instances. This
allows us to report initialization errors at time of initialization, rather than
when format is called, and remove internal checks in the implementation for
successful initialization.

The existing fluent code assumes that creating a NumberFormat instance always
succeeds. This patch updates that code to handle failures.

Differential Revision: https://phabricator.services.mozilla.com/D114593
2021-05-12 17:22:51 +00:00
Dan Minor 3b533cd007 Bug 1701695 - Add documentation to NumberFormat.h; r=gregtatum,nordzilla
Differential Revision: https://phabricator.services.mozilla.com/D113145
2021-05-12 17:22:51 +00:00
Dan Minor 5f755ac1ab Bug 1701695 - Use intl::NumberFormatterSkeleton in PluralRules r=tcampbell
This temporarily adds intl::NumberFormatterSkeleton to the public API so that
we can use it in PluralRules. This allows us to remove the SpiderMonkey
NumberFormatterSkeleton implementation when we convert SpiderMonkey to use
intl::NumberFormat.

We can remove intl::NumberFormatterSkeleton from the public API when we
implement intl::PluralRules in Bug 1704509.

Differential Revision: https://phabricator.services.mozilla.com/D111887
2021-05-12 17:22:50 +00:00
Dan Minor d5183e8bf1 Bug 1701695 - Add support for format to parts to intl::NumberFormat r=gregtatum,tcampbell,anba
Differential Revision: https://phabricator.services.mozilla.com/D111886
2021-05-12 17:22:49 +00:00
Dan Minor 4b3bf83c4b Bug 1701695 - Restore [[nodiscard]] annotations to NumberFormatterSkeleton; r=gregtatum
I foolishly dropped these when bringing the code over from SpiderMonkey.

Differential Revision: https://phabricator.services.mozilla.com/D113558
2021-05-12 17:22:49 +00:00
Dan Minor afc8a3b58a Bug 1701695 - Rename NumberFormatOptions::CurrencyDisplayStyle; r=gregtatum
This should be CurrencyDisplay to be consistent with ecma-402.

Differential Revision: https://phabricator.services.mozilla.com/D113557
2021-05-12 17:22:48 +00:00
Dan Minor 27dd93eb84 Bug 1701695 - Return std::u16string_view instead of char16_t* in intl::NumberFormat r=gregtatum
The SpiderMonkey call sites need both the pointer and the length when
copying/deflating the string, so this changes the API to expose the underlying
string_view.

While we're here, this updates the API to use mozilla::Result.

Differential Revision: https://phabricator.services.mozilla.com/D112801
2021-05-12 17:22:48 +00:00
Brindusan Cristian efd8dfd0cf Backed out 9 changesets (bug 1701695) for causing xpcshell failures in test_messagecontext.js. CLOSED TREE
Backed out changeset e88dd41c0a90 (bug 1701695)
Backed out changeset 823ed70ef5fe (bug 1701695)
Backed out changeset 11f97bc74622 (bug 1701695)
Backed out changeset fdf12ac55593 (bug 1701695)
Backed out changeset abcf774d3b58 (bug 1701695)
Backed out changeset 4239fe67d69f (bug 1701695)
Backed out changeset 216472b634b9 (bug 1701695)
Backed out changeset 89ff5f91d8e9 (bug 1701695)
Backed out changeset 9c0dbc73dad2 (bug 1701695)
2021-05-11 15:25:46 +03:00
Dan Minor 7a648a32c3 Bug 1701695 - Add NumberFormat::TryCreate; r=tcampbell
This adds a fallible factory method to create new NumberFormat instances. This
allows us to report initialization errors at time of initialization, rather than
when format is called, and remove internal checks in the implementation for
successful initialization.

The existing fluent code assumes that creating a NumberFormat instance always
succeeds. This patch updates that code to handle failures.

Differential Revision: https://phabricator.services.mozilla.com/D114593
2021-05-11 11:37:40 +00:00
Dan Minor 6eaea879f1 Bug 1701695 - Add documentation to NumberFormat.h; r=gregtatum,nordzilla
Differential Revision: https://phabricator.services.mozilla.com/D113145
2021-05-11 11:37:40 +00:00
Dan Minor 3322d3ceb6 Bug 1701695 - Use intl::NumberFormatterSkeleton in PluralRules r=tcampbell
This temporarily adds intl::NumberFormatterSkeleton to the public API so that
we can use it in PluralRules. This allows us to remove the SpiderMonkey
NumberFormatterSkeleton implementation when we convert SpiderMonkey to use
intl::NumberFormat.

We can remove intl::NumberFormatterSkeleton from the public API when we
implement intl::PluralRules in Bug 1704509.

Differential Revision: https://phabricator.services.mozilla.com/D111887
2021-05-11 11:37:38 +00:00
Dan Minor c6f5bbceb4 Bug 1701695 - Add support for format to parts to intl::NumberFormat r=gregtatum,tcampbell,anba
Differential Revision: https://phabricator.services.mozilla.com/D111886
2021-05-11 11:37:38 +00:00
Dan Minor 8cf0f1089a Bug 1701695 - Restore [[nodiscard]] annotations to NumberFormatterSkeleton; r=gregtatum
I foolishly dropped these when bringing the code over from SpiderMonkey.

Differential Revision: https://phabricator.services.mozilla.com/D113558
2021-05-11 11:37:38 +00:00
Dan Minor 72adfe7239 Bug 1701695 - Rename NumberFormatOptions::CurrencyDisplayStyle; r=gregtatum
This should be CurrencyDisplay to be consistent with ecma-402.

Differential Revision: https://phabricator.services.mozilla.com/D113557
2021-05-11 11:37:37 +00:00
Dan Minor 089ad0d14c Bug 1701695 - Return std::u16string_view instead of char16_t* in intl::NumberFormat r=gregtatum
The SpiderMonkey call sites need both the pointer and the length when
copying/deflating the string, so this changes the API to expose the underlying
string_view.

While we're here, this updates the API to use mozilla::Result.

Differential Revision: https://phabricator.services.mozilla.com/D112801
2021-05-11 11:37:37 +00:00
Dan Minor 28196b0645 Bug 1705363 - Fixes to intl::NumberFormatterSkeleton; r=gregtatum
These are fixes for issues noticed with NumberFormatterSkeleton while testing
this code in SpiderMonkey against the full set of intl tests there. I've added
minimal test cases for the issues encountered as part of this patch.

Differential Revision: https://phabricator.services.mozilla.com/D112240
2021-04-20 18:16:24 +00:00
Dan Minor 96711bfb68 Bug 1695937 - Add intl::NumberFormat to components; r=zbraniecki,tcampbell,jandem
This adds an initial version of NumberFormat that is suitable for use by
Fluent.

The options formatting code is taken from SpiderMonkey and modified to use the
standard c++ library rather than SpiderMonkey specific code. The code
generated MeasureUnitGenerated.h is duplicated here temporarily. Once we can
move SpiderMonkey to using this code, we can update the code generation to
avoid this duplication.

Some simple gtests have been written to make development easier. Full test
coverage is not a goal here, as this code will eventually be covered by running
test262 in SpiderMonkey.

Differential Revision: https://phabricator.services.mozilla.com/D107223
2021-04-08 14:56:33 +00:00
Butkovits Atila 15db4c5343 Backed out 2 changesets (bug 1695937) for causing bustages on FluentBundle.cpp.
Backed out changeset d17059c999a6 (bug 1695937)
Backed out changeset 232a570d6739 (bug 1695937)
2021-04-08 04:21:27 +03:00
Dan Minor 91e357191b Bug 1695937 - Add intl::NumberFormat to components; r=zbraniecki,tcampbell,jandem
This adds an initial version of NumberFormat that is suitable for use by
Fluent.

The options formatting code is taken from SpiderMonkey and modified to use the
standard c++ library rather than SpiderMonkey specific code. The code
generated MeasureUnitGenerated.h is duplicated here temporarily. Once we can
move SpiderMonkey to using this code, we can update the code generation to
avoid this duplication.

Some simple gtests have been written to make development easier. Full test
coverage is not a goal here, as this code will eventually be covered by running
test262 in SpiderMonkey.

Differential Revision: https://phabricator.services.mozilla.com/D107223
2021-04-07 20:03:22 +00:00