From 6602390a06e0ef7d57798843fb4adee02a9a834c Mon Sep 17 00:00:00 2001 From: theindigamer Date: Thu, 11 Oct 2018 18:03:17 -0400 Subject: [PATCH 1/2] Add a possible issue to the README. --- README.md | 10 ++++++++++ src/tests.rs | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 53a096d..c74fa36 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,16 @@ fn main() { } ``` +**NOTE:** The computed width values may not match the actual rendered column +width. For example, the woman scientist emoji comprises of a woman emoji, a +zero-width joiner and a microscope emoji. + +```rust + assert_eq!(UnicodeWidthStr::width("👩"), 2); // Woman + assert_eq!(UnicodeWidthStr::width("🔬"), 2); // Microscope + assert_eq!(UnicodeWidthStr::width("👩‍🔬"), 4); // Woman scientist +``` + ## features unicode-width does not depend on libstd, so it can be used in crates diff --git a/src/tests.rs b/src/tests.rs index 2ba1e23..7e76b8f 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -108,6 +108,16 @@ fn test_str() { assert_eq!("\u{2081}\u{2082}\u{2083}\u{2084}".width_cjk(), 8); } +#[test] +fn test_emoji() { + // Example from the README. + use super::UnicodeWidthStr; + + assert_eq!(UnicodeWidthStr::width("👩"), 2); // Woman + assert_eq!(UnicodeWidthStr::width("🔬"), 2); // Microscope + assert_eq!(UnicodeWidthStr::width("👩‍🔬"), 4); // Woman scientist +} + #[test] fn test_char() { use super::UnicodeWidthChar; From 88bc3eafd69c93473a68b0e9ed9d03359ad4e5ff Mon Sep 17 00:00:00 2001 From: theindigamer Date: Thu, 11 Oct 2018 18:56:11 -0400 Subject: [PATCH 2/2] Add comment in README linking to UAX #11 for further details. --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c74fa36..8166ce1 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # unicode-width Determine displayed width of `char` and `str` types according to -[Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/) -rules. +[Unicode Standard Annex #11][UAX11] rules. + +[UAX11]: (http://www.unicode.org/reports/tr11/) [![Build Status](https://travis-ci.org/unicode-rs/unicode-width.svg)](https://travis-ci.org/unicode-rs/unicode-width) @@ -28,11 +29,19 @@ width. For example, the woman scientist emoji comprises of a woman emoji, a zero-width joiner and a microscope emoji. ```rust +extern crate unicode_width; +use unicode_width::UnicodeWidthStr; + +fn main() { assert_eq!(UnicodeWidthStr::width("👩"), 2); // Woman assert_eq!(UnicodeWidthStr::width("🔬"), 2); // Microscope assert_eq!(UnicodeWidthStr::width("👩‍🔬"), 4); // Woman scientist +} ``` +See [Unicode Standard Annex #11](UAX11) for precise details on what is and isn't +covered by this crate. + ## features unicode-width does not depend on libstd, so it can be used in crates