This is useful for the following parts, as UniqueFileHandle is a cross-platform
type which can also be used to support transferring HANDLEs between processes.
This change requires fairly sweeping changes to existing callsites, which
previously did not require owning access to the handle types when transferring.
For the most part these changes were straightforward, but manual.
Differential Revision: https://phabricator.services.mozilla.com/D126564
LineBreaker has no member variables and acts like "namespaces" with
utility functions. Therefore, its methods can be static and called
directly without needing a LineBreaker instance.
Rename GetJISx4051Breaks() to ComputeBreakPositions() per review
feedbacks.
Differential Revision: https://phabricator.services.mozilla.com/D129107
After removing Prev() in Bug 1733009, WordMove()'s argument aDirection
now always equals to 1 passed from its remaining caller Next(). Thus, we
can expand WordMove() within Next(), and simply the logic.
Differential Revision: https://phabricator.services.mozilla.com/D129361
The original code was created before bug 1583953 and at that point of time, the
`Span` operators where still costly to call due to release-assertions overhead.
With the release assertions removed, the `Span` operators are now just as efficient
as manually calling `std::char_traits`. (Both will compile down to plain `memcmp`
calls.) But compared to using `std::char_traits`, the `Span` operators are more
ergonomic to use and result in less written code.
Depends on D129036
Differential Revision: https://phabricator.services.mozilla.com/D129037
We no longer need to null-terminate the result of `CallLikelySubtags`, because
the computed string isn't passed back to ICU anymore. Also update `AssignFromLocaleId`
now that the string isn't null-terminated anymore.
Differential Revision: https://phabricator.services.mozilla.com/D129036
Add a mozilla::intl::DateIntervalFormat class, with two methods:
- TryFormatCalendar
- TryFormatDateTime
and a mozilla::intl::AutoFormattedDateInterval class, which is a RAII
class calling udtitvfmt_openResult and udtitvfmt_closeResult for
DateIntervalFormat operations.
Differential Revision: https://phabricator.services.mozilla.com/D125642
There is also a mozilla::intl::Locale in intl/locale/MozLocale.h. This naming
collision was causing crashes in debug builds where the wrong destructor ended
up being called. This patch renames the intl/locale/MozLocale.h class to
MozLocale.
I've filed Bug 1736017 to move callers of the MozLocale version to the
unified intl/components/Locale version.
Differential Revision: https://phabricator.services.mozilla.com/D128593
This updates the script to generate intl/components/LocaleGenerated.cpp. I've
also tried to make it better match clang-format's style in places where that
wasn't too challenging.
Differential Revision: https://phabricator.services.mozilla.com/D126989
This moves the LanguageTag implementation from js/src/builtin/intl to
intl/components and renames them to Locale. The next commit will add
them to the build system.
Differential Revision: https://phabricator.services.mozilla.com/D126982
Some functions are accepting `Span<const char>` and expect that the underlying
`const char*` is null-terminated. Add an assertion that the string is really
null-terminated before passing it to ICU.
And then fix-up any issues where the string span is including the null
terminator. Also see bug 1660161.
Differential Revision: https://phabricator.services.mozilla.com/D127091
So with this patch FillVectorWithICUCall could become an overload of FillBufferWithICUCall,
with the buffer type is mozilla::Vector.
The callers of mozilla::intl could provide a mozilla::Vector as the
buffer, instead of creating some buffer adapter like nsTArrayU8Buffer,
TestBuffer, or FormatBuffer.
Differential Revision: https://phabricator.services.mozilla.com/D128240
So with this patch FillVectorWithICUCall could become an overload of FillBufferWithICUCall,
with the buffer type is mozilla::Vector.
The callers of mozilla::intl could provide a mozilla::Vector as the
buffer, instead of creating some buffer adapter like nsTArrayU8Buffer,
TestBuffer, or FormatBuffer.
Differential Revision: https://phabricator.services.mozilla.com/D128240
So with this patch FillVectorWithICUCall could become an overload of FillBufferWithICUCall,
with the buffer type is mozilla::Vector.
The callers of mozilla::intl could provide a mozilla::Vector as the
buffer, instead of creating some buffer adapter like nsTArrayU8Buffer,
TestBuffer, or FormatBuffer.
Differential Revision: https://phabricator.services.mozilla.com/D128240
This updates the script to generate intl/components/LocaleGenerated.cpp. I've
also tried to make it better match clang-format's style in places where that
wasn't too challenging.
Differential Revision: https://phabricator.services.mozilla.com/D126989
This moves the LanguageTag implementation from js/src/builtin/intl to
intl/components and renames them to Locale. The next commit will add
them to the build system.
Differential Revision: https://phabricator.services.mozilla.com/D126982
Adds abstractions for `u_init()`, `u_cleanup()`, and `u_setMemoryFunctions()`,
and additionally a method to retrieve `U_ICU_VERSION`.
Because these methods are unlikely to replaceable with ICU4X, the class was
named "ICU4CLibrary" to make clear that the functionality is specific to ICU4C.
Differential Revision: https://phabricator.services.mozilla.com/D128228
This patch is similar to Bug 1728708 Part 4, but for line breaker. This
should make the future integration of ICU4X line segmenter easier. A
UAX14 compatible line breaker always breaks at the end of text
(rule LB3 [1]), and ICU4X line segmenter has this behavior, too.
Current LineBreaker::Next() doesn't treat the end of text as a line
break opportunity, so this patch deprecates it by renaming it, and add a
new Next() method.
TestASCIILB() has adopted the new Next(). All the other callers of the
DeprecatedNext (nsPlainTextSerializer, nsXMLContentSerializer,
InternetCiter) should be audited later, possibly with the removal of
Prev() because the all the usages are very close to Prev().
[1] https://www.unicode.org/reports/tr14/#LB3
Differential Revision: https://phabricator.services.mozilla.com/D127379
After Bug 1728708 Part 4 [1], WordBreaker always breaks at the end of
text. Therefore, we don't need to manually record the end of text as a
word break opportunity when we see NS_WORDBREAKER_NEED_MORE_TEXT.
Also, modernize the interface of each functions by using mozilla::Span
to remove the needs to pass array length as parameters.
[1] https://hg.mozilla.org/mozilla-central/rev/55efff2d5628
Differential Revision: https://phabricator.services.mozilla.com/D127378
Add a wrapper for `ucal_getHostTimeZone` to `mozilla::intl::TimeZone`. This
function is only used for the "testing" function framework.
Differential Revision: https://phabricator.services.mozilla.com/D126198
Add setters to change ICU's default time zone.
1. `SetDefaultTimeZone()` sets the default time zone from a time zone identifier.
2. `SetDefaultTimeZoneFromHostTimeZone()` synchronizes the default time zone with
the host system's time zone.
The two new methods will be used in the next part to replace ICU calls in
`js::DateTimeInfo::internalResyncICUDefaultTimeZone()`.
Differential Revision: https://phabricator.services.mozilla.com/D126196
ICU doesn't provide a C-API for time zone functions, but instead requires to
use `UCalendar`. This adds a noticeable overhead, because whenever time zone
offsets are computed, it's first necessary to set the time on a `UCalendar`,
which triggers a recomputation of all calendar fields. And because time zone
offset computation is used for JavaScript's `Date`, which is widely used, we
should avoid performance regressions compared to the current code which is
using the ICU C++ API.
We can only safely use the ICU C++ API when we don't use the system ICU,
because C++ doesn't have a stable ABI, so the ICU C++ API code paths are only
taken when `MOZ_SYSTEM_ICU` is `false`.
Differential Revision: https://phabricator.services.mozilla.com/D126192
Add four additional methods to `mozilla::intl::TimeZone`:
1. `GetDSTOffsetMs()` to return the daylight saving offset at a specific UTC time.
2. `GetOffsetMs()` to return the time zone offset at a specific UTC time.
3. `GetUTCOffsetMs()` to return the UTC offset at a specific local time.
4. `GetDisplayName()` to return the display name of a time zone.
All four methods will be used to replace ICU calls in "js/src/vm/DateTime.cpp".
Differential Revision: https://phabricator.services.mozilla.com/D126191
Use `mozilla::intl::Calendar` instead of directly calling ICU in
`intl_GetCalendarInfo`. This implies that the days of the week are now ordered
the same way as in the "Intl Locale Info API" and the "Temporal" proposal, i.e.
starting from Monday=1 to Sunday=7.
Differential Revision: https://phabricator.services.mozilla.com/D126228
Returning an array matches the current "Intl Locale Info API" proposal and
actually also simplifies the single user of this function.
Differential Revision: https://phabricator.services.mozilla.com/D126227
The filter type is `UCAL_ZONE_TYPE_ANY` to ensure all possible time zones are
returned, and not just CLDR canonical time zones. (CLDR canonical time zones
are different from IANA canonical time zones.)
Differential Revision: https://phabricator.services.mozilla.com/D125576
- `TimeZone` objects can be created with any time zone identifier, so the "Default"
part in the name isn't correct.
- The "TimeZone" part is no longer needed, now that there's a distinct class for
`TimeZone` objects.
Therefore let's rename `GetDefaultTimeZoneOffsetMs()` to `GetRawOffsetMs()`.
Differential Revision: https://phabricator.services.mozilla.com/D125575
Time zone functions being part of `UCalendar` is an internal implementation
detail of ICU4C. For the public unified Intl API we should rather follow
Temporal (or ICU4C's C++ API) and have a separate `TimeZone` class.
The files were moved using `hg cp` to preserve the file history.
Differential Revision: https://phabricator.services.mozilla.com/D125574
ICU's public API only provides a function to return the preferred hour cycle
(`udatpg_getDefaultHourCycle()`), whereas for `Intl.Locale` we want to be able
to determine all allowed hour cycles. So we have to do it the hard way and
directly read ICU resource bundles to get the data we need for this feature.
Differential Revision: https://phabricator.services.mozilla.com/D125571
Currently only provides a single method to retrieve all available measurement units.
`MeasureUnit::GetAvailable()` returns an enumeration similar to the other Intl
classes which use `intl::Enumeration`. This approach gives us a more consistent
API, because it abstracts away the internal ICU implementation, which looks up
the measurement units through `UResourceBundle`. But it also means the
implementation is slightly more complicated due to this additional abstraction.
The default constructor was deleted because all methods are static.
Differential Revision: https://phabricator.services.mozilla.com/D125966
Currently only provides a single method to retrieve all ISO currency codes.
The default constructor was deleted because all methods are static.
Depends on D125674
Differential Revision: https://phabricator.services.mozilla.com/D125675
In contrast to the existing `GetBcp47KeywordValuesForLocale()` method, this
method returns all possible collation types, even the ones which aren't supported
by a specific locale.
Depends on D125672
Differential Revision: https://phabricator.services.mozilla.com/D125673
The motivation of this patch is to remove rarely used API in
WordBreaker. WordBreaker::BreakInBetween() is used only in
nsFind::BreakInBetween() in production, and it can be replaced by
Next().
If the user wants to know whether there is a word break between two
strings such as the use cases in gtest, joining the two strings and
passing the result to Next() is the preferred way.
Note: I delete the buggy forward word search algorithm in
TestFindWordBreakFromPosition() because from the test expectations, it
doesn't expect to continue the search in previous fragments. Also, the
buggy part comes from the following code, which had undefined behavior
before Part 4, and does nothing after Part 4.
```
wbk->FindWord(prevFragText.get(), prevFragText.Length(), prevFragText.Length());
```
Differential Revision: https://phabricator.services.mozilla.com/D125151
* Rename arguments so that their names are consistent with Next().
* Make the function not assert on an empty string, i.e. aLen == 0, like
Next().
* Fix an undefined behavior when the user passes aTextLen == aOffset.
The methods used to access `aText[aOffset]` that is clearly out of range
because the string may not be null-terminated. After this patch, it
returns a sentinel WordRange when aLen == aPos.
* Add document and gtest TestFindWordWithEmptyString().
* Change the sentinel return value to {aLen,aLen} for FindWord(), and
adapt one caller.
Differential Revision: https://phabricator.services.mozilla.com/D125434
The function is added in Bug 1728708 Part 4, but it never get called, so
this patch transforms it into a test in WordBreak test suite to make it
run.
While I'm here, other individual functions are also transformed into
tests so that we can have more granular results if some of them failed.
Differential Revision: https://phabricator.services.mozilla.com/D125148
This patch will probably not compile on its own, but requires the SpiderMonkey
side as well. It aims at building a components bag interface that can be
then used in SpiderMonkey to back the ECMA 402 API.
Differential Revision: https://phabricator.services.mozilla.com/D123822
This patch will not compile. It naively copies over the hour cycle code
from SpiderMonkey into the unified components. In a following patch,
these will be modified to use only the unified types.
Differential Revision: https://phabricator.services.mozilla.com/D123821
As discussed in https://bugzilla.mozilla.org/show_bug.cgi?id=1719747#c6,
In Part 1, the ownership of the Span in PartsVector is maintained by
ICU. This method adds a callback so js::intl::ListFormat could copy the
content of the Span to Spidermonkey, and mozilla::intl::ListFormat could
use ScopedICUObject to release the string owned by ICU earlier.
Differential Revision: https://phabricator.services.mozilla.com/D123166