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

Publish 0.2.0 with newlines treated as width 1#68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Manishearth merged 3 commits intounicode-rs:masterfromManishearth:two
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionCargo.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
[package]

name = "unicode-width"
version = "0.1.14"
version = "0.2.0"
authors = [
"kwantam <kwantam@gmail.com>",
"Manish Goregaokar <manishsmail@gmail.com>",
Expand Down
13 changes: 13 additions & 0 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -55,3 +55,16 @@ to your `Cargo.toml`:
[dependencies]
unicode-width = "0.1.11"
```


## Changelog


### 0.2.0

- Treat `\n` as width 1 (#60)
- Treat ambiguous `Modifier_Letter`s as narrow (#63)
- Support `Grapheme_Cluster_Break=Prepend` (#62)
- Support lots of ligatures (#53)

Note: If you are using `unicode-width` for linebreaking, the change treating `\n` as width 1 _may cause behavior changes_. It is recommended that in such cases you feed already-line segmented text to `unicode-width`. In other words, please apply higher level control character based line breaking protocols before feeding text to `unicode-width`. Relying on any character producing a stable width in this crate is likely the sign of a bug.
5 changes: 1 addition & 4 deletionsscripts/unicode.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1281,10 +1281,7 @@ def lookup_fns(
s += """
if c <= '\\u{A0}' {
match c {
// According to the spec, LF should be width 1, which is how it is often rendered when it is forced to have a single-line rendering
// However, this makes it harder to use this crate to calculate line breaks, and breaks assumptions of downstream crates.
// https://github.com/unicode-rs/unicode-width/issues/60
'\\n' => (0, WidthInfo::LINE_FEED),
'\\n' => (1, WidthInfo::LINE_FEED),
'\\r' if next_info == WidthInfo::LINE_FEED => (0, WidthInfo::DEFAULT),
_ => (1, WidthInfo::DEFAULT),
}
Expand Down
10 changes: 2 additions & 8 deletionssrc/tables.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -215,10 +215,7 @@ fn width_in_str(c: char, mut next_info: WidthInfo) -> (i8, WidthInfo) {
}
if c <= '\u{A0}' {
match c {
// According to the spec, LF should be width 1, which is how it is often rendered when it is forced to have a single-line rendering
// However, this makes it harder to use this crate to calculate line breaks, and breaks assumptions of downstream crates.
// https://github.com/unicode-rs/unicode-width/issues/60
'\n' => (0, WidthInfo::LINE_FEED),
'\n' => (1, WidthInfo::LINE_FEED),
'\r' if next_info == WidthInfo::LINE_FEED => (0, WidthInfo::DEFAULT),
_ => (1, WidthInfo::DEFAULT),
}
Expand DownExpand Up@@ -510,10 +507,7 @@ fn width_in_str_cjk(c: char, mut next_info: WidthInfo) -> (i8, WidthInfo) {
}
if c <= '\u{A0}' {
match c {
// According to the spec, LF should be width 1, which is how it is often rendered when it is forced to have a single-line rendering
// However, this makes it harder to use this crate to calculate line breaks, and breaks assumptions of downstream crates.
// https://github.com/unicode-rs/unicode-width/issues/60
'\n' => (0, WidthInfo::LINE_FEED),
'\n' => (1, WidthInfo::LINE_FEED),
'\r' if next_info == WidthInfo::LINE_FEED => (0, WidthInfo::DEFAULT),
_ => (1, WidthInfo::DEFAULT),
}
Expand Down
24 changes: 5 additions & 19 deletionstests/tests.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -214,23 +214,18 @@ fn test_control_line_break() {
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!("\n", 1, 1);
assert_width!("\r\n", 1, 1);
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);
assert_width!("1\t2\r\n3\u{85}4",7, 7);
assert_width!("\r\u{FE0F}\n",2, 2);
assert_width!("\r\u{200D}\n",2, 2);
}

#[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());
Expand DownExpand Up@@ -423,10 +418,6 @@ fn test_khmer_coeng() {
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),
Expand DownExpand Up@@ -597,11 +588,6 @@ fn emoji_test_file() {
}
}

#[test]
fn test_newline_zero_issue_60() {
assert_width!("a\na", 2, 2);
}

// Test traits are unsealed

#[cfg(feature = "cjk")]
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp