diff --git a/Cargo.lock b/Cargo.lock index f2960cc..575c7ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -256,7 +256,6 @@ dependencies = [ "log", "regex", "similar", - "unicode-width", ] [[package]] @@ -265,12 +264,6 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" -[[package]] -name = "unicode-width" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" - [[package]] name = "utf8parse" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index 56e9491..1c13eb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ lazy_static = "1.5.0" log = "0.4.22" regex = "1.11.0" similar = "2.6.0" -unicode-width = "0.2.0" [profile.release] codegen-units = 1 diff --git a/README.md b/README.md index e15d143..333db69 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ tex-fmt is over a thousand times faster than latexindent. | **Files** | **Lines** | **Size** | **tex-fmt** | **latexindent** | **latexindent -m** | | --- | --- | --- | --- | --- | --- | -| 49 | 94k | 3.5M | **0.055s** | 99s [x1800] | 132s [x2400] | +| 49 | 94k | 3.5M | **0.052s** | 99s [x1904] | 132s [x2538] | ## Contribution diff --git a/src/wrap.rs b/src/wrap.rs index 1961149..4cf5810 100644 --- a/src/wrap.rs +++ b/src/wrap.rs @@ -5,7 +5,6 @@ use crate::comments::*; use crate::format::*; use crate::logging::*; use log::Level::{Trace, Warn}; -use unicode_width::UnicodeWidthChar; /// String slice to start wrapped text lines pub const TEXT_LINE_START: &str = ""; @@ -14,16 +13,7 @@ pub const COMMENT_LINE_START: &str = "% "; /// Check if a line needs wrapping pub fn needs_wrap(line: &str, indent_length: usize, args: &Cli) -> bool { - !args.keep - && ({ - let mut line_length = 0; - for c in line.chars() { - line_length += - c.width().expect("Why control character in text?"); - } - line_length - } + indent_length - > args.wrap.into()) + !args.keep && (line.chars().count() + indent_length > args.wrap.into()) } /// Find the best place to break a long line @@ -42,8 +32,7 @@ fn find_wrap_point( // Return *byte* index rather than *char* index. for (i, c) in line.char_indices() { - line_width += c.width().expect("No control characters in text."); - + line_width += 1; if line_width > wrap_boundary && wrap_point.is_some() { break; }