Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

View File

@@ -0,0 +1 @@
{"files":{"COPYRIGHT":"23860c2a7b5d96b21569afedf033469bab9fe14a1b24a35068b8641c578ce24d","Cargo.toml":"c455912954b250b8b2c6ca5cf83c29b4d4fb515a923d7dc349f6c9e6dd18439b","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"7b63ecd5f1902af1b63729947373683c32745c16a10e8e6292e2e2dcd7e90ae0","README.md":"57b83939f483d1acfce94d5eb369756e732a584dfe3b4c7054ea27751ad566db","benches/benches.rs":"4cfb510cd83882f31eacc974c65acd2b6a0ce659aadf300de921e659ace7d587","scripts/unicode.py":"e052a4c4c09e25926dbfa64969a0fde09cd4dbc373862908f412e36837e1cad0","src/lib.rs":"af71fa2d16706a1f15c9d3807829d8308c11ed4d974263ccf5a37d21a8c33982","src/tables.rs":"038d95e481399741ad549769f3c3a059c90f874c0dea3addadc9b33ab68fe633","tests/emoji-test.txt":"d876ee249aa28eaa76cfa6dfaa702847a8d13b062aa488d465d0395ee8137ed9","tests/tests.rs":"591d0ee54d434d4bf839b0054f0a4f410b42b118c27065192cd495bdf851940b"},"package":"7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"}

7
vendor/unicode-width/COPYRIGHT vendored Normal file
View File

@@ -0,0 +1,7 @@
Licensed under the Apache License, Version 2.0
<LICENSE-APACHE or
http://www.apache.org/licenses/LICENSE-2.0> or the MIT
license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
at your option. All files in the project carrying such
notice may not be copied, modified, or distributed except
according to those terms.

80
vendor/unicode-width/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,80 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "unicode-width"
version = "0.1.14"
authors = [
"kwantam <kwantam@gmail.com>",
"Manish Goregaokar <manishsmail@gmail.com>",
]
build = false
exclude = ["/.github/*"]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = """
Determine displayed width of `char` and `str` types
according to Unicode Standard Annex #11 rules.
"""
homepage = "https://github.com/unicode-rs/unicode-width"
readme = "README.md"
keywords = [
"text",
"width",
"unicode",
]
categories = [
"command-line-interface",
"internationalization",
"no-std::no-alloc",
"text-processing",
]
license = "MIT OR Apache-2.0"
repository = "https://github.com/unicode-rs/unicode-width"
[lib]
name = "unicode_width"
path = "src/lib.rs"
[[test]]
name = "tests"
path = "tests/tests.rs"
[[bench]]
name = "benches"
path = "benches/benches.rs"
[dependencies.compiler_builtins]
version = "0.1"
optional = true
[dependencies.core]
version = "1.0"
optional = true
package = "rustc-std-workspace-core"
[dependencies.std]
version = "1.0"
optional = true
package = "rustc-std-workspace-std"
[features]
cjk = []
default = ["cjk"]
no_std = []
rustc-dep-of-std = [
"std",
"core",
"compiler_builtins",
]

201
vendor/unicode-width/LICENSE-APACHE vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

25
vendor/unicode-width/LICENSE-MIT vendored Normal file
View File

@@ -0,0 +1,25 @@
Copyright (c) 2015 The Rust Project Developers
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

57
vendor/unicode-width/README.md vendored Normal file
View File

@@ -0,0 +1,57 @@
# `unicode-width`
[![Build status](https://github.com/unicode-rs/unicode-width/actions/workflows/rust.yml/badge.svg)](https://github.com/unicode-rs/unicode-width/actions/workflows/rust.yml)
[![crates.io version](https://img.shields.io/crates/v/unicode-width)](https://crates.io/crates/unicode-width)
[![Docs status](https://img.shields.io/docsrs/unicode-width)](https://docs.rs/unicode-width/)
Determine displayed width of `char` and `str` types according to [Unicode Standard Annex #11][UAX11]
and other portions of the Unicode standard.
This crate is `#![no_std]`.
[UAX11]: http://www.unicode.org/reports/tr11/
```rust
use unicode_width::UnicodeWidthStr;
fn main() {
let teststr = ", !";
let width = teststr.width();
println!("{}", teststr);
println!("The above string is {} columns wide.", width);
let width = teststr.width_cjk();
println!("The above string is {} columns wide (CJK).", width);
}
```
**NOTE:** The computed width values may not match the actual rendered column
width. For example, many Brahmic scripts like Devanagari have complex rendering rules
which this crate does not currently handle (and will never fully handle, because
the exact rendering depends on the font):
```rust
extern crate unicode_width;
use unicode_width::UnicodeWidthStr;
fn main() {
assert_eq!("".width(), 1); // Devanagari letter Ka
assert_eq!("".width(), 1); // Devanagari letter Ssa
assert_eq!("क्ष".width(), 2); // Ka + Virama + Ssa
}
```
Additionally, [defective combining character sequences](https://unicode.org/glossary/#defective_combining_character_sequence)
and nonstandard [Korean jamo](https://unicode.org/glossary/#jamo) sequences may
be rendered with a different width than what this crate says. (This is not an
exhaustive list.) For a list of what this crate *does* handle, see
[docs.rs](https://docs.rs/unicode-width/latest/unicode_width/#rules-for-determining-width).
## crates.io
You can use this package in your project by adding the following
to your `Cargo.toml`:
```toml
[dependencies]
unicode-width = "0.1.11"
```

114
vendor/unicode-width/benches/benches.rs vendored Normal file
View File

@@ -0,0 +1,114 @@
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(test)]
extern crate test;
use std::iter;
use test::Bencher;
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
#[bench]
fn cargo(b: &mut Bencher) {
let string = iter::repeat('a').take(4096).collect::<String>();
b.iter(|| {
for c in string.chars() {
test::black_box(UnicodeWidthChar::width(c));
}
});
}
#[bench]
#[allow(deprecated)]
fn stdlib(b: &mut Bencher) {
let string = iter::repeat('a').take(4096).collect::<String>();
b.iter(|| {
for c in string.chars() {
test::black_box(c.width());
}
});
}
#[bench]
fn simple_if(b: &mut Bencher) {
let string = iter::repeat('a').take(4096).collect::<String>();
b.iter(|| {
for c in string.chars() {
test::black_box(simple_width_if(c));
}
});
}
#[bench]
fn simple_match(b: &mut Bencher) {
let string = iter::repeat('a').take(4096).collect::<String>();
b.iter(|| {
for c in string.chars() {
test::black_box(simple_width_match(c));
}
});
}
#[inline]
fn simple_width_if(c: char) -> Option<usize> {
let cu = c as u32;
if cu < 127 {
if cu > 31 {
Some(1)
} else if cu == 0 {
Some(0)
} else {
None
}
} else {
UnicodeWidthChar::width(c)
}
}
#[inline]
fn simple_width_match(c: char) -> Option<usize> {
match c as u32 {
cu if cu == 0 => Some(0),
cu if cu < 0x20 => None,
cu if cu < 0x7f => Some(1),
_ => UnicodeWidthChar::width(c),
}
}
#[bench]
fn enwik8(b: &mut Bencher) {
// To benchmark, download & unzip `enwik8` from https://data.deepai.org/enwik8.zip
let data_path = "bench_data/enwik8";
let string = std::fs::read_to_string(data_path).unwrap_or_default();
b.iter(|| test::black_box(UnicodeWidthStr::width(string.as_str())));
}
#[bench]
fn jawiki(b: &mut Bencher) {
// To benchmark, download & extract `jawiki-20220501-pages-articles-multistream-index.txt` from
// https://dumps.wikimedia.org/jawiki/20220501/jawiki-20220501-pages-articles-multistream-index.txt.bz2
let data_path = "bench_data/jawiki-20220501-pages-articles-multistream-index.txt";
let string = std::fs::read_to_string(data_path).unwrap_or_default();
b.iter(|| test::black_box(UnicodeWidthStr::width(string.as_str())));
}
#[bench]
fn emoji(b: &mut Bencher) {
// To benchmark, download emoji-style.txt from https://www.unicode.org/emoji/charts/emoji-style.txt
let data_path = "bench_data/emoji-style.txt";
let string = std::fs::read_to_string(data_path).unwrap_or_default();
b.iter(|| test::black_box(UnicodeWidthStr::width(string.as_str())));
}

2156
vendor/unicode-width/scripts/unicode.py vendored Executable file

File diff suppressed because it is too large Load Diff

258
vendor/unicode-width/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,258 @@
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Determine displayed width of `char` and `str` types according to
//! [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
//! and other portions of the Unicode standard.
//! See the [Rules for determining width](#rules-for-determining-width) section
//! for the exact rules.
//!
//! This crate is `#![no_std]`.
//!
//! ```rust
//! use unicode_width::UnicodeWidthStr;
//!
//! let teststr = ", !";
//! let width = UnicodeWidthStr::width(teststr);
//! println!("{}", teststr);
//! println!("The above string is {} columns wide.", width);
//! ```
//!
//! # `"cjk"` feature flag
//!
//! This crate has one Cargo feature flag, `"cjk"`
//! (enabled by default).
//! It enables the [`UnicodeWidthChar::width_cjk`]
//! and [`UnicodeWidthStr::width_cjk`],
//! which perform an alternate width calculation
//! more suited to CJK contexts. The flag also unseals the
//! [`UnicodeWidthChar`] and [`UnicodeWidthStr`] traits.
//!
//! Disabling the flag (with `no_default_features` in `Cargo.toml`)
//! will reduce the amount of static data needed by the crate.
//!
//! ```rust
//! use unicode_width::UnicodeWidthStr;
//!
//! let teststr = "“𘀀”";
//! assert_eq!(teststr.width(), 4);
//!
//! #[cfg(feature = "cjk")]
//! assert_eq!(teststr.width_cjk(), 6);
//! ```
//!
//! # Rules for determining width
//!
//! This crate currently uses the following rules to determine the width of a
//! character or string, in order of decreasing precedence. These may be tweaked in the future.
//!
//! 1. In the following cases, the width of a string differs from the sum of the widths of its constituent characters:
//! - The sequence `"\r\n"` has width 1.
//! - Emoji-specific ligatures:
//! - Well-formed, fully-qualified [emoji ZWJ sequences] have width 2.
//! - [Emoji modifier sequences] have width 2.
//! - [Emoji presentation sequences] have width 2.
//! - Outside of an East Asian context, [text presentation sequences] have width 1 if their base character:
//! - Has the [`Emoji_Presentation`] property, and
//! - Is not in the [Enclosed Ideographic Supplement] block.
//! - Script-specific ligatures:
//! - For all the following ligatures, the insertion of any number of [default-ignorable][`Default_Ignorable_Code_Point`]
//! [combining marks] anywhere in the sequence will not change the total width. In addition, for all non-Arabic
//! ligatures, the insertion of any number of [`'\u{200D}'` ZERO WIDTH JOINER](https://www.unicode.org/versions/Unicode15.0.0/ch23.pdf#G23126)s
//! will not affect the width.
//! - **[Arabic]**: A character sequence consisting of one character with [`Joining_Group`]`=Lam`,
//! followed by any number of characters with [`Joining_Type`]`=Transparent`, followed by one character
//! with [`Joining_Group`]`=Alef`, has total width 1. For example: `لا`, `لآ`, `ڸا`, `لٟٞأ`
//! - **[Buginese]**: `"\u{1A15}\u{1A17}\u{200D}\u{1A10}"` (<a, -i> ya, `ᨕᨗ‍ᨐ`) has total width 1.
//! - **[Hebrew]**: `"א\u{200D}ל"` (Alef-Lamed, `א‍ל`) has total width 1.
//! - **[Khmer]**: Coeng signs consisting of `'\u{17D2}'` followed by a character in
//! `'\u{1780}'..='\u{1782}' | '\u{1784}'..='\u{1787}' | '\u{1789}'..='\u{178C}' | '\u{178E}'..='\u{1793}' | '\u{1795}'..='\u{1798}' | '\u{179B}'..='\u{179D}' | '\u{17A0}' | '\u{17A2}' | '\u{17A7}' | '\u{17AB}'..='\u{17AC}' | '\u{17AF}'`
//! have width 0.
//! - **[Lisu]**: Tone letter combinations consisting of a character in the range `'\u{A4F8}'..='\u{A4FB}'`
//! followed by a character in the range `'\u{A4FC}'..='\u{A4FD}'` have width 1. For example: `ꓹꓼ`
//! - **[Old Turkic]**: `"\u{10C32}\u{200D}\u{10C03}"` (`𐰲‍𐰃`) has total width 1.
//! - **[Tifinagh]**: A sequence of a Tifinagh consonant in the range `'\u{2D31}'..='\u{2D65}' | '\u{2D6F}'`, followed by either
//! [`'\u{2D7F}'` TIFINAGH CONSONANT JOINER] or `'\u{200D}'`, followed by another Tifinangh consonant, has total width 1.
//! For example: `ⵏ⵿ⴾ`
//! - In an East Asian context only, `<`, `=`, or `>` have width 2 when followed by [`'\u{0338}'` COMBINING LONG SOLIDUS OVERLAY].
//! The two characters may be separated by any number of characters whose canonical decompositions consist only of characters meeting
//! one of the following requirements:
//! - Has [`Canonical_Combining_Class`] greater than 1, or
//! - Is a [default-ignorable][`Default_Ignorable_Code_Point`] [combining mark][combining marks].
//! 2. In all other cases, the width of the string equals the sum of its character widths:
//! 1. [`'\u{2D7F}'` TIFINAGH CONSONANT JOINER] has width 1 (outside of the ligatures described previously).
//! 2. [`'\u{115F}'` HANGUL CHOSEONG FILLER](https://util.unicode.org/UnicodeJsps/character.jsp?a=115F) and
//! [`'\u{17A4}'` KHMER INDEPENDENT VOWEL QAA](https://util.unicode.org/UnicodeJsps/character.jsp?a=17A4) have width 2.
//! 3. [`'\u{17D8}'` KHMER SIGN BEYYAL](https://util.unicode.org/UnicodeJsps/character.jsp?a=17D8) has width 3.
//! 4. The following have width 0:
//! - [Characters](https://util.unicode.org/UnicodeJsps/list-unicodeset.jsp?a=%5Cp%7BDefault_Ignorable_Code_Point%7D)
//! with the [`Default_Ignorable_Code_Point`] property.
//! - [Characters](https://util.unicode.org/UnicodeJsps/list-unicodeset.jsp?a=%5Cp%7BGrapheme_Extend%7D)
//! with the [`Grapheme_Extend`] property.
//! - The following 8 characters, all of which have NFD decompositions consisting of two [`Grapheme_Extend`] characters:
//! - [`'\u{0CC0}'` KANNADA VOWEL SIGN II](https://util.unicode.org/UnicodeJsps/character.jsp?a=0CC0),
//! - [`'\u{0CC7}'` KANNADA VOWEL SIGN EE](https://util.unicode.org/UnicodeJsps/character.jsp?a=0CC7),
//! - [`'\u{0CC8}'` KANNADA VOWEL SIGN AI](https://util.unicode.org/UnicodeJsps/character.jsp?a=0CC8),
//! - [`'\u{0CCA}'` KANNADA VOWEL SIGN O](https://util.unicode.org/UnicodeJsps/character.jsp?a=0CCA),
//! - [`'\u{0CCB}'` KANNADA VOWEL SIGN OO](https://util.unicode.org/UnicodeJsps/character.jsp?a=0CCB),
//! - [`'\u{1B3B}'` BALINESE VOWEL SIGN RA REPA TEDUNG](https://util.unicode.org/UnicodeJsps/character.jsp?a=1B3B),
//! - [`'\u{1B3D}'` BALINESE VOWEL SIGN LA LENGA TEDUNG](https://util.unicode.org/UnicodeJsps/character.jsp?a=1B3D), and
//! - [`'\u{1B43}'` BALINESE VOWEL SIGN PEPET TEDUNG](https://util.unicode.org/UnicodeJsps/character.jsp?a=1B43).
//! - [Characters](https://util.unicode.org/UnicodeJsps/list-unicodeset.jsp?a=%5Cp%7BHangul_Syllable_Type%3DV%7D%5Cp%7BHangul_Syllable_Type%3DT%7D)
//! with a [`Hangul_Syllable_Type`] of `Vowel_Jamo` (`V`) or `Trailing_Jamo` (`T`).
//! - The following [`Prepended_Concatenation_Mark`]s:
//! - [`'\u{0605}'` NUMBER MARK ABOVE](https://util.unicode.org/UnicodeJsps/character.jsp?a=0605),
//! - [`'\u{070F}'` SYRIAC ABBREVIATION MARK](https://util.unicode.org/UnicodeJsps/character.jsp?a=070F),
//! - [`'\u{0890}'` POUND MARK ABOVE](https://util.unicode.org/UnicodeJsps/character.jsp?a=0890),
//! - [`'\u{0891}'` PIASTRE MARK ABOVE](https://util.unicode.org/UnicodeJsps/character.jsp?a=0891), and
//! - [`'\u{08E2}'` DISPUTED END OF AYAH](https://util.unicode.org/UnicodeJsps/character.jsp?a=08E2).
//! - [Characters](https://util.unicode.org/UnicodeJsps/list-unicodeset.jsp?a=%5Cp%7BGrapheme_Cluster_Break%3DPrepend%7D-%5Cp%7BPrepended_Concatenation_Mark%7D)
//! with the [`Grapheme_Extend=Prepend`] property, that are not also [`Prepended_Concatenation_Mark`]s.
//! - [`'\u{A8FA}'` DEVANAGARI CARET](https://util.unicode.org/UnicodeJsps/character.jsp?a=A8FA).
//! 5. [Characters](https://util.unicode.org/UnicodeJsps/list-unicodeset.jsp?a=%5Cp%7BEast_Asian_Width%3DF%7D%5Cp%7BEast_Asian_Width%3DW%7D)
//! with an [`East_Asian_Width`] of [`Fullwidth`] or [`Wide`] have width 2.
//! 6. Characters fulfilling all of the following conditions have width 2 in an East Asian context, and width 1 otherwise:
//! - Has an [`East_Asian_Width`] of [`Ambiguous`], or
//! has a canonical decomposition to an [`Ambiguous`] character followed by [`'\u{0338}'` COMBINING LONG SOLIDUS OVERLAY], or
//! is [`'\u{0387}'` GREEK ANO TELEIA](https://util.unicode.org/UnicodeJsps/character.jsp?a=0387), and
//! - Does not have a [`General_Category`] of `Letter` or `Modifier_Symbol`.
//! 7. All other characters have width 1.
//!
//! [`'\u{0338}'` COMBINING LONG SOLIDUS OVERLAY]: https://util.unicode.org/UnicodeJsps/character.jsp?a=0338
//! [`'\u{2D7F}'` TIFINAGH CONSONANT JOINER]: https://util.unicode.org/UnicodeJsps/character.jsp?a=2D7F
//!
//! [`Canonical_Combining_Class`]: https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf#G50313
//! [`Default_Ignorable_Code_Point`]: https://www.unicode.org/versions/Unicode15.0.0/ch05.pdf#G40095
//! [`East_Asian_Width`]: https://www.unicode.org/reports/tr11/#ED1
//! [`Emoji_Presentation`]: https://unicode.org/reports/tr51/#def_emoji_presentation
//! [`General_Category`]: https://www.unicode.org/versions/Unicode15.0.0/ch04.pdf#G124142
//! [`Grapheme_Extend=Prepend`]: https://www.unicode.org/reports/tr29/#Prepend
//! [`Grapheme_Extend`]: https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf#G52443
//! [`Hangul_Syllable_Type`]: https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf#G45593
//! [`Joining_Group`]: https://www.unicode.org/versions/Unicode14.0.0/ch09.pdf#G36862
//! [`Joining_Type`]: http://www.unicode.org/versions/Unicode15.0.0/ch09.pdf#G50009
//! [`Prepended_Concatenation_Mark`]: https://www.unicode.org/versions/Unicode15.0.0/ch23.pdf#G37908
//! [`Script`]: https://www.unicode.org/reports/tr24/#Script
//!
//! [`Fullwidth`]: https://www.unicode.org/reports/tr11/#ED2
//! [`Wide`]: https://www.unicode.org/reports/tr11/#ED4
//! [`Ambiguous`]: https://www.unicode.org/reports/tr11/#ED6
//!
//! [combining marks]: https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf#G30602
//!
//! [emoji ZWJ sequences]: https://www.unicode.org/reports/tr51/#def_emoji_sequence
//! [Emoji modifier sequences]: https://www.unicode.org/reports/tr51/#def_emoji_modifier_sequence
//! [Emoji presentation sequences]: https://unicode.org/reports/tr51/#def_emoji_presentation_sequence
//! [text presentation sequences]: https://unicode.org/reports/tr51/#def_text_presentation_sequence
//!
//! [Enclosed Ideographic Supplement]: https://unicode.org/charts/nameslist/n_1F200.html
//!
//! [Arabic]: https://www.unicode.org/versions/Unicode15.0.0/ch09.pdf#G7480
//! [Buginese]: https://www.unicode.org/versions/Unicode15.0.0/ch17.pdf#G26743
//! [Hebrew]: https://www.unicode.org/versions/Unicode15.0.0/ch09.pdf#G6528
//! [Khmer]: https://www.unicode.org/versions/Unicode15.0.0/ch16.pdf#G64642
//! [Lisu]: https://www.unicode.org/versions/Unicode15.0.0/ch18.pdf#G44587
//! [Old Turkic]: https://www.unicode.org/versions/Unicode15.0.0/ch14.pdf#G41975
//! [Tifinagh]: http://www.unicode.org/versions/Unicode15.0.0/ch19.pdf#G43184
//!
//!
//! ## Canonical equivalence
//!
//! Canonically equivalent strings are assigned the same width (CJK and non-CJK).
#![forbid(unsafe_code)]
#![deny(missing_docs)]
#![doc(
html_logo_url = "https://unicode-rs.github.io/unicode-rs_sm.png",
html_favicon_url = "https://unicode-rs.github.io/unicode-rs_sm.png"
)]
#![no_std]
pub use tables::UNICODE_VERSION;
mod tables;
mod private {
pub trait Sealed {}
#[cfg(not(feature = "cjk"))]
impl Sealed for char {}
#[cfg(not(feature = "cjk"))]
impl Sealed for str {}
#[cfg(feature = "cjk")]
impl<T: ?Sized> Sealed for T {}
}
/// Methods for determining displayed width of Unicode characters.
pub trait UnicodeWidthChar: private::Sealed {
/// Returns the character's displayed width in columns, or `None` if the
/// character is a control character.
///
/// This function treats characters in the Ambiguous category according
/// to [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
/// as 1 column wide. This is consistent with the recommendations for non-CJK
/// contexts, or when the context cannot be reliably determined.
fn width(self) -> Option<usize>;
/// Returns the character's displayed width in columns, or `None` if the
/// character is a control character.
///
/// This function treats characters in the Ambiguous category according
/// to [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
/// as 2 columns wide. This is consistent with the recommendations for
/// CJK contexts.
#[cfg(feature = "cjk")]
fn width_cjk(self) -> Option<usize>;
}
impl UnicodeWidthChar for char {
#[inline]
fn width(self) -> Option<usize> {
tables::single_char_width(self)
}
#[cfg(feature = "cjk")]
#[inline]
fn width_cjk(self) -> Option<usize> {
tables::single_char_width_cjk(self)
}
}
/// Methods for determining displayed width of Unicode strings.
pub trait UnicodeWidthStr: private::Sealed {
/// Returns the string's displayed width in columns.
///
/// This function treats characters in the Ambiguous category according
/// to [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
/// as 1 column wide. This is consistent with the recommendations for
/// non-CJK contexts, or when the context cannot be reliably determined.
fn width(&self) -> usize;
/// Returns the string's displayed width in columns.
///
/// This function treats characters in the Ambiguous category according
/// to [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
/// as 2 column wide. This is consistent with the recommendations for
/// CJK contexts.
#[cfg(feature = "cjk")]
fn width_cjk(&self) -> usize;
}
impl UnicodeWidthStr for str {
#[inline]
fn width(&self) -> usize {
tables::str_width(self)
}
#[cfg(feature = "cjk")]
#[inline]
fn width_cjk(&self) -> usize {
tables::str_width_cjk(self)
}
}

21762
vendor/unicode-width/src/tables.rs vendored Normal file

File diff suppressed because it is too large Load Diff

5325
vendor/unicode-width/tests/emoji-test.txt vendored Normal file

File diff suppressed because it is too large Load Diff

631
vendor/unicode-width/tests/tests.rs vendored Normal file
View File

@@ -0,0 +1,631 @@
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::{
fs::File,
io::{BufRead, BufReader},
};
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
macro_rules! assert_width {
($s:expr, $nocjk:expr, $cjk:expr $(,)?) => {{
assert_eq!($s.width(), $nocjk, "{:?} has the wrong width", $s);
#[cfg(feature = "cjk")]
assert_eq!($s.width_cjk(), $cjk, "{:?} has the wrong width (CJK)", $s);
}};
}
#[test]
fn test_str() {
assert_width!("", 10, 10);
assert_width!("\0\0\0\x01\x01", 5, 5);
assert_width!("", 0, 0);
assert_width!("\u{2081}\u{2082}\u{2083}\u{2084}", 4, 8);
}
#[test]
fn test_emoji() {
assert_width!("👩", 2, 2); // Woman
assert_width!("🔬", 2, 2); // Microscope
assert_width!("👩‍🔬", 2, 2); // Woman scientist
}
// From README
#[test]
fn test_bad_devanagari() {
assert_eq!("".width(), 1); // Devanagari letter Ka
assert_eq!("".width(), 1); // Devanagari letter Ssa
assert_eq!("क्ष".width(), 2); // Ka + Virama + Ssa
}
#[test]
fn test_char() {
assert_width!('', Some(2), Some(2));
assert_width!('\x00', None, None);
assert_width!('\x01', None, None);
assert_width!('\u{2081}', Some(1), Some(2));
}
#[test]
fn test_char2() {
assert_width!('\x0A', None, None);
assert_width!('w', Some(1), Some(1));
assert_width!('', Some(2), Some(2));
assert_width!('\u{AD}', Some(0), Some(0));
assert_width!('\u{1160}', Some(0), Some(0));
assert_width!('\u{a1}', Some(1), Some(2));
assert_width!('\u{300}', Some(0), Some(0));
}
#[test]
fn unicode_12() {
assert_width!('\u{1F971}', Some(2), Some(2));
}
#[test]
fn test_default_ignorable() {
assert_width!('\u{1160}', Some(0), Some(0));
assert_width!('\u{3164}', Some(0), Some(0));
assert_width!('\u{FFA0}', Some(0), Some(0));
assert_width!('\u{E0000}', Some(0), Some(0));
}
#[test]
fn test_ambiguous() {
assert_width!("\u{B7}", 1, 2);
assert_width!("\u{0387}", 1, 2);
assert_width!("\u{A8}", 1, 1);
assert_width!("\u{02C9}", 1, 1);
}
#[test]
fn test_jamo() {
assert_width!('\u{1100}', Some(2), Some(2));
assert_width!('\u{A97C}', Some(2), Some(2));
// Special case: U+115F HANGUL CHOSEONG FILLER
assert_width!('\u{115F}', Some(2), Some(2));
assert_width!('\u{1160}', Some(0), Some(0));
assert_width!('\u{D7C6}', Some(0), Some(0));
assert_width!('\u{11A8}', Some(0), Some(0));
assert_width!('\u{D7FB}', Some(0), Some(0));
}
#[test]
fn test_prepended_concatenation_marks() {
for c in [
'\u{0600}',
'\u{0601}',
'\u{0602}',
'\u{0603}',
'\u{0604}',
'\u{06DD}',
'\u{110BD}',
'\u{110CD}',
] {
assert_width!(c, Some(1), Some(1));
}
for c in ['\u{0605}', '\u{070F}', '\u{0890}', '\u{0891}', '\u{08E2}'] {
assert_width!(c, Some(0), Some(0));
}
}
#[test]
fn test_gcb_prepend() {
assert_width!("ൎഉ", 1, 1);
assert_width!("\u{11A89}", 0, 0);
}
#[test]
fn test_interlinear_annotation_chars() {
assert_width!('\u{FFF9}', Some(1), Some(1));
assert_width!('\u{FFFA}', Some(1), Some(1));
assert_width!('\u{FFFB}', Some(1), Some(1));
}
#[test]
fn test_hieroglyph_format_controls() {
assert_width!('\u{13430}', Some(1), Some(1));
assert_width!('\u{13436}', Some(1), Some(1));
assert_width!('\u{1343C}', Some(1), Some(1));
}
#[test]
fn test_marks() {
// Nonspacing marks have 0 width
assert_width!('\u{0301}', Some(0), Some(0));
// Enclosing marks have 0 width
assert_width!('\u{20DD}', Some(0), Some(0));
// Some spacing marks have width 1
assert_width!('\u{09CB}', Some(1), Some(1));
// But others have width 0
assert_width!('\u{09BE}', Some(0), Some(0));
}
#[test]
fn test_devanagari_caret() {
assert_width!('\u{A8FA}', Some(0), Some(0));
}
#[test]
fn test_solidus_overlay() {
assert_width!("<\u{338}", 1, 2);
assert_width!("=\u{338}", 1, 2);
assert_width!(">\u{338}", 1, 2);
assert_width!("=\u{301}\u{338}", 1, 2);
assert_width!("=\u{338}\u{301}", 1, 2);
assert_width!("=\u{FE0F}\u{338}", 1, 2);
assert_width!("#\u{FE0F}\u{338}", 2, 2);
assert_width!("#\u{338}\u{FE0F}", 1, 1);
assert_width!("\u{06B8}\u{338}\u{0627}", 1, 1);
assert_width!("\u{06B8}\u{338}\u{FE0E}\u{0627}", 1, 1);
assert_width!("\u{06B8}\u{338}\u{FE0F}\u{0627}", 1, 1);
assert_width!("\u{06B8}\u{FE0E}\u{338}\u{0627}", 1, 1);
assert_width!("\u{06B8}\u{FE0F}\u{338}\u{0627}", 1, 1);
assert_width!("=\u{338}\u{0627}", 2, 3);
}
#[test]
fn test_emoji_presentation() {
assert_width!('\u{0023}', Some(1), Some(1));
assert_width!('\u{FE0F}', Some(0), Some(0));
assert_width!("\u{0023}\u{FE0F}", 2, 2);
assert_width!("a\u{0023}\u{FE0F}a", 4, 4);
assert_width!("\u{0023}a\u{FE0F}", 2, 2);
assert_width!("a\u{FE0F}", 1, 1);
assert_width!("\u{0023}\u{0023}\u{FE0F}a", 4, 4);
assert_width!("\u{002A}\u{FE0F}", 2, 2);
assert_width!("\u{23F9}\u{FE0F}", 2, 2);
assert_width!("\u{24C2}\u{FE0F}", 2, 2);
assert_width!("\u{1F6F3}\u{FE0F}", 2, 2);
assert_width!("\u{1F700}\u{FE0F}", 1, 1);
assert_width!("\u{002A}\u{301}\u{FE0F}", 1, 1);
assert_width!("\u{002A}\u{200D}\u{FE0F}", 1, 1);
assert_width!("\u{002A}\u{FE0E}\u{FE0F}", 1, 1);
}
#[test]
fn test_text_presentation() {
assert_width!('\u{FE0E}', Some(0), Some(0));
assert_width!('\u{2648}', Some(2), Some(2));
assert_width!("\u{2648}\u{FE0E}", 1, 2);
assert_width!("\u{1F21A}\u{FE0E}", 2, 2);
assert_width!("\u{0301}\u{FE0E}", 0, 0);
assert_width!("a\u{FE0E}", 1, 1);
assert_width!("𘀀\u{FE0E}", 2, 2);
assert_width!("\u{2648}\u{0301}\u{FE0E}", 2, 2);
assert_width!("\u{2648}\u{200D}\u{FE0E}", 2, 2);
}
#[test]
fn test_control_line_break() {
assert_width!('\u{2028}', Some(1), Some(1));
assert_width!('\u{2029}', Some(1), Some(1));
assert_width!('\r', None, None);
assert_width!('\n', None, None);
assert_width!("\r", 1, 1);
// This is 0 due to #60
assert_width!("\n", 0, 0);
assert_width!("\r\n", 0, 0);
assert_width!("\0", 1, 1);
assert_width!("1\t2\r\n3\u{85}4", 6, 6);
assert_width!("\r\u{FE0F}\n", 1, 1);
assert_width!("\r\u{200D}\n", 1, 1);
}
#[test]
fn char_str_consistent() {
let mut s = String::with_capacity(4);
for c in '\0'..=char::MAX {
// Newlines are special cased (#60)
if c == '\n' {
continue;
}
s.clear();
s.push(c);
assert_eq!(c.width().unwrap_or(1), s.width());
#[cfg(feature = "cjk")]
assert_eq!(c.width_cjk().unwrap_or(1), s.width_cjk());
}
}
#[test]
fn test_lisu_tones() {
for c in '\u{A4F8}'..='\u{A4FD}' {
assert_width!(c, Some(1), Some(1));
assert_width!(String::from(c), 1, 1);
}
for c1 in '\u{A4F8}'..='\u{A4FD}' {
for c2 in '\u{A4F8}'..='\u{A4FD}' {
let mut s = String::with_capacity(8);
s.push(c1);
s.push(c2);
match (c1, c2) {
('\u{A4F8}'..='\u{A4FB}', '\u{A4FC}'..='\u{A4FD}') => assert_width!(s, 1, 1),
_ => assert_width!(s, 2, 2),
}
}
}
assert_width!("", 2, 2);
assert_width!("ꓪꓹꓼ", 2, 2);
assert_width!("\u{FE0F}", 2, 2);
assert_width!("\u{200D}", 2, 2);
assert_width!("ꓪꓹꓼ\u{FE0F}", 2, 2);
assert_width!("\u{0301}", 3, 3);
assert_width!("", 3, 3);
assert_width!("ꓪꓼꓼ", 3, 3);
}
#[test]
fn test_hebrew_alef_lamed() {
assert_width!("\u{05D0}", 1, 1);
assert_width!("\u{05DC}", 1, 1);
assert_width!("\u{05D0}\u{05DC}", 2, 2);
assert_width!("\u{05D0}\u{200D}\u{05DC}", 1, 1);
assert_width!(
"\u{05D0}\u{200D}\u{200D}\u{200D}\u{200D}\u{200D}\u{200D}\u{200D}\u{05DC}",
1,
1,
);
assert_width!("\u{05D0}\u{05D0}\u{200D}\u{05DC}", 2, 2);
assert_width!(
"\u{05D0}\u{05D0}\u{200D}\u{200D}\u{200D}\u{200D}\u{200D}\u{200D}\u{05DC}",
2,
2,
);
assert_width!("\u{05D0}\u{FE0F}\u{200D}\u{FE0F}\u{05DC}\u{FE0F}", 1, 1);
assert_width!("\u{05D0}\u{FE0E}\u{200D}\u{FE0E}\u{05DC}\u{FE0E}", 1, 1);
}
#[test]
fn test_arabic_lam_alef() {
assert_width!("\u{0644}", 1, 1);
assert_width!("\u{06B8}", 1, 1);
assert_width!("\u{0623}", 1, 1);
assert_width!("\u{0627}", 1, 1);
assert_width!("\u{0644}\u{0623}", 1, 1);
assert_width!("\u{0644}\u{0627}", 1, 1);
assert_width!("\u{06B8}\u{0623}", 1, 1);
assert_width!("\u{06B8}\u{0627}", 1, 1);
assert_width!("\u{0644}\u{065F}\u{065E}\u{0623}", 1, 1);
assert_width!("\u{0644}\u{065F}\u{065E}\u{0627}", 1, 1);
assert_width!("\u{06B8}\u{065F}\u{065E}\u{0623}", 1, 1);
assert_width!("\u{06B8}\u{065F}\u{065E}\u{0627}", 1, 1);
assert_width!("\u{06B8}\u{FE0E}\u{0627}", 1, 1);
assert_width!("\u{06B8}\u{FE0F}\u{0627}", 1, 1);
assert_width!("\u{06B8}\u{17B5}\u{0627}", 1, 1);
assert_width!("\u{0644}\u{0644}\u{0623}", 2, 2);
assert_width!("\u{0644}\u{0644}\u{0627}", 2, 2);
assert_width!("\u{06B8}\u{06B8}\u{0623}", 2, 2);
assert_width!("\u{06B8}\u{06B8}\u{0627}", 2, 2);
assert_width!("\u{0644}\u{200D}\u{0623}", 2, 2);
assert_width!("\u{0644}\u{200D}\u{0627}", 2, 2);
assert_width!("\u{06B8}\u{200D}\u{0623}", 2, 2);
assert_width!("\u{06B8}\u{200D}\u{0627}", 2, 2);
assert_width!("\u{0644}\u{1E94B}\u{0623}", 3, 3);
assert_width!("\u{0644}\u{1E94B}\u{0627}", 3, 3);
assert_width!("\u{06B8}\u{1E94B}\u{0623}", 3, 3);
assert_width!("\u{06B8}\u{1E94B}\u{0627}", 3, 3);
}
#[test]
fn test_buginese_a_i_ya() {
assert_width!("\u{1A15}", 1, 1);
assert_width!("\u{1A17}", 0, 0);
assert_width!("\u{1A10}", 1, 1);
assert_width!("\u{1A15}\u{1A17}\u{200D}\u{1A10}", 1, 1);
assert_width!(
"\u{1A15}\u{1A17}\u{200D}\u{200D}\u{200D}\u{200D}\u{1A10}",
1,
1,
);
assert_width!("\u{1A15}\u{1A17}\u{200D}\u{338}", 1, 1);
assert_width!("\u{1A15}\u{FE0E}\u{1A17}\u{200D}", 1, 1);
assert_width!("\u{1A15}\u{FE0F}\u{1A17}\u{200D}", 1, 1);
assert_width!("\u{1A15}\u{1A17}\u{FE0E}\u{200D}", 1, 1);
assert_width!("\u{1A15}\u{1A17}\u{FE0F}\u{200D}", 1, 1);
assert_width!("\u{1A15}\u{1A17}\u{200D}\u{FE0E}", 1, 1);
assert_width!("\u{1A15}\u{1A17}\u{200D}\u{FE0F}", 1, 1);
assert_width!(
"\u{1A15}\u{17B5}\u{200D}\u{FE0E}\u{1A17}\u{200D}\u{FE0F}\u{200D}\u{FE0F}",
1,
1,
);
assert_width!("\u{1A15}\u{1A15}\u{1A17}\u{200D}\u{1A10}", 2, 2);
assert_width!(
"\u{1A15}\u{1A15}\u{1A17}\u{200D}\u{200D}\u{200D}\u{200D}\u{1A10}",
2,
2,
);
assert_width!("\u{1A15}\u{1A17}\u{1A10}", 2, 2);
assert_width!("\u{1A15}\u{200D}\u{1A10}", 2, 2);
assert_width!("\u{1A15}\u{1A10}", 2, 2);
assert_width!("\u{1A15}\u{1A17}\u{1A17}\u{200D}\u{1A10}", 2, 2);
assert_width!("\u{1A15}\u{1A17}\u{338}\u{200D}\u{1A10}", 2, 2);
}
#[test]
fn test_tifinagh_biconsonants() {
assert_width!("\u{2D4F}", 1, 1);
assert_width!("\u{2D3E}", 1, 1);
assert_width!("\u{2D7F}", 1, 1);
assert_width!("\u{2D4F}\u{200D}\u{2D3E}", 1, 1);
assert_width!("\u{2D4F}\u{2D7F}\u{2D3E}", 1, 1);
assert_width!("\u{2D4F}\u{200D}\u{2D3E}", 1, 1);
assert_width!(
"\u{2D4F}\u{FE0F}\u{200D}\u{2D7F}\u{FE0E}\u{200D}\u{17B5}\u{2D3E}",
1,
1,
);
assert_width!("\u{2D4F}\u{301}\u{2D7F}\u{2D3E}", 3, 3);
assert_width!("\u{2D4F}\u{301}\u{200D}\u{2D3E}", 2, 2);
assert_width!("\u{2D4F}\u{2D3E}", 2, 2);
assert_width!("\u{2D4F}\u{2D7F}\u{2D7F}\u{2D3E}", 4, 4);
assert_width!("\u{2D7F}\u{2D3E}", 2, 2);
assert_width!("\u{2D7F}\u{2D7F}\u{2D66}", 3, 3);
assert_width!("\u{2D66}\u{2D7F}\u{2D3E}", 3, 3);
}
#[test]
fn test_old_turkic_ligature() {
assert_width!("\u{10C32}", 1, 1);
assert_width!("\u{10C03}", 1, 1);
assert_width!("\u{10C32}\u{10C03}", 2, 2);
assert_width!("\u{10C32}\u{200D}\u{10C03}", 1, 1);
assert_width!("\u{10C32}\u{FE0F}\u{200D}\u{FE0E}\u{10C03}", 1, 1);
assert_width!("\u{10C32}\u{2D7F}\u{10C03}", 3, 3);
assert_width!("\u{10C32}\u{0301}\u{200D}\u{10C03}", 2, 2);
assert_width!("\u{10C03}\u{200D}\u{10C32}", 2, 2);
assert_width!("\u{200D}\u{10C32}", 1, 1);
}
#[test]
fn test_khmer_coeng() {
assert_width!("", 1, 1);
assert_width!("", 1, 1);
assert_width!("លង", 2, 2);
assert_width!("ល្ង", 1, 1);
for c in '\0'..=char::MAX {
if matches!(
c,
'\u{1780}'..='\u{1782}' | '\u{1784}'..='\u{1787}'
| '\u{1789}'..='\u{178C}' | '\u{178E}'..='\u{1793}'
| '\u{1795}'..='\u{1798}' | '\u{179B}'..='\u{179D}'
| '\u{17A0}' | '\u{17A2}' | '\u{17A7}'
| '\u{17AB}'..='\u{17AC}' | '\u{17AF}'
) {
assert_width!(format!("\u{17D2}{c}"), 0, 0);
assert_width!(format!("\u{17D2}\u{200D}\u{200D}{c}"), 0, 0);
} else {
// Newlines are special cased (#60)
if c == '\n' {
continue;
}
assert_width!(
format!("\u{17D2}{c}"),
c.width().unwrap_or(1),
c.width_cjk().unwrap_or(1)
);
}
}
}
#[test]
fn test_khmer_qaa() {
assert_width!("\u{17A4}", 2, 2);
assert_width!("\u{17A2}\u{17A6}", 2, 2);
}
#[test]
fn test_khmer_sign_beyyal() {
assert_width!("\u{17D8}", 3, 3);
assert_width!("\u{17D4}\u{179B}\u{17D4}", 3, 3);
}
#[test]
fn test_emoji_modifier() {
assert_width!("\u{1F46A}", 2, 2);
assert_width!("\u{1F3FB}", 2, 2);
assert_width!("\u{1F46A}\u{1F3FB}", 2, 2);
assert_width!("\u{1F46A}\u{200D}\u{200D}\u{1F3FB}", 4, 4);
}
#[test]
fn test_emoji_zwj() {
assert_width!("🧑‍🤝‍🧑", 2, 2);
assert_width!("🇮🇱🕊️🇵🇸", 6, 6);
assert_width!("🇵🇸\u{200D}🕊️\u{200D}🇮🇱", 2, 2);
assert_width!("🇮🇱\u{200D}🕊️\u{200D}\u{200D}🇵🇸", 4, 4);
assert_width!("🇵🇸\u{200D}\u{200D}🕊️\u{200D}🇮🇱", 4, 4);
assert_width!("🇦🇦\u{200D}🇦🇦", 2, 2);
assert_width!("🇦🇦\u{200D}🇦🇦🇦", 3, 3);
assert_width!("🇦🇦\u{200D}🇦🇦🇦", 3, 3);
assert_width!("🇦🇦\u{200D}\u{200D}🇦🇦", 4, 4);
assert_width!("🇦🇦\u{200D}🇦\u{200D}🇦🇦", 5, 5);
assert_width!("🇦🇦\u{200D}🇦🇦\u{200D}🇦🇦", 2, 2);
assert_width!("🇦🇦\u{200D}🇦🇦🇦\u{200D}🇦🇦", 5, 5);
assert_width!("🇦🇦\u{200D}🇦🇦🇦🇦\u{200D}🇦🇦", 4, 4);
assert_width!("🇦🇦\u{200D}🇦🇦🇦🇦🇦\u{200D}🇦🇦", 7, 7);
assert_width!("🇦🇦\u{200D}🇦🇦🇦🇦🇦🇦\u{200D}🇦🇦", 6, 6);
assert_width!("🇦🇦\u{200D}🇦🇦🇦🇦🇦🇦🇦\u{200D}🇦🇦", 9, 9);
assert_width!("🏴󠁧󠁢󠁷󠁬󠁳󠁿", 2, 2);
assert_width!("🏴󠁧󠁢󠁥󠁮󠁧󠁿\u{200D}🏴󠁧󠁢󠁳󠁣󠁴󠁿\u{200D}🏴󠁧󠁢󠁷󠁬󠁳󠁿", 2, 2);
assert_width!("🇦👪\u{200D}🏿", 3, 3);
assert_width!("🇦🏿\u{200D}🏿", 3, 3);
assert_width!('🏴', Some(2), Some(2));
assert_width!("\u{E0031}", 0, 0);
assert_width!("\u{E0063}", 0, 0);
assert_width!("\u{E007F}", 0, 0);
assert_width!("🏴\u{200D}Ⓜ️", 2, 2);
assert_width!("🏴\u{E0031}\u{200D}Ⓜ️", 4, 4);
assert_width!("🏴\u{E0063}\u{200D}Ⓜ️", 4, 4);
assert_width!("🏴\u{E007F}\u{200D}Ⓜ️", 4, 4);
assert_width!("🏴\u{E0031}\u{E007F}\u{200D}Ⓜ️", 4, 4);
assert_width!("🏴\u{E0031}\u{E0031}\u{E007F}\u{200D}Ⓜ️", 4, 4);
assert_width!("🏴\u{E0031}\u{E0031}\u{E0031}\u{E007F}\u{200D}Ⓜ️", 2, 2);
assert_width!(
"🏴\u{E0031}\u{E0031}\u{E0031}\u{E0031}\u{E007F}\u{200D}Ⓜ️",
4,
4,
);
assert_width!(
"🏴\u{E0031}\u{E0031}\u{E0031}\u{E0063}\u{E007F}\u{200D}Ⓜ️",
2,
2,
);
assert_width!(
"🏴\u{E0031}\u{E0031}\u{E0031}\u{E0063}\u{E0063}\u{E007F}\u{200D}Ⓜ️",
2,
2,
);
assert_width!(
"🏴\u{E0031}\u{E0031}\u{E0031}\u{E0063}\u{E0063}\u{E0063}\u{E007F}\u{200D}Ⓜ️",
2,
2,
);
assert_width!(
"🏴\u{E0031}\u{E0031}\u{E0031}\u{E0063}\u{E0063}\u{E0063}\u{E0063}\u{E007F}\u{200D}Ⓜ️",
2,
2,
);
assert_width!(
"🏴\u{E0031}\u{E0031}\u{E0031}\u{E0063}\u{E0063}\u{E0063}\u{E0063}\u{E0063}\u{E007F}\u{200D}Ⓜ️",
4,
4,
);
assert_width!("🏴\u{E0063}\u{E0063}\u{E007F}\u{200D}Ⓜ️", 4, 4);
assert_width!("🏴\u{E0063}\u{E0063}\u{E0063}\u{E007F}\u{200D}Ⓜ️", 2, 2);
assert_width!(
"🏴\u{E0063}\u{E0063}\u{E0063}\u{E0063}\u{E007F}\u{200D}Ⓜ️",
2,
2,
);
assert_width!(
"🏴\u{E0063}\u{E0063}\u{E0063}\u{E0063}\u{E0063}\u{E007F}\u{200D}Ⓜ️",
2,
2,
);
assert_width!(
"🏴\u{E0063}\u{E0063}\u{E0063}\u{E0063}\u{E0063}\u{E0063}\u{E007F}\u{200D}Ⓜ️",
2,
2,
);
assert_width!(
"🏴\u{E0063}\u{E0063}\u{E0063}\u{E0063}\u{E0063}\u{E0063}\u{E0063}\u{E007F}\u{200D}Ⓜ️",
4,
4,
);
assert_width!("a\u{200D}🏴󠁧󠁢󠁷󠁬󠁳󠁿", 3, 3);
assert_width!("👪\u{200D}a", 3, 3);
assert_width!("a\u{200D}a", 2, 2);
assert_width!("*\u{FE0F}", 2, 2);
assert_width!("*\u{20E3}", 1, 1);
assert_width!("*️⃣", 2, 2);
assert_width!("*\u{FE0F}", 2, 2);
assert_width!("*\u{20E3}\u{FE0F}", 1, 1);
assert_width!("*️⃣\u{200D}👪", 2, 2);
assert_width!("*\u{20E3}\u{FE0F}\u{200D}👪", 3, 3);
assert_width!("*\u{20E3}\u{200D}👪", 3, 3);
assert_width!("*\u{FE0F}\u{200D}👪", 2, 2);
assert_width!("*️⃣\u{20E3}\u{200D}👪", 4, 4);
assert_width!("*\u{FE0F}\u{FE0F}\u{20E3}\u{200D}👪", 4, 4);
assert_width!(
"🇦👪\u{200D}🏿\u{200D}👪🏻\u{200D}Ⓜ️\u{200D}*\u{FE0F}\u{200D}🇦🇦\u{200D}🏴󠁧󠁢󠁷󠁬󠁳󠁿\u{200D}👪",
3,
3,
);
}
#[test]
fn emoji_test_file() {
let norm_file = BufReader::new(
File::open("tests/emoji-test.txt")
.expect("run `unicode.py` first to download `emoji-test.txt`"),
);
for line in norm_file.lines() {
let line = line.unwrap();
if line.is_empty() || line.starts_with('#') {
continue;
}
let (cps, status) = line.split_once(';').unwrap();
let status = status.trim();
if status.starts_with("fully-qualified") || status.starts_with("component") {
let emoji: String = cps
.trim()
.split(' ')
.map(|s| char::try_from(u32::from_str_radix(s, 16).unwrap()).unwrap())
.collect();
dbg!(&emoji);
assert_width!(emoji, 2, 2);
}
}
}
#[test]
fn test_newline_zero_issue_60() {
assert_width!("a\na", 2, 2);
}
// Test traits are unsealed
#[cfg(feature = "cjk")]
#[allow(dead_code)]
struct Foo;
#[cfg(feature = "cjk")]
impl UnicodeWidthChar for Foo {
fn width(self) -> Option<usize> {
Some(0)
}
fn width_cjk(self) -> Option<usize> {
Some(0)
}
}
#[cfg(feature = "cjk")]
impl UnicodeWidthStr for Foo {
fn width(&self) -> usize {
0
}
fn width_cjk(&self) -> usize {
0
}
}