File tree 2 files changed +31
-2
lines changed
2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 1
1
# unicode-width
2
2
3
3
Determine displayed width of ` char ` and ` str ` types according to
4
- [ Unicode Standard Annex #11 ] ( http://www.unicode.org/reports/tr11/ )
5
- rules.
4
+ [ Unicode Standard Annex #11 ] [ UAX11 ] rules.
5
+
6
+ [ UAX11 ] : (http://www.unicode.org/reports/tr11/)
6
7
7
8
[ ![ Build Status] ( https://travis-ci.org/unicode-rs/unicode-width.svg )] ( https://travis-ci.org/unicode-rs/unicode-width )
8
9
@@ -23,6 +24,24 @@ fn main() {
23
24
}
24
25
```
25
26
27
+ ** NOTE:** The computed width values may not match the actual rendered column
28
+ width. For example, the woman scientist emoji comprises of a woman emoji, a
29
+ zero-width joiner and a microscope emoji.
30
+
31
+ ``` rust
32
+ extern crate unicode_width;
33
+ use unicode_width :: UnicodeWidthStr ;
34
+
35
+ fn main () {
36
+ assert_eq! (UnicodeWidthStr :: width (" 👩" ), 2 ); // Woman
37
+ assert_eq! (UnicodeWidthStr :: width (" 🔬" ), 2 ); // Microscope
38
+ assert_eq! (UnicodeWidthStr :: width (" 👩🔬" ), 4 ); // Woman scientist
39
+ }
40
+ ```
41
+
42
+ See [ Unicode Standard Annex #11 ] ( UAX11 ) for precise details on what is and isn't
43
+ covered by this crate.
44
+
26
45
## features
27
46
28
47
unicode-width does not depend on libstd, so it can be used in crates
Original file line number Diff line number Diff line change @@ -108,6 +108,16 @@ fn test_str() {
108
108
assert_eq ! ( "\u{2081} \u{2082} \u{2083} \u{2084} " . width_cjk( ) , 8 ) ;
109
109
}
110
110
111
+ #[ test]
112
+ fn test_emoji ( ) {
113
+ // Example from the README.
114
+ use super :: UnicodeWidthStr ;
115
+
116
+ assert_eq ! ( UnicodeWidthStr :: width( "👩" ) , 2 ) ; // Woman
117
+ assert_eq ! ( UnicodeWidthStr :: width( "🔬" ) , 2 ) ; // Microscope
118
+ assert_eq ! ( UnicodeWidthStr :: width( "👩🔬" ) , 4 ) ; // Woman scientist
119
+ }
120
+
111
121
#[ test]
112
122
fn test_char ( ) {
113
123
use super :: UnicodeWidthChar ;
You can’t perform that action at this time.
0 commit comments