Skip to content

Commit

Permalink
Returning ExtraneousLocale in BlobDataProvider (#3562)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Jun 23, 2023
1 parent 6fd55ca commit 8b30bb1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 42 deletions.
3 changes: 3 additions & 0 deletions provider/blob/src/blob_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ impl<'data> BlobSchemaV1<'data> {
.get0(&key.hashed())
.ok_or(DataErrorKind::MissingDataKey)
.and_then(|cursor| {
if key.metadata().singleton && !req.locale.is_empty() {
return Err(DataErrorKind::ExtraneousLocale);
}
cursor
.get1_copied_by(|bytes| req.locale.strict_cmp(&bytes.0).reverse())
.ok_or(DataErrorKind::MissingLocale)
Expand Down
16 changes: 2 additions & 14 deletions provider/datagen/src/transform/cldr/fallback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ use zerovec::{maps::ZeroMap2d, ule::UnvalidatedStr};
impl DataProvider<LocaleFallbackLikelySubtagsV1Marker> for crate::DatagenProvider {
fn load(
&self,
req: DataRequest,
_: DataRequest,
) -> Result<DataResponse<LocaleFallbackLikelySubtagsV1Marker>, DataError> {
// We treat searching for `und` as a request for all data. Other requests
// are not currently supported.
if !req.locale.is_empty() {
return Err(DataErrorKind::ExtraneousLocale.into_error());
}

let resources = LikelySubtagsResources::try_from_source_data(&self.source)?;

let metadata = DataResponseMetadata::default();
Expand All @@ -42,14 +36,8 @@ impl DataProvider<LocaleFallbackLikelySubtagsV1Marker> for crate::DatagenProvide
impl DataProvider<LocaleFallbackParentsV1Marker> for crate::DatagenProvider {
fn load(
&self,
req: DataRequest,
_: DataRequest,
) -> Result<DataResponse<LocaleFallbackParentsV1Marker>, DataError> {
// We treat searching for `und` as a request for all data. Other requests
// are not currently supported.
if !req.locale.is_empty() {
return Err(DataErrorKind::ExtraneousLocale.into_error());
}

let parents_data: &cldr_serde::parent_locales::Resource = self
.source
.cldr()?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ use tinystr::TinyAsciiStr;
use zerovec::ZeroSlice;

impl DataProvider<AliasesV1Marker> for crate::DatagenProvider {
fn load(&self, req: DataRequest) -> Result<DataResponse<AliasesV1Marker>, DataError> {
// We treat searching for `und` as a request for all data. Other requests
// are not currently supported.
if !req.locale.is_empty() {
return Err(DataErrorKind::ExtraneousLocale.into_error());
}

fn load(&self, _: DataRequest) -> Result<DataResponse<AliasesV1Marker>, DataError> {
let data: &cldr_serde::aliases::Resource = self
.source
.cldr()?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ use icu_provider::datagen::IterableDataProvider;
use icu_provider::prelude::*;

impl DataProvider<ScriptDirectionV1Marker> for crate::DatagenProvider {
fn load(&self, req: DataRequest) -> Result<DataResponse<ScriptDirectionV1Marker>, DataError> {
// We treat searching for `und` as a request for all data. Other requests
// are not currently supported.
if !req.locale.is_empty() {
return Err(DataErrorKind::ExtraneousLocale.into_error());
}

fn load(&self, _: DataRequest) -> Result<DataResponse<ScriptDirectionV1Marker>, DataError> {
let data: &cldr_serde::directionality::Resource = self
.source
.cldr()?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ use icu_provider::prelude::*;
use std::collections::{BTreeMap, HashSet};

impl DataProvider<LikelySubtagsV1Marker> for crate::DatagenProvider {
fn load(&self, req: DataRequest) -> Result<DataResponse<LikelySubtagsV1Marker>, DataError> {
// We treat searching for und as a request for all data. Other requests
// are not currently supported.
if !req.locale.is_empty() {
return Err(DataErrorKind::ExtraneousLocale.into_error());
}

fn load(&self, _: DataRequest) -> Result<DataResponse<LikelySubtagsV1Marker>, DataError> {
let resources = LikelySubtagsResources::try_from_source_data(&self.source)?;

Ok(DataResponse {
Expand All @@ -37,14 +31,8 @@ impl IterableDataProvider<LikelySubtagsV1Marker> for crate::DatagenProvider {
impl DataProvider<LikelySubtagsExtendedV1Marker> for crate::DatagenProvider {
fn load(
&self,
req: DataRequest,
_: DataRequest,
) -> Result<DataResponse<LikelySubtagsExtendedV1Marker>, DataError> {
// We treat searching for und as a request for all data. Other requests
// are not currently supported.
if !req.locale.is_empty() {
return Err(DataErrorKind::ExtraneousLocale.into_error());
}

let resources = LikelySubtagsResources::try_from_source_data(&self.source)?;

Ok(DataResponse {
Expand Down

0 comments on commit 8b30bb1

Please sign in to comment.