-
Notifications
You must be signed in to change notification settings - Fork 0
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
異字体セレクタを含む入力への対応: 文字列から異字体セレクタを取り除くメソッドを定義 #401
Merged
YuukiToriyama
merged 2 commits into
feature/filter-unicode-variation-selectors/master
from
feature/filter-unicode-variation-selectors/add-utility-method
Sep 3, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod converter; | ||
pub(crate) mod extension; | ||
pub mod sequence_matcher; | ||
mod trimmer; |
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,62 @@ | ||
pub(crate) trait CharExt { | ||
fn is_variation_selector(&self) -> bool; | ||
} | ||
|
||
impl CharExt for char { | ||
/// 異字体セレクタかどうかを判別します | ||
fn is_variation_selector(&self) -> bool { | ||
matches!(self, '\u{FE00}'..='\u{FE0F}' | '\u{E0100}'..='\u{E01EF}') | ||
} | ||
} | ||
|
||
pub(crate) trait StrExt { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 次のPRで使用箇所が発生する予定 |
||
fn strip_variation_selectors(&self) -> String; | ||
} | ||
|
||
impl StrExt for str { | ||
/// 文字列から異字体セレクタを取り除きます | ||
fn strip_variation_selectors(&self) -> String { | ||
self.chars() | ||
.filter(|c| !c.is_variation_selector()) | ||
.collect() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::util::extension::{CharExt, StrExt}; | ||
|
||
#[test] | ||
fn is_variation_selector() { | ||
assert_eq!('あ'.is_variation_selector(), false); | ||
assert_eq!('亜'.is_variation_selector(), false); | ||
|
||
assert_eq!('\u{FDFF}'.is_variation_selector(), false); | ||
assert_eq!('\u{FE00}'.is_variation_selector(), true); | ||
|
||
assert_eq!('\u{FE0F}'.is_variation_selector(), true); | ||
assert_eq!('\u{FE10}'.is_variation_selector(), false); | ||
|
||
assert_eq!('\u{E00FF}'.is_variation_selector(), false); | ||
assert_eq!('\u{E0100}'.is_variation_selector(), true); | ||
|
||
assert_eq!('\u{E01EF}'.is_variation_selector(), true); | ||
assert_eq!('\u{E01F0}'.is_variation_selector(), false); | ||
} | ||
|
||
#[test] | ||
fn strip_variation_selectors_逢坂() { | ||
let normal = "\u{9022}\u{5742}"; // 逢坂 | ||
let variant = "\u{9022}\u{E0101}\u{5742}"; // 逢󠄁坂 | ||
assert_ne!(normal, variant); | ||
assert_eq!(normal, variant.strip_variation_selectors()); | ||
} | ||
|
||
#[test] | ||
fn strip_variation_selectors_茨城() { | ||
let normal = "\u{8328}\u{57CE}"; | ||
let variant = "\u{8328}\u{E0100}\u{57CE}"; | ||
assert_ne!(normal, variant); | ||
assert_eq!(normal, variant.strip_variation_selectors()); | ||
} | ||
} |
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.
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.
次のPRで使用箇所が発生する予定