mirror of https://github.com/boa-dev/boa.git
Browse Source
We currently use `unicode_normalization` to handle the `String.prototype.normalize` method. However, the crate doesn't support UTF-16 as a first class string, so we had to do some hacks by converting the valid parts of a string to UTF-8, normalizing each one, encoding back to UTF-16 and concatenating everything with the unpaired surrogates within. All of this is obviously suboptimal for performance, which is why I leveraged the `icu_normalizer`, which does support UTF-16 input, to replace our current implementation. Additionally, this allows users to override the default normalization data if the `intl` feature is enabled by providing the required data in the `BoaProvider` data provider.pull/2865/head
José Julián Espina
2 years ago
29 changed files with 655 additions and 115 deletions
@ -0,0 +1,2 @@
|
||||
// @generated
|
||||
impl_any_provider!(BakedDataProvider); |
@ -0,0 +1,6 @@
|
||||
// @generated
|
||||
type DataStruct = < :: icu_provider_adapters :: fallback :: provider :: LocaleFallbackLikelySubtagsV1Marker as :: icu_provider :: DataMarker > :: Yokeable ; |
||||
pub fn lookup(locale: &icu_provider::DataLocale) -> Option<&'static DataStruct> { |
||||
locale.is_empty().then(|| &UND) |
||||
} |
||||
static UND: DataStruct = include!("und.rs.data"); |
@ -0,0 +1,66 @@
|
||||
::icu_provider_adapters::fallback::provider::LocaleFallbackLikelySubtagsV1 { |
||||
l2s: unsafe { |
||||
#[allow(unused_unsafe)] |
||||
::zerovec::ZeroMap::from_parts_unchecked( |
||||
unsafe { |
||||
:: zerovec :: ZeroVec :: from_bytes_unchecked (b"am\0ar\0as\0be\0bg\0bgcbhobn\0brxchrcv\0doiel\0fa\0gu\0he\0hi\0hy\0ja\0ka\0kk\0km\0kn\0ko\0kokks\0ky\0lo\0maimk\0ml\0mn\0mnimr\0my\0ne\0or\0pa\0ps\0rajru\0sa\0satsd\0si\0sr\0ta\0te\0tg\0th\0ti\0tt\0uk\0ur\0yuezh\0") |
||||
}, |
||||
unsafe { |
||||
:: zerovec :: ZeroVec :: from_bytes_unchecked (b"EthiArabBengCyrlCyrlDevaDevaBengDevaCherCyrlDevaGrekArabGujrHebrDevaArmnJpanGeorCyrlKhmrKndaKoreDevaArabCyrlLaooDevaCyrlMlymCyrlBengDevaMymrDevaOryaGuruArabDevaCyrlDevaOlckArabSinhCyrlTamlTeluCyrlThaiEthiCyrlCyrlArabHantHans") |
||||
}, |
||||
) |
||||
}, |
||||
lr2s: unsafe { |
||||
#[allow(unused_unsafe)] |
||||
::zerovec::ZeroMap2d::from_parts_unchecked( |
||||
unsafe { |
||||
::zerovec::ZeroVec::from_bytes_unchecked( |
||||
b"az\0ha\0kk\0ky\0mn\0ms\0pa\0sd\0sr\0tg\0uz\0yuezh\0", |
||||
) |
||||
}, |
||||
unsafe { |
||||
:: zerovec :: ZeroVec :: from_bytes_unchecked (b"\x03\0\0\0\x05\0\0\0\t\0\0\0\x0B\0\0\0\x0C\0\0\0\r\0\0\0\x0E\0\0\0\x0F\0\0\0\x13\0\0\0\x14\0\0\0\x16\0\0\0\x17\0\0\0&\0\0\0") |
||||
}, |
||||
unsafe { |
||||
:: zerovec :: ZeroVec :: from_bytes_unchecked (b"IQ\0IR\0RU\0CM\0SD\0AF\0CN\0IR\0MN\0CN\0TR\0CN\0CC\0PK\0IN\0ME\0RO\0RU\0TR\0PK\0AF\0CN\0CN\0AU\0BN\0GB\0GF\0HK\0ID\0MO\0PA\0PF\0PH\0SR\0TH\0TW\0US\0VN\0") |
||||
}, |
||||
unsafe { |
||||
:: zerovec :: ZeroVec :: from_bytes_unchecked (b"ArabArabCyrlArabArabArabArabArabArabArabLatnMongArabArabDevaLatnLatnLatnLatnArabArabCyrlHansHantHantHantHantHantHantHantHantHantHantHantHantHantHantHant") |
||||
}, |
||||
) |
||||
}, |
||||
l2r: unsafe { |
||||
#[allow(unused_unsafe)] |
||||
::zerovec::ZeroMap::from_parts_unchecked( |
||||
unsafe { |
||||
:: zerovec :: ZeroVec :: from_bytes_unchecked (b"af\0am\0ar\0as\0astaz\0be\0bg\0bgcbhobn\0br\0brxbs\0ca\0cebchrcs\0cv\0cy\0da\0de\0doidsbel\0en\0es\0et\0eu\0fa\0ff\0fi\0filfo\0fr\0ga\0gd\0gl\0gu\0ha\0he\0hi\0hr\0hsbhu\0hy\0ia\0id\0ig\0is\0it\0ja\0jv\0ka\0keakgpkk\0km\0kn\0ko\0kokks\0ky\0lo\0lt\0lv\0maimi\0mk\0ml\0mn\0mnimr\0ms\0my\0ne\0nl\0nn\0no\0or\0pa\0pcmpl\0ps\0pt\0qu\0rajrm\0ro\0ru\0sa\0satsc\0sd\0si\0sk\0sl\0so\0sq\0sr\0su\0sv\0sw\0ta\0te\0tg\0th\0ti\0tk\0to\0tr\0tt\0uk\0ur\0uz\0vi\0wo\0xh\0yo\0yrlyuezh\0zu\0") |
||||
}, |
||||
unsafe { |
||||
:: zerovec :: ZeroVec :: from_bytes_unchecked (b"ZA\0ET\0EG\0IN\0ES\0AZ\0BY\0BG\0IN\0IN\0BD\0FR\0IN\0BA\0ES\0PH\0US\0CZ\0RU\0GB\0DK\0DE\0IN\0DE\0GR\0US\0ES\0EE\0ES\0IR\0SN\0FI\0PH\0FO\0FR\0IE\0GB\0ES\0IN\0NG\0IL\0IN\0HR\0DE\0HU\0AM\x00001ID\0NG\0IS\0IT\0JP\0ID\0GE\0CV\0BR\0KZ\0KH\0IN\0KR\0IN\0IN\0KG\0LA\0LT\0LV\0IN\0NZ\0MK\0IN\0MN\0IN\0IN\0MY\0MM\0NP\0NL\0NO\0NO\0IN\0IN\0NG\0PL\0AF\0BR\0PE\0IN\0CH\0RO\0RU\0IN\0IN\0IT\0PK\0LK\0SK\0SI\0SO\0AL\0RS\0ID\0SE\0TZ\0IN\0IN\0TJ\0TH\0ET\0TM\0TO\0TR\0RU\0UA\0PK\0UZ\0VN\0SN\0ZA\0NG\0BR\0HK\0CN\0ZA\0") |
||||
}, |
||||
) |
||||
}, |
||||
ls2r: unsafe { |
||||
#[allow(unused_unsafe)] |
||||
::zerovec::ZeroMap2d::from_parts_unchecked( |
||||
unsafe { |
||||
::zerovec::ZeroVec::from_bytes_unchecked( |
||||
b"az\0en\0ff\0kk\0ky\0mn\0pa\0sd\0tg\0uz\0yuezh\0", |
||||
) |
||||
}, |
||||
unsafe { |
||||
:: zerovec :: ZeroVec :: from_bytes_unchecked (b"\x01\0\0\0\x02\0\0\0\x03\0\0\0\x04\0\0\0\x06\0\0\0\x07\0\0\0\x08\0\0\0\x0B\0\0\0\x0C\0\0\0\r\0\0\0\x0E\0\0\0\x11\0\0\0") |
||||
}, |
||||
unsafe { |
||||
::zerovec::ZeroVec::from_bytes_unchecked( |
||||
b"ArabShawAdlmArabArabLatnMongArabDevaKhojSindArabArabHansBopoHanbHant", |
||||
) |
||||
}, |
||||
unsafe { |
||||
::zerovec::ZeroVec::from_bytes_unchecked( |
||||
b"IR\0GB\0GN\0CN\0CN\0TR\0CN\0PK\0IN\0IN\0IN\0PK\0AF\0CN\0TW\0TW\0TW\0", |
||||
) |
||||
}, |
||||
) |
||||
}, |
||||
} |
@ -0,0 +1,4 @@
|
||||
// @generated
|
||||
pub mod likelysubtags_v1; |
||||
pub mod parents_v1; |
||||
pub mod supplement; |
@ -0,0 +1,6 @@
|
||||
// @generated
|
||||
type DataStruct = < :: icu_provider_adapters :: fallback :: provider :: LocaleFallbackParentsV1Marker as :: icu_provider :: DataMarker > :: Yokeable ; |
||||
pub fn lookup(locale: &icu_provider::DataLocale) -> Option<&'static DataStruct> { |
||||
locale.is_empty().then(|| &UND) |
||||
} |
||||
static UND: DataStruct = include!("und.rs.data"); |
@ -0,0 +1,13 @@
|
||||
::icu_provider_adapters::fallback::provider::LocaleFallbackParentsV1 { |
||||
parents: unsafe { |
||||
#[allow(unused_unsafe)] |
||||
::zerovec::ZeroMap::from_parts_unchecked( |
||||
unsafe { |
||||
:: zerovec :: VarZeroVec :: from_bytes_unchecked (b"\x84\0\0\0\0\0\x06\0\x0B\0\x10\0\x15\0\x1A\0\x1F\0$\0)\0.\x003\08\0=\0B\0G\0L\0Q\0V\0[\0`\0e\0j\0o\0t\0y\0~\0\x83\0\x88\0\x8D\0\x92\0\x97\0\x9C\0\xA1\0\xA6\0\xAB\0\xB0\0\xB5\0\xBA\0\xBF\0\xC4\0\xC9\0\xCE\0\xD3\0\xD8\0\xDD\0\xE2\0\xE7\0\xEC\0\xF1\0\xF6\0\xFB\0\0\x01\x05\x01\n\x01\x0F\x01\x14\x01\x19\x01\x1E\x01#\x01(\x01-\x012\x017\x01<\x01A\x01F\x01K\x01P\x01U\x01Z\x01_\x01d\x01i\x01n\x01s\x01x\x01}\x01\x82\x01\x87\x01\x8C\x01\x91\x01\x96\x01\x9B\x01\xA0\x01\xA5\x01\xAA\x01\xAF\x01\xB4\x01\xB9\x01\xBE\x01\xC3\x01\xC8\x01\xCD\x01\xD2\x01\xD7\x01\xDC\x01\xE1\x01\xE6\x01\xEB\x01\xF0\x01\xF5\x01\xFA\x01\xFF\x01\x04\x02\t\x02\x0E\x02\x13\x02\x18\x02\x1D\x02\"\x02'\x02,\x021\x026\x02;\x02@\x02G\x02I\x02K\x02M\x02R\x02W\x02\\\x02a\x02f\x02k\x02p\x02u\x02z\x02\x7F\x02\x84\x02\x89\x02en-150en-AGen-AIen-ATen-AUen-BBen-BEen-BMen-BSen-BWen-BZen-CCen-CHen-CKen-CMen-CXen-CYen-DEen-DGen-DKen-DMen-ERen-FIen-FJen-FKen-FMen-GBen-GDen-GGen-GHen-GIen-GMen-GYen-HKen-IEen-ILen-IMen-INen-IOen-JEen-JMen-KEen-KIen-KNen-KYen-LCen-LRen-LSen-MGen-MOen-MSen-MTen-MUen-MVen-MWen-MYen-NAen-NFen-NGen-NLen-NRen-NUen-NZen-PGen-PKen-PNen-PWen-RWen-SBen-SCen-SDen-SEen-SGen-SHen-SIen-SLen-SSen-SXen-SZen-TCen-TKen-TOen-TTen-TVen-TZen-UGen-VCen-VGen-VUen-WSen-ZAen-ZMen-ZWes-ARes-BOes-BRes-BZes-CLes-COes-CRes-CUes-DOes-ECes-GTes-HNes-MXes-NIes-PAes-PEes-PRes-PYes-SVes-USes-UYes-VEhi-Latnhtnbnnno-NOpt-AOpt-CHpt-CVpt-FRpt-GQpt-GWpt-LUpt-MOpt-MZpt-STpt-TLzh-Hant-MO") |
||||
}, |
||||
unsafe { |
||||
:: zerovec :: ZeroVec :: from_bytes_unchecked (b"en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01150en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01150en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01150en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01150en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01150en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01150en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01150en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01150en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01150en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001en\0\0\0\0\0\0\x01001es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419es\0\0\0\0\0\0\x01419en\0\0\0\0\0\0\x01IN\0fr\0\0\0\0\0\0\x01HT\0no\0\0\0\0\0\0\0\0\0\0no\0\0\0\0\0\0\0\0\0\0no\0\0\0\0\0\0\0\0\0\0pt\0\0\0\0\0\0\x01PT\0pt\0\0\0\0\0\0\x01PT\0pt\0\0\0\0\0\0\x01PT\0pt\0\0\0\0\0\0\x01PT\0pt\0\0\0\0\0\0\x01PT\0pt\0\0\0\0\0\0\x01PT\0pt\0\0\0\0\0\0\x01PT\0pt\0\0\0\0\0\0\x01PT\0pt\0\0\0\0\0\0\x01PT\0pt\0\0\0\0\0\0\x01PT\0pt\0\0\0\0\0\0\x01PT\0zh\0\x01Hant\x01HK\0") |
||||
}, |
||||
) |
||||
}, |
||||
} |
@ -0,0 +1,6 @@
|
||||
// @generated
|
||||
type DataStruct = < :: icu_provider_adapters :: fallback :: provider :: CollationFallbackSupplementV1Marker as :: icu_provider :: DataMarker > :: Yokeable ; |
||||
pub fn lookup(locale: &icu_provider::DataLocale) -> Option<&'static DataStruct> { |
||||
locale.is_empty().then(|| &UND) |
||||
} |
||||
static UND: DataStruct = include!("und.rs.data"); |
@ -0,0 +1,22 @@
|
||||
::icu_provider_adapters::fallback::provider::LocaleFallbackSupplementV1 { |
||||
parents: unsafe { |
||||
#[allow(unused_unsafe)] |
||||
::zerovec::ZeroMap::from_parts_unchecked( |
||||
unsafe { ::zerovec::VarZeroVec::from_bytes_unchecked(b"\x01\0\0\0\0\0yue") }, |
||||
unsafe { ::zerovec::ZeroVec::from_bytes_unchecked(b"zh\0\x01Hant\0\0\0\0") }, |
||||
) |
||||
}, |
||||
unicode_extension_defaults: unsafe { |
||||
#[allow(unused_unsafe)] |
||||
::zerovec::ZeroMap2d::from_parts_unchecked( |
||||
unsafe { ::zerovec::ZeroVec::from_bytes_unchecked(b"co") }, |
||||
unsafe { ::zerovec::ZeroVec::from_bytes_unchecked(b"\x02\0\0\0") }, |
||||
unsafe { |
||||
::zerovec::VarZeroVec::from_bytes_unchecked(b"\x02\0\0\0\0\0\x02\0zhzh-Hant") |
||||
}, |
||||
unsafe { |
||||
::zerovec::VarZeroVec::from_bytes_unchecked(b"\x02\0\0\0\0\0\x06\0pinyinstroke") |
||||
}, |
||||
) |
||||
}, |
||||
} |
@ -0,0 +1,2 @@
|
||||
// @generated
|
||||
pub mod co_v1; |
@ -0,0 +1,216 @@
|
||||
// @generated
|
||||
#[clippy::msrv = "1.61"] |
||||
mod fallback; |
||||
#[clippy::msrv = "1.61"] |
||||
mod normalizer; |
||||
#[clippy::msrv = "1.61"] |
||||
use icu_provider::prelude::*; |
||||
/// Implement [`DataProvider<M>`] on the given struct using the data
|
||||
/// hardcoded in this module. This allows the struct to be used with
|
||||
/// `icu`'s `_unstable` constructors.
|
||||
///
|
||||
/// This macro can only be called from its definition-site, i.e. right
|
||||
/// after `include!`-ing the generated module.
|
||||
///
|
||||
/// ```compile_fail
|
||||
/// struct MyDataProvider;
|
||||
/// include!("/path/to/generated/mod.rs");
|
||||
/// impl_data_provider(MyDataProvider);
|
||||
/// ```
|
||||
#[allow(unused_macros)] |
||||
macro_rules! impl_data_provider { |
||||
($ provider : path) => { |
||||
#[clippy::msrv = "1.61"] |
||||
impl DataProvider<::icu_normalizer::provider::CanonicalCompositionsV1Marker> for $provider { |
||||
fn load(&self, req: DataRequest) -> Result<DataResponse<::icu_normalizer::provider::CanonicalCompositionsV1Marker>, DataError> { |
||||
normalizer::comp_v1::lookup(&req.locale) |
||||
.map(zerofrom::ZeroFrom::zero_from) |
||||
.map(DataPayload::from_owned) |
||||
.map(|payload| DataResponse { |
||||
metadata: Default::default(), |
||||
payload: Some(payload), |
||||
}) |
||||
.ok_or_else(|| DataErrorKind::MissingLocale.with_req(::icu_normalizer::provider::CanonicalCompositionsV1Marker::KEY, req)) |
||||
} |
||||
} |
||||
#[clippy::msrv = "1.61"] |
||||
impl DataProvider<::icu_normalizer::provider::CanonicalDecompositionDataV1Marker> for $provider { |
||||
fn load(&self, req: DataRequest) -> Result<DataResponse<::icu_normalizer::provider::CanonicalDecompositionDataV1Marker>, DataError> { |
||||
normalizer::nfd_v1::lookup(&req.locale) |
||||
.map(zerofrom::ZeroFrom::zero_from) |
||||
.map(DataPayload::from_owned) |
||||
.map(|payload| DataResponse { |
||||
metadata: Default::default(), |
||||
payload: Some(payload), |
||||
}) |
||||
.ok_or_else(|| DataErrorKind::MissingLocale.with_req(::icu_normalizer::provider::CanonicalDecompositionDataV1Marker::KEY, req)) |
||||
} |
||||
} |
||||
#[clippy::msrv = "1.61"] |
||||
impl DataProvider<::icu_normalizer::provider::CanonicalDecompositionTablesV1Marker> for $provider { |
||||
fn load(&self, req: DataRequest) -> Result<DataResponse<::icu_normalizer::provider::CanonicalDecompositionTablesV1Marker>, DataError> { |
||||
normalizer::nfdex_v1::lookup(&req.locale) |
||||
.map(zerofrom::ZeroFrom::zero_from) |
||||
.map(DataPayload::from_owned) |
||||
.map(|payload| DataResponse { |
||||
metadata: Default::default(), |
||||
payload: Some(payload), |
||||
}) |
||||
.ok_or_else(|| DataErrorKind::MissingLocale.with_req(::icu_normalizer::provider::CanonicalDecompositionTablesV1Marker::KEY, req)) |
||||
} |
||||
} |
||||
#[clippy::msrv = "1.61"] |
||||
impl DataProvider<::icu_normalizer::provider::CompatibilityDecompositionSupplementV1Marker> for $provider { |
||||
fn load( |
||||
&self, |
||||
req: DataRequest, |
||||
) -> Result<DataResponse<::icu_normalizer::provider::CompatibilityDecompositionSupplementV1Marker>, DataError> { |
||||
normalizer::nfkd_v1::lookup(&req.locale) |
||||
.map(zerofrom::ZeroFrom::zero_from) |
||||
.map(DataPayload::from_owned) |
||||
.map(|payload| DataResponse { |
||||
metadata: Default::default(), |
||||
payload: Some(payload), |
||||
}) |
||||
.ok_or_else(|| { |
||||
DataErrorKind::MissingLocale.with_req(::icu_normalizer::provider::CompatibilityDecompositionSupplementV1Marker::KEY, req) |
||||
}) |
||||
} |
||||
} |
||||
#[clippy::msrv = "1.61"] |
||||
impl DataProvider<::icu_normalizer::provider::CompatibilityDecompositionTablesV1Marker> for $provider { |
||||
fn load( |
||||
&self, |
||||
req: DataRequest, |
||||
) -> Result<DataResponse<::icu_normalizer::provider::CompatibilityDecompositionTablesV1Marker>, DataError> { |
||||
normalizer::nfkdex_v1::lookup(&req.locale) |
||||
.map(zerofrom::ZeroFrom::zero_from) |
||||
.map(DataPayload::from_owned) |
||||
.map(|payload| DataResponse { |
||||
metadata: Default::default(), |
||||
payload: Some(payload), |
||||
}) |
||||
.ok_or_else(|| { |
||||
DataErrorKind::MissingLocale.with_req(::icu_normalizer::provider::CompatibilityDecompositionTablesV1Marker::KEY, req) |
||||
}) |
||||
} |
||||
} |
||||
#[clippy::msrv = "1.61"] |
||||
impl DataProvider<::icu_provider_adapters::fallback::provider::CollationFallbackSupplementV1Marker> for $provider { |
||||
fn load( |
||||
&self, |
||||
req: DataRequest, |
||||
) -> Result<DataResponse<::icu_provider_adapters::fallback::provider::CollationFallbackSupplementV1Marker>, DataError> { |
||||
fallback::supplement::co_v1::lookup(&req.locale) |
||||
.map(zerofrom::ZeroFrom::zero_from) |
||||
.map(DataPayload::from_owned) |
||||
.map(|payload| DataResponse { |
||||
metadata: Default::default(), |
||||
payload: Some(payload), |
||||
}) |
||||
.ok_or_else(|| { |
||||
DataErrorKind::MissingLocale.with_req( |
||||
::icu_provider_adapters::fallback::provider::CollationFallbackSupplementV1Marker::KEY, |
||||
req, |
||||
) |
||||
}) |
||||
} |
||||
} |
||||
#[clippy::msrv = "1.61"] |
||||
impl DataProvider<::icu_provider_adapters::fallback::provider::LocaleFallbackLikelySubtagsV1Marker> for $provider { |
||||
fn load( |
||||
&self, |
||||
req: DataRequest, |
||||
) -> Result<DataResponse<::icu_provider_adapters::fallback::provider::LocaleFallbackLikelySubtagsV1Marker>, DataError> { |
||||
fallback::likelysubtags_v1::lookup(&req.locale) |
||||
.map(zerofrom::ZeroFrom::zero_from) |
||||
.map(DataPayload::from_owned) |
||||
.map(|payload| DataResponse { |
||||
metadata: Default::default(), |
||||
payload: Some(payload), |
||||
}) |
||||
.ok_or_else(|| { |
||||
DataErrorKind::MissingLocale.with_req( |
||||
::icu_provider_adapters::fallback::provider::LocaleFallbackLikelySubtagsV1Marker::KEY, |
||||
req, |
||||
) |
||||
}) |
||||
} |
||||
} |
||||
#[clippy::msrv = "1.61"] |
||||
impl DataProvider<::icu_provider_adapters::fallback::provider::LocaleFallbackParentsV1Marker> for $provider { |
||||
fn load( |
||||
&self, |
||||
req: DataRequest, |
||||
) -> Result<DataResponse<::icu_provider_adapters::fallback::provider::LocaleFallbackParentsV1Marker>, DataError> { |
||||
fallback::parents_v1::lookup(&req.locale) |
||||
.map(zerofrom::ZeroFrom::zero_from) |
||||
.map(DataPayload::from_owned) |
||||
.map(|payload| DataResponse { |
||||
metadata: Default::default(), |
||||
payload: Some(payload), |
||||
}) |
||||
.ok_or_else(|| { |
||||
DataErrorKind::MissingLocale.with_req(::icu_provider_adapters::fallback::provider::LocaleFallbackParentsV1Marker::KEY, req) |
||||
}) |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
/// Implement [`AnyProvider`] on the given struct using the data
|
||||
/// hardcoded in this module. This allows the struct to be used with
|
||||
/// `icu`'s `_any` constructors.
|
||||
///
|
||||
/// This macro can only be called from its definition-site, i.e. right
|
||||
/// after `include!`-ing the generated module.
|
||||
///
|
||||
/// ```compile_fail
|
||||
/// struct MyAnyProvider;
|
||||
/// include!("/path/to/generated/mod.rs");
|
||||
/// impl_any_provider(MyAnyProvider);
|
||||
/// ```
|
||||
#[allow(unused_macros)] |
||||
macro_rules! impl_any_provider { |
||||
($ provider : path) => { |
||||
#[clippy::msrv = "1.61"] |
||||
impl AnyProvider for $provider { |
||||
fn load_any(&self, key: DataKey, req: DataRequest) -> Result<AnyResponse, DataError> { |
||||
const CANONICALCOMPOSITIONSV1MARKER: ::icu_provider::DataKeyHash = |
||||
::icu_normalizer::provider::CanonicalCompositionsV1Marker::KEY.hashed(); |
||||
const CANONICALDECOMPOSITIONDATAV1MARKER: ::icu_provider::DataKeyHash = |
||||
::icu_normalizer::provider::CanonicalDecompositionDataV1Marker::KEY.hashed(); |
||||
const CANONICALDECOMPOSITIONTABLESV1MARKER: ::icu_provider::DataKeyHash = |
||||
::icu_normalizer::provider::CanonicalDecompositionTablesV1Marker::KEY.hashed(); |
||||
const COMPATIBILITYDECOMPOSITIONSUPPLEMENTV1MARKER: ::icu_provider::DataKeyHash = |
||||
::icu_normalizer::provider::CompatibilityDecompositionSupplementV1Marker::KEY.hashed(); |
||||
const COMPATIBILITYDECOMPOSITIONTABLESV1MARKER: ::icu_provider::DataKeyHash = |
||||
::icu_normalizer::provider::CompatibilityDecompositionTablesV1Marker::KEY.hashed(); |
||||
const COLLATIONFALLBACKSUPPLEMENTV1MARKER: ::icu_provider::DataKeyHash = |
||||
::icu_provider_adapters::fallback::provider::CollationFallbackSupplementV1Marker::KEY.hashed(); |
||||
const LOCALEFALLBACKLIKELYSUBTAGSV1MARKER: ::icu_provider::DataKeyHash = |
||||
::icu_provider_adapters::fallback::provider::LocaleFallbackLikelySubtagsV1Marker::KEY.hashed(); |
||||
const LOCALEFALLBACKPARENTSV1MARKER: ::icu_provider::DataKeyHash = |
||||
::icu_provider_adapters::fallback::provider::LocaleFallbackParentsV1Marker::KEY.hashed(); |
||||
match key.hashed() { |
||||
CANONICALCOMPOSITIONSV1MARKER => normalizer::comp_v1::lookup(&req.locale).map(AnyPayload::from_static_ref), |
||||
CANONICALDECOMPOSITIONDATAV1MARKER => normalizer::nfd_v1::lookup(&req.locale).map(AnyPayload::from_static_ref), |
||||
CANONICALDECOMPOSITIONTABLESV1MARKER => normalizer::nfdex_v1::lookup(&req.locale).map(AnyPayload::from_static_ref), |
||||
COMPATIBILITYDECOMPOSITIONSUPPLEMENTV1MARKER => normalizer::nfkd_v1::lookup(&req.locale).map(AnyPayload::from_static_ref), |
||||
COMPATIBILITYDECOMPOSITIONTABLESV1MARKER => normalizer::nfkdex_v1::lookup(&req.locale).map(AnyPayload::from_static_ref), |
||||
COLLATIONFALLBACKSUPPLEMENTV1MARKER => fallback::supplement::co_v1::lookup(&req.locale).map(AnyPayload::from_static_ref), |
||||
LOCALEFALLBACKLIKELYSUBTAGSV1MARKER => fallback::likelysubtags_v1::lookup(&req.locale).map(AnyPayload::from_static_ref), |
||||
LOCALEFALLBACKPARENTSV1MARKER => fallback::parents_v1::lookup(&req.locale).map(AnyPayload::from_static_ref), |
||||
_ => return Err(DataErrorKind::MissingDataKey.with_req(key, req)), |
||||
} |
||||
.map(|payload| AnyResponse { |
||||
payload: Some(payload), |
||||
metadata: Default::default(), |
||||
}) |
||||
.ok_or_else(|| DataErrorKind::MissingLocale.with_req(key, req)) |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
#[clippy::msrv = "1.61"] |
||||
pub struct BakedDataProvider; |
||||
impl_data_provider!(BakedDataProvider); |
@ -0,0 +1,6 @@
|
||||
// @generated
|
||||
type DataStruct = < :: icu_normalizer :: provider :: CanonicalCompositionsV1Marker as :: icu_provider :: DataMarker > :: Yokeable ; |
||||
pub fn lookup(locale: &icu_provider::DataLocale) -> Option<&'static DataStruct> { |
||||
locale.is_empty().then(|| &UND) |
||||
} |
||||
static UND: DataStruct = include!("und.rs.data"); |
File diff suppressed because one or more lines are too long
@ -0,0 +1,6 @@
|
||||
// @generated
|
||||
pub mod comp_v1; |
||||
pub mod nfd_v1; |
||||
pub mod nfdex_v1; |
||||
pub mod nfkd_v1; |
||||
pub mod nfkdex_v1; |
@ -0,0 +1,6 @@
|
||||
// @generated
|
||||
type DataStruct = < :: icu_normalizer :: provider :: CanonicalDecompositionDataV1Marker as :: icu_provider :: DataMarker > :: Yokeable ; |
||||
pub fn lookup(locale: &icu_provider::DataLocale) -> Option<&'static DataStruct> { |
||||
locale.is_empty().then(|| &UND) |
||||
} |
||||
static UND: DataStruct = include!("und.rs.data"); |
File diff suppressed because one or more lines are too long
@ -0,0 +1,6 @@
|
||||
// @generated
|
||||
type DataStruct = < :: icu_normalizer :: provider :: CanonicalDecompositionTablesV1Marker as :: icu_provider :: DataMarker > :: Yokeable ; |
||||
pub fn lookup(locale: &icu_provider::DataLocale) -> Option<&'static DataStruct> { |
||||
locale.is_empty().then(|| &UND) |
||||
} |
||||
static UND: DataStruct = include!("und.rs.data"); |
File diff suppressed because one or more lines are too long
@ -0,0 +1,6 @@
|
||||
// @generated
|
||||
type DataStruct = < :: icu_normalizer :: provider :: CompatibilityDecompositionSupplementV1Marker as :: icu_provider :: DataMarker > :: Yokeable ; |
||||
pub fn lookup(locale: &icu_provider::DataLocale) -> Option<&'static DataStruct> { |
||||
locale.is_empty().then(|| &UND) |
||||
} |
||||
static UND: DataStruct = include!("und.rs.data"); |
File diff suppressed because one or more lines are too long
@ -0,0 +1,6 @@
|
||||
// @generated
|
||||
type DataStruct = < :: icu_normalizer :: provider :: CompatibilityDecompositionTablesV1Marker as :: icu_provider :: DataMarker > :: Yokeable ; |
||||
pub fn lookup(locale: &icu_provider::DataLocale) -> Option<&'static DataStruct> { |
||||
locale.is_empty().then(|| &UND) |
||||
} |
||||
static UND: DataStruct = include!("und.rs.data"); |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue