]> git.lizzy.rs Git - rust.git/commitdiff
Fix wrap_str
authortopecongiro <seuchida@gmail.com>
Sat, 17 Jun 2017 07:54:25 +0000 (16:54 +0900)
committertopecongiro <seuchida@gmail.com>
Sat, 17 Jun 2017 07:54:25 +0000 (16:54 +0900)
Use shape.width for the first line and shape.used_width() for the last line.

src/utils.rs

index dd18572575b1fda8563a8b984a288dd89dd487ca..9c3d023c2ed88184109186ffbb126e90aa1af332 100644 (file)
@@ -317,10 +317,7 @@ pub fn wrap_str<S: AsRef<str>>(s: S, max_width: usize, shape: Shape) -> Option<S
             } else {
                 let mut lines = snippet.lines();
 
-                // The caller of this function has already placed `shape.offset`
-                // characters on the first line.
-                let first_line_max_len = try_opt!(max_width.checked_sub(shape.indent.width()));
-                if lines.next().unwrap().len() > first_line_max_len {
+                if lines.next().unwrap().len() > shape.width {
                     return None;
                 }
 
@@ -333,9 +330,7 @@ pub fn wrap_str<S: AsRef<str>>(s: S, max_width: usize, shape: Shape) -> Option<S
                 // indentation.
                 // A special check for the last line, since the caller may
                 // place trailing characters on this line.
-                if snippet.lines().rev().next().unwrap().len() >
-                    shape.indent.width() + shape.width
-                {
+                if snippet.lines().rev().next().unwrap().len() > shape.used_width() + shape.width {
                     return None;
                 }
             }