mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-07 03:32:53 +00:00
Previously, LibUnicode would store the values of a keyword as a Vector. For example, the locale "en-u-ca-abc-def" would have its keyword "ca" stored as {"abc, "def"}. Then, canonicalization would occur on each of the elements in that Vector. This is incorrect because, for example, the keyword value "true" should only be dropped if that is the entire value. That is, the canonical form of "en-u-kb-true" is "en-u-kb", but "en-u-kb-abc-true" does not change for canonicalization. However, we would canonicalize that locale as "en-u-kb-abc".
53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
|
#include <LibJS/Runtime/Intl/Locale.h>
|
|
#include <LibUnicode/Locale.h>
|
|
|
|
namespace JS::Intl {
|
|
|
|
Locale* Locale::create(GlobalObject& global_object, Unicode::LocaleID const& locale_id)
|
|
{
|
|
return global_object.heap().allocate<Locale>(global_object, locale_id, *global_object.intl_locale_prototype());
|
|
}
|
|
|
|
// 14 Locale Objects, https://tc39.es/ecma402/#locale-objects
|
|
Locale::Locale(Object& prototype)
|
|
: Object(prototype)
|
|
{
|
|
}
|
|
|
|
Locale::Locale(Unicode::LocaleID const& locale_id, Object& prototype)
|
|
: Object(prototype)
|
|
{
|
|
set_locale(locale_id.to_string());
|
|
|
|
for (auto const& extension : locale_id.extensions) {
|
|
if (!extension.has<Unicode::LocaleExtension>())
|
|
continue;
|
|
|
|
for (auto const& keyword : extension.get<Unicode::LocaleExtension>().keywords) {
|
|
if (keyword.key == "ca"sv) {
|
|
set_calendar(keyword.value);
|
|
} else if (keyword.key == "co"sv) {
|
|
set_collation(keyword.value);
|
|
} else if (keyword.key == "hc"sv) {
|
|
set_hour_cycle(keyword.value);
|
|
} else if (keyword.key == "kf"sv) {
|
|
set_case_first(keyword.value);
|
|
} else if (keyword.key == "kn"sv) {
|
|
set_numeric(keyword.value.is_empty());
|
|
} else if (keyword.key == "nu"sv) {
|
|
set_numbering_system(keyword.value);
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|