diff --git a/CHANGELOG.md b/CHANGELOG.md index 0edda32e6d4..205830f074f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ - `FormattedDateTime` and `FormattedZonedDateTime` now implement `Clone` and `Copy` (https://github.com/unicode-org/icu4x/pull/4476) - `icu_properties` - Add `Aran` script code (https://github.com/unicode-org/icu4x/pull/4426) - - Mark `BidiClassAdapter::new` as const (https://github.com/unicode-org/icu4x/pull/4584) + - Mark additional constructors as `const` (https://github.com/unicode-org/icu4x/pull/4584, https://github.com/unicode-org/icu4x/pull/4574) - Implement Joining_Type property (https://github.com/unicode-org/icu4x/pull/4599) - `icu_segmenter` - Fix Unicode 15.0 line breaking (https://github.com/unicode-org/icu4x/pull/4389) diff --git a/components/normalizer/src/properties.rs b/components/normalizer/src/properties.rs index 631cb281fda..9794d5209cd 100644 --- a/components/normalizer/src/properties.rs +++ b/components/normalizer/src/properties.rs @@ -90,7 +90,7 @@ impl CanonicalComposition { /// /// [📚 Help choosing a constructor](icu_provider::constructors) #[cfg(feature = "compiled_data")] - pub fn new() -> Self { + pub const fn new() -> Self { Self { canonical_compositions: DataPayload::from_static_ref( crate::provider::Baked::SINGLETON_NORMALIZER_COMP_V1, diff --git a/components/properties/src/props.rs b/components/properties/src/props.rs index a043218c24f..e9c3030fbbd 100644 --- a/components/properties/src/props.rs +++ b/components/properties/src/props.rs @@ -585,7 +585,7 @@ macro_rules! impl_value_getter { impl $ty { $(#[$attr_n2e])* #[cfg(feature = "compiled_data")] - $vis_n2e fn $cname_n2e() -> PropertyValueNameToEnumMapperBorrowed<'static, $ty> { + $vis_n2e const fn $cname_n2e() -> PropertyValueNameToEnumMapperBorrowed<'static, $ty> { PropertyValueNameToEnumMapperBorrowed { map: crate::provider::Baked::$singleton_n2e, markers: PhantomData, @@ -604,7 +604,7 @@ macro_rules! impl_value_getter { $( $(#[$attr_e2sn])* #[cfg(feature = "compiled_data")] - $vis_e2sn fn $cname_e2sn() -> $mapper_e2snb<'static, $ty> { + $vis_e2sn const fn $cname_e2sn() -> $mapper_e2snb<'static, $ty> { $mapper_e2snb { map: crate::provider::Baked::$singleton_e2sn, markers: PhantomData, @@ -622,7 +622,7 @@ macro_rules! impl_value_getter { $(#[$attr_e2ln])* #[cfg(feature = "compiled_data")] - $vis_e2ln fn $cname_e2ln() -> $mapper_e2lnb<'static, $ty> { + $vis_e2ln const fn $cname_e2ln() -> $mapper_e2lnb<'static, $ty> { $mapper_e2lnb { map: crate::provider::Baked::$singleton_e2ln, markers: PhantomData, diff --git a/experimental/harfbuzz/README.md b/experimental/harfbuzz/README.md index 8cdab6e5369..f005f1209a2 100644 --- a/experimental/harfbuzz/README.md +++ b/experimental/harfbuzz/README.md @@ -11,7 +11,7 @@ use harfbuzz::{Buffer, Direction, sys}; let mut b = Buffer::with("مساء الخير"); -let unicode_funcs = icu_harfbuzz::new_hb_unicode_funcs().unwrap(); +let unicode_funcs = icu_harfbuzz::UnicodeFuncs::new().unwrap(); // NOTE: This currently requires `unsafe` code. For progress toward a safe abstraction, see: // diff --git a/experimental/harfbuzz/src/lib.rs b/experimental/harfbuzz/src/lib.rs index 9a8054dfc59..2202fbeba98 100644 --- a/experimental/harfbuzz/src/lib.rs +++ b/experimental/harfbuzz/src/lib.rs @@ -28,7 +28,7 @@ //! //! let mut b = Buffer::with("مساء الخير"); //! -//! let unicode_funcs = icu_harfbuzz::new_hb_unicode_funcs().unwrap(); +//! let unicode_funcs = icu_harfbuzz::UnicodeFuncs::new().unwrap(); //! //! // NOTE: This currently requires `unsafe` code. For progress toward a safe abstraction, see: //! // @@ -52,11 +52,13 @@ use icu_normalizer::properties::CanonicalCombiningClassMap; use icu_normalizer::properties::CanonicalComposition; use icu_normalizer::properties::CanonicalDecomposition; use icu_normalizer::properties::Decomposed; -use icu_normalizer::provider::CanonicalCompositionsV1Marker; -use icu_normalizer::provider::CanonicalDecompositionDataV1Marker; -use icu_normalizer::provider::CanonicalDecompositionTablesV1Marker; -use icu_normalizer::provider::NonRecursiveDecompositionSupplementV1Marker; +use icu_normalizer::provider::{ + CanonicalCompositionsV1Marker, CanonicalDecompositionDataV1Marker, + CanonicalDecompositionTablesV1Marker, NonRecursiveDecompositionSupplementV1Marker, +}; +use icu_properties::bidi_data; use icu_properties::bidi_data::BidiAuxiliaryProperties; +use icu_properties::maps; use icu_properties::maps::CodePointMapData; use icu_properties::names::PropertyEnumToValueNameLinearTiny4Mapper; use icu_properties::provider::bidi_data::BidiAuxiliaryPropertiesV1Marker; @@ -65,7 +67,7 @@ use icu_properties::provider::{ }; use icu_properties::{GeneralCategory, Script}; use icu_provider::prelude::*; -use tinystr::{tinystr, TinyStr4}; +use tinystr::tinystr; /// The total number of General Category values is fixed per /// https://www.unicode.org/policies/stability_policy.html : @@ -113,169 +115,6 @@ static ICU4X_GENERAL_CATEGORY_TO_HARFBUZZ: [u8; 30] = [ HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION as u8, // FinalPunctuation = 29, ]; -unsafe extern "C" fn icu4x_hb_unicode_combining_class( - _ufuncs: *mut hb_unicode_funcs_t, - unicode: hb_codepoint_t, - user_data: *mut c_void, -) -> hb_unicode_combining_class_t { - (*(user_data as *mut CanonicalCombiningClassMap)) - .get32(unicode) - .0 as hb_unicode_combining_class_t -} - -unsafe extern "C" fn icu4x_hb_unicode_combining_class_destroy(user_data: *mut c_void) { - let _ = Box::from_raw(user_data as *mut CanonicalCombiningClassMap); -} - -#[allow(clippy::indexing_slicing)] -unsafe extern "C" fn icu4x_hb_unicode_general_category( - _ufuncs: *mut hb_unicode_funcs_t, - unicode: hb_codepoint_t, - user_data: *mut c_void, -) -> hb_unicode_general_category_t { - // Indexing is OK, because `GeneralCategory` data is validated upon - // deserialization so that there can be no out-of-range `GeneralCategory` - // values (which would be UB to materialize). `GeneralCategory` is a - // stable exhaustive enum, and the length of `ICU4X_GENERAL_CATEGORY_TO_HARFBUZZ` - // matches the number of enum items, so the index will always be in range here. - ICU4X_GENERAL_CATEGORY_TO_HARFBUZZ[(*(user_data as *mut CodePointMapData)) - .as_borrowed() - .get32(unicode) as usize] as hb_unicode_general_category_t -} - -unsafe extern "C" fn icu4x_hb_unicode_general_category_destroy(user_data: *mut c_void) { - let _ = Box::from_raw(user_data as *mut CodePointMapData); -} - -/// Returns the Bidi_Mirroring_Glyph, but adjusting the return value -/// to fix HarfBuzz expected behavior for code points whose property value -/// for Bidi_Mirroring_Glyph is the undefined value. -/// -/// From HarfBuzz docs on `hb_unicode_mirroring_func_t`: -/// Note: If a code point does not have a specified -/// Bi-Directional Mirroring Glyph defined, the method should -/// return the original code point. -unsafe extern "C" fn icu4x_hb_unicode_mirroring( - _ufuncs: *mut hb_unicode_funcs_t, - unicode: hb_codepoint_t, - user_data: *mut c_void, -) -> hb_codepoint_t { - (*(user_data as *mut BidiAuxiliaryProperties)) - .as_borrowed() - .get32_mirroring_props(unicode) - .mirroring_glyph - .map(u32::from) - .unwrap_or(unicode) as hb_codepoint_t -} - -unsafe extern "C" fn icu4x_hb_unicode_mirroring_destroy(user_data: *mut c_void) { - let _ = Box::from_raw(user_data as *mut BidiAuxiliaryProperties); -} - -struct ScriptDataForHarfBuzz { - script_map: CodePointMapData