Skip to content

Commit

Permalink
Make GeneralCategory an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Aug 24, 2023
1 parent 9cf9066 commit 6868c97
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions harfbuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ mod traits;
pub use self::traits::CombiningClassFunc;
pub use self::traits::ComposeFunc;
pub use self::traits::DecomposeFunc;
pub use self::traits::GeneralCategory;
pub use self::traits::GeneralCategoryFunc;
pub use self::traits::MirroringFunc;
pub use self::traits::ScriptFunc;
Expand Down
43 changes: 40 additions & 3 deletions harfbuzz/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,48 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

/// A general category value. Equivalent to [`hb_unicode_general_category_t`].
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[allow(non_camel_case_types)] // the names are defined by Unicode
#[allow(missing_docs)] // the categories are defined by Unicode
pub enum GeneralCategory {
Control = 0,
Format = 1,
Unassigned = 2,
Private_use = 3,
Surrogate = 4,
Lowercase_Letter = 5,
Modifier_Letter = 6,
Other_Letter = 7,
Titlecase_Letter = 8,
Uppercase_Letter = 9,
Spacing_Mark = 10,
Enclosing_Mark = 11,
Non_Spacing_Mark = 12,
Decimal_Number = 13,
Letter_Number = 14,
Other_Number = 15,
Connect_Punctuation = 16,
Dash_Punctuation = 17,
Close_Punctuation = 18,
Final_Punctuation = 19,
Initial_Punctuation = 20,
Other_Punctuation = 21,
Open_Punctuation = 22,
Currency_Symbol = 23,
Modifier_Symbol = 24,
Math_Symbol = 25,
Other_Symbol = 26,
Line_Separator = 27,
Paragraph_Separator = 28,
Space_Separator = 29,
}

/// An object to map from code points to general category properties.
pub trait GeneralCategoryFunc {
/// Given a code point, return the general category as a
/// [`hb_unicode_general_category_t`].
fn general_category(&self, ch: u32) -> core::ffi::c_uint;
/// Given a code point, return the general category as a [`GeneralCategory`].
fn general_category(&self, ch: u32) -> GeneralCategory;
}

/// An object to map from code points to combining classes.
Expand Down
3 changes: 2 additions & 1 deletion harfbuzz/src/unicode_funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl UnicodeFuncsBuilder {
user_data: *mut c_void,
) -> hb_unicode_general_category_t {
unsafe { &*(user_data as *mut F) }.general_category(unicode)
as hb_unicode_general_category_t
}
extern "C" fn destroy_general_category<F>(user_data: *mut c_void) {
let _ = unsafe { Box::from_raw(user_data as *mut F) };
Expand Down Expand Up @@ -263,7 +264,7 @@ impl Drop for UnicodeFuncsBuilder {
/// struct PropertyProvider;
///
/// impl harfbuzz::GeneralCategoryFunc for PropertyProvider {
/// fn general_category(&self, ch: u32) -> core::ffi::c_uint {
/// fn general_category(&self, ch: u32) -> harfbuzz::GeneralCategory {
/// todo!("GeneralCategoryFunc")
/// }
/// }
Expand Down

0 comments on commit 6868c97

Please sign in to comment.