-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37e4e44
commit 0e08645
Showing
3 changed files
with
29 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#![allow(dead_code)] | ||
|
||
use unicode_segmentation::UnicodeSegmentation; | ||
|
||
trait Trim { | ||
fn trim_count(&self, count: usize) -> String; | ||
} | ||
|
||
impl Trim for str { | ||
fn trim_count(&self, count: usize) -> String { | ||
UnicodeSegmentation::graphemes(self, true).take(count).collect() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_graphemes() { | ||
let s = "a̐éö̲\r\n"; | ||
let result = s.trim_count(2); | ||
assert_eq!(result, "a̐é"); | ||
} | ||
} |
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,2 +1,3 @@ | ||
pub mod graphemes; | ||
pub mod mutate_in_closure; | ||
pub mod vec_any; |