Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience properties API #6066

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions components/properties/src/code_point_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,12 @@ pub trait EnumeratedProperty: crate::private::Sealed + TrieValue {
const NAME: &'static [u8];
/// The abbreviated name of this property, if it exists, otherwise the name
const SHORT_NAME: &'static [u8];

/// Convenience method for `CodePointMapData::new().get(ch)`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add intra doc links, here and below

Suggested change
/// Convenience method for `CodePointMapData::new().get(ch)`
/// Convenience method for [`CodePointMapData::new().get(ch)`](CodePointMapData::get)

///
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
#[cfg(feature = "compiled_data")]
fn for_char(ch: char) -> Self {
CodePointMapData::new().get(ch)
}
}
10 changes: 9 additions & 1 deletion components/properties/src/code_point_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl<'a> CodePointSetDataBorrowed<'a> {
/// [`CodePointSetData`]: crate::sets::CodePointSetData
/// [`TR44`]: https://www.unicode.org/reports/tr44
/// [`TR18`]: https://www.unicode.org/reports/tr18
pub trait BinaryProperty: crate::private::Sealed {
pub trait BinaryProperty: crate::private::Sealed + Sized {
#[doc(hidden)]
type DataMarker: DataMarker<DataStruct = PropertyCodePointSetV1<'static>>;
#[doc(hidden)]
Expand All @@ -222,6 +222,14 @@ pub trait BinaryProperty: crate::private::Sealed {
const NAME: &'static [u8];
/// The abbreviated name of this property, if it exists, otherwise the name
const SHORT_NAME: &'static [u8];

/// Convenience method for `CodePointSetData::new().contains(ch)`
///
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
#[cfg(feature = "compiled_data")]
fn for_char(ch: char) -> bool {
CodePointSetData::new::<Self>().contains(ch)
}
}

#[cfg(test)]
Expand Down
24 changes: 24 additions & 0 deletions components/properties/src/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,30 @@ pub trait NamedEnumeratedProperty: ParseableEnumeratedProperty {
fn nep_short_identity_static(
stat: &'static Self::DataStructShortBorrowed<'static>,
) -> &'static Self::DataStructShort;

/// Convenience method for `PropertyParser::new().get_loose(s)`
///
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
#[cfg(feature = "compiled_data")]
fn try_from_str(s: &str) -> Option<Self> {
PropertyParser::new().get_loose(s)
}
/// Convenience method for `PropertyNamesLong::new().get(*self).unwrap()`
///
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
#[cfg(feature = "compiled_data")]
fn long_name(&self) -> &'static str {
PropertyNamesLong::new().get(*self).unwrap_or("unreachable")
}
/// Convenience method for `PropertyNamesShort::new().get(*self).unwrap()`
///
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
#[cfg(feature = "compiled_data")]
fn short_name(&self) -> &'static str {
PropertyNamesShort::new()
.get(*self)
.unwrap_or("unreachable")
}
}

macro_rules! impl_value_getter {
Expand Down
5 changes: 5 additions & 0 deletions ffi/capi/tests/missing_apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ icu::properties::PropertyNamesShortBorrowed::get_locale_script#FnInStruct
icu::properties::PropertyNamesShortBorrowed::new#FnInStruct
icu::properties::props::BidiMirroringGlyph#Struct
icu::properties::props::BidiPairedBracketType#Enum
icu::properties::props::BinaryProperty::for_char#FnInTrait
icu::properties::props::EnumeratedProperty::for_char#FnInTrait
icu::properties::props::NamedEnumeratedProperty::long_name#FnInTrait
icu::properties::props::NamedEnumeratedProperty::short_name#FnInTrait
icu::properties::props::NamedEnumeratedProperty::try_from_str#FnInTrait
icu::timezone::TimeZoneBcp47Iter#Struct
icu::timezone::TimeZoneBcp47Iter::next#FnInStruct
icu::timezone::TimeZoneCanonicalIanaIter#Struct
Expand Down