Skip to content

Commit

Permalink
properties
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Feb 8, 2025
1 parent eda21ca commit 1dac677
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/experimental/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ icu_list = { workspace = true }
icu_locale = { workspace = true }
icu_normalizer = { workspace = true }
icu_plurals = { workspace = true }
icu_properties = { workspace = true }
icu_properties = { workspace = true, features = ["alloc"] }

databake = { workspace = true, optional = true, features = ["derive"] }
either = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion components/icu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ icu_list = { workspace = true }
icu_locale = { workspace = true }
icu_normalizer = { workspace = true }
icu_plurals = { workspace = true }
icu_properties = { workspace = true }
icu_properties = { workspace = true, features = ["alloc"] }
icu_segmenter = { workspace = true }
icu_timezone = { workspace = true }
icu_experimental = { workspace = true, optional = true }
Expand Down
1 change: 1 addition & 0 deletions components/properties/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ serde = ["dep:serde", "icu_locale_core/serde", "potential_utf/serde", "zerovec/s
datagen = ["serde", "dep:databake", "potential_utf/databake", "zerovec/databake", "icu_collections/databake", "icu_locale_core/databake", "zerotrie/databake"]
unicode_bidi = [ "dep:unicode-bidi" ]
compiled_data = ["dep:icu_properties_data"]
alloc = ["zerovec/alloc", "icu_collections/alloc"]
10 changes: 7 additions & 3 deletions components/properties/src/code_point_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

#[cfg(feature = "alloc")]
use crate::code_point_set::CodePointSetData;
use crate::props::GeneralCategory;
use crate::props::GeneralCategoryGroup;
use crate::provider::*;
use crate::{code_point_set::CodePointSetData, props::GeneralCategoryGroup};
use core::ops::RangeInclusive;
use icu_collections::codepointtrie::{CodePointMapRange, CodePointTrie, TrieValue};
use icu_provider::marker::ErasedMarker;
use icu_provider::prelude::*;
use zerovec::ule::UleError;

/// A wrapper around code point map data.
///
Expand Down Expand Up @@ -85,7 +86,8 @@ impl<T: TrieValue> CodePointMapData<T> {
/// assert_eq!(gc.get('木'), GeneralCategory::OtherLetter as u8); // U+6728
/// assert_eq!(gc.get('🎃'), GeneralCategory::OtherSymbol as u8); // U+1F383 JACK-O-LANTERN
/// ```
pub fn try_into_converted<P>(self) -> Result<CodePointMapData<P>, UleError>
#[cfg(feature = "alloc")]
pub fn try_into_converted<P>(self) -> Result<CodePointMapData<P>, zerovec::ule::UleError>
where
P: TrieValue,
{
Expand Down Expand Up @@ -186,6 +188,7 @@ impl<'a, T: TrieValue> CodePointMapDataBorrowed<'a, T> {
/// assert!(other_letter_set.contains('木')); // U+6728
/// assert!(!other_letter_set.contains('🎃')); // U+1F383 JACK-O-LANTERN
/// ```
#[cfg(feature = "alloc")]
pub fn get_set_for_value(self, value: T) -> CodePointSetData {
let set = self.map.get_set_for_value(value);
CodePointSetData::from_code_point_inversion_list(set)
Expand Down Expand Up @@ -263,6 +266,7 @@ impl<'a, T: TrieValue> CodePointMapDataBorrowed<'a, T> {

impl CodePointMapDataBorrowed<'_, GeneralCategory> {
/// TODO
#[cfg(feature = "alloc")]
pub fn get_set_for_value_group(self, value: GeneralCategoryGroup) -> crate::CodePointSetData {
let matching_gc_ranges = self
.iter_ranges()
Expand Down
1 change: 1 addition & 0 deletions components/properties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
)]
#![warn(missing_docs)]

#[cfg(feature = "alloc")]
extern crate alloc;

mod code_point_set;
Expand Down
2 changes: 1 addition & 1 deletion components/properties/src/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,7 @@ make_emoji_set! {
#[cfg(test)]
mod test_enumerated_property_completeness {
use super::*;
use alloc::collections::BTreeMap;
use std::collections::BTreeMap;

fn check_enum<'a, T: NamedEnumeratedProperty>(
lookup: &crate::provider::names::PropertyValueNameToEnumMap<'static>,
Expand Down
8 changes: 6 additions & 2 deletions components/properties/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use icu_collections::codepointinvliststringlist::CodePointInversionListAndString
use icu_collections::codepointtrie::{CodePointMapRange, CodePointTrie, TrieValue};
use icu_provider::prelude::*;
use zerofrom::ZeroFrom;
use zerovec::{ule::UleError, VarZeroVec, ZeroSlice};
use zerovec::{VarZeroVec, ZeroSlice};

#[cfg(feature = "compiled_data")]
#[derive(Debug)]
Expand Down Expand Up @@ -528,7 +528,10 @@ impl<'data, T: TrieValue> PropertyCodePointMap<'data, T> {
}

#[inline]
pub(crate) fn try_into_converted<P>(self) -> Result<PropertyCodePointMap<'data, P>, UleError>
#[cfg(feature = "alloc")]
pub(crate) fn try_into_converted<P>(
self,
) -> Result<PropertyCodePointMap<'data, P>, zerovec::ule::UleError>
where
P: TrieValue,
{
Expand All @@ -540,6 +543,7 @@ impl<'data, T: TrieValue> PropertyCodePointMap<'data, T> {
}

#[inline]
#[cfg(feature = "alloc")]
pub(crate) fn get_set_for_value(&self, value: T) -> CodePointInversionList<'static> {
match *self {
Self::CodePointTrie(ref t) => t.get_set_for_value(value),
Expand Down
3 changes: 3 additions & 0 deletions components/properties/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
use crate::props::Script;
use crate::provider::*;

#[cfg(feature = "alloc")]
use core::iter::FromIterator;
use core::ops::RangeInclusive;
#[cfg(feature = "alloc")]
use icu_collections::codepointinvlist::CodePointInversionList;
use icu_provider::prelude::*;
use zerovec::{ule::AsULE, ZeroSlice};
Expand Down Expand Up @@ -641,6 +643,7 @@ impl<'a> ScriptWithExtensionsBorrowed<'a> {
/// assert!(syriac.contains('\u{1DFA}')); // COMBINING DOT BELOW LEFT
/// assert!(!syriac.contains('\u{1DFB}')); // COMBINING DELETION MARK
/// ```
#[cfg(feature = "alloc")]
pub fn get_script_extensions_set(self, script: Script) -> CodePointInversionList<'a> {
CodePointInversionList::from_iter(self.get_script_extensions_ranges(script))
}
Expand Down
2 changes: 1 addition & 1 deletion ffi/capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ icu_list = { workspace = true, optional = true }
icu_locale = { workspace = true, optional = true }
icu_normalizer = { workspace = true, optional = true }
icu_plurals = { workspace = true, optional = true }
icu_properties = { workspace = true, features = ["unicode_bidi"], optional = true }
icu_properties = { workspace = true, features = ["alloc", "unicode_bidi"], optional = true }
icu_segmenter = { workspace = true, features = ["auto"], optional = true }
icu_timezone = { workspace = true, features = ["ixdtf"], optional = true }
icu_experimental = { workspace = true, optional = true }
Expand Down
1 change: 1 addition & 0 deletions tools/noalloctest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ publish = false
# Dependencies that should be no-alloc should go here
icu_collections = { workspace = true }
icu_locale_core = { workspace = true }
icu_properties = { workspace = true }
icu_provider = { workspace = true }
icu_provider_baked = { workspace = true }
litemap = { workspace = true }
Expand Down

0 comments on commit 1dac677

Please sign in to comment.