зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1735352 - Part 2: Add String::GetUnicodeVersion(). r=platform-i18n-reviewers,gregtatum
Adds a method to retrieve `U_UNICODE_VERSION` to `mozilla::intl::String`. Depends on D128226 Differential Revision: https://phabricator.services.mozilla.com/D128227
This commit is contained in:
Родитель
d65723b692
Коммит
e5bef00d2b
|
@ -5,6 +5,9 @@
|
|||
|
||||
#include "mozilla/intl/String.h"
|
||||
#include "mozilla/Span.h"
|
||||
#include "mozilla/TextUtils.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "TestBuffer.h"
|
||||
|
||||
|
@ -236,4 +239,13 @@ TEST(IntlString, IsCaseIgnorable)
|
|||
ASSERT_TRUE(String::IsCaseIgnorable(U'.'));
|
||||
}
|
||||
|
||||
TEST(IntlString, GetUnicodeVersion)
|
||||
{
|
||||
auto version = String::GetUnicodeVersion();
|
||||
|
||||
ASSERT_TRUE(std::all_of(version.begin(), version.end(), [](char ch) {
|
||||
return IsAsciiDigit(ch) || ch == '.';
|
||||
}));
|
||||
}
|
||||
|
||||
} // namespace mozilla::intl
|
||||
|
|
|
@ -42,6 +42,7 @@ UNIFIED_SOURCES += [
|
|||
"src/NumberRangeFormat.cpp",
|
||||
"src/PluralRules.cpp",
|
||||
"src/RelativeTimeFormat.cpp",
|
||||
"src/String.cpp",
|
||||
"src/TimeZone.cpp",
|
||||
]
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
/* 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/String.h"
|
||||
|
||||
namespace mozilla::intl {
|
||||
|
||||
Span<const char> String::GetUnicodeVersion() {
|
||||
return MakeStringSpan(U_UNICODE_VERSION);
|
||||
}
|
||||
|
||||
} // namespace mozilla::intl
|
|
@ -243,6 +243,11 @@ class String final {
|
|||
utext_close(&text);
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Unicode version, for example "13.0".
|
||||
*/
|
||||
static Span<const char> GetUnicodeVersion();
|
||||
};
|
||||
|
||||
} // namespace mozilla::intl
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "mozilla/FloatingPoint.h"
|
||||
#ifdef JS_HAS_INTL_API
|
||||
# include "mozilla/intl/Locale.h"
|
||||
# include "mozilla/intl/String.h"
|
||||
# include "mozilla/intl/TimeZone.h"
|
||||
#endif
|
||||
#include "mozilla/Maybe.h"
|
||||
|
@ -103,7 +104,6 @@
|
|||
#include "js/Wrapper.h"
|
||||
#include "threading/CpuCount.h"
|
||||
#ifdef JS_HAS_INTL_API
|
||||
# include "unicode/uchar.h"
|
||||
# include "unicode/uversion.h"
|
||||
#endif
|
||||
#include "util/DifferentialTesting.h"
|
||||
|
@ -7326,7 +7326,7 @@ static bool GetICUOptions(JSContext* cx, unsigned argc, Value* vp) {
|
|||
return false;
|
||||
}
|
||||
|
||||
str = NewStringCopyZ<CanGC>(cx, U_UNICODE_VERSION);
|
||||
str = NewStringCopy<CanGC>(cx, mozilla::intl::String::GetUnicodeVersion());
|
||||
if (!str || !JS_DefineProperty(cx, info, "unicode", str, JSPROP_ENUMERATE)) {
|
||||
return false;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче