Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff4923a

Browse files
authored
Merge pull request#7 from theindigamer/add-emoji-example
Add a possible issue to the README.
2 parents9bc5375 +88bc3ea commitff4923a

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

‎README.md‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#unicode-width
22

33
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/)
67

78
[![Build Status](https://travis-ci.org/unicode-rs/unicode-width.svg)](https://travis-ci.org/unicode-rs/unicode-width)
89

@@ -23,6 +24,24 @@ fn main() {
2324
}
2425
```
2526

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+
externcrate unicode_width;
33+
useunicode_width::UnicodeWidthStr;
34+
35+
fnmain() {
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+
2645
##features
2746

2847
unicode-width does not depend on libstd, so it can be used in crates

‎src/tests.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ fn test_str() {
108108
assert_eq!("\u{2081}\u{2082}\u{2083}\u{2084}".width_cjk(),8);
109109
}
110110

111+
#[test]
112+
fntest_emoji(){
113+
// Example from the README.
114+
usesuper::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+
111121
#[test]
112122
fntest_char(){
113123
usesuper::UnicodeWidthChar;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp