-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add UnicodeFuncs with safe-to-implement traits #197
Merged
Merged
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
742deba
Add UnicodeFuncs
sffc 992ead8
Add ability to set parent
sffc 1980bc9
Use individual functions with individual bounds
sffc 2792d92
Make the crate no_std and add harfbuzz-sys feature
sffc 4f3392b
Fix docs and tests
sffc 7c779f1
Merge branch 'master' into unicode-funcs
sffc 9cf9066
Post-merge fixes
sffc 6868c97
Make GeneralCategory an enum
sffc 39af919
Change CombiningClassFunc to return a u8
sffc ea3a6d3
Fix docs links
sffc 5b8a4aa
Use `char` instead of `u32` for hb_codepoint_t in traits
sffc 62e8b30
Add std feature to harfbuzz
sffc e66b4c4
Mark harfbuzz-sys as no_std.
sffc d055b33
Merge branch 'std' into unicode-funcs
sffc 0509b8b
Move to separate crate
sffc 19b35fc
Undo sys feature
sffc a313e89
fix
sffc ce55be7
Merge branch 'master' into unicode-funcs
sffc b54c454
Add no_std marker for unicode-traits
sffc 2b2ed07
Merge branch 'servo:master' into unicode-funcs
sffc cfa6c82
Update lib.rs
sffc 9629d7a
Docs tests
sffc 7e0ac7f
fmt?
sffc 8aae545
Update unicode_funcs_traits.rs
sffc cfe7ca4
Update lib.rs
sffc cfc89ac
Update unicode_funcs.rs
sffc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2023 The Servo Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// 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`]. | ||
/// | ||
/// [`hb_unicode_general_category_t`]: crate::sys::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 [`GeneralCategory`]. | ||
fn general_category(&self, ch: char) -> GeneralCategory; | ||
} | ||
|
||
/// An object to map from code points to combining classes. | ||
pub trait CombiningClassFunc { | ||
/// Given a code point, return the combining class as a `u8` corresponding to a | ||
/// [`hb_unicode_combining_class_t`]. Note that the | ||
/// [Unicode stability policy](https://www.unicode.org/policies/stability_policy.html) | ||
/// guarantees that Canonical Combining Class numeric values fit in a `u8`. | ||
/// | ||
/// [`hb_unicode_combining_class_t`]: crate::sys::hb_unicode_combining_class_t | ||
fn combining_class(&self, ch: char) -> u8; | ||
} | ||
|
||
/// An object to map from code points to mirrored code points. | ||
pub trait MirroringFunc { | ||
/// Given a code point, return the mirrored code point. | ||
fn mirroring(&self, ch: char) -> char; | ||
} | ||
|
||
/// An object to map from code points to script names. | ||
pub trait ScriptFunc { | ||
/// Given a code point, return the script as a 4-byte script name. | ||
fn script(&self, ch: char) -> [u8; 4]; | ||
} | ||
|
||
/// An object to compose two characters. | ||
pub trait ComposeFunc { | ||
/// Given two code points, return the composed code point. | ||
fn compose(&self, a: char, b: char) -> Option<char>; | ||
} | ||
|
||
/// An object to decompose a character. | ||
pub trait DecomposeFunc { | ||
/// Given a code point, return the two decomposed code points. | ||
fn decompose(&self, ab: char) -> Option<(char, char)>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest dropping the underscores like ICU4X does. That way, the names would be idiomatic for a Rust enum. Even if the names are defined by Unicode, it's pretty obvious to the reader what the applied name transformation would be if the names were idiomatic to Rust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, note the casing of the letter "u" in
PrivateUse
/Private_Use
.