Why whitespace is been removed after wrap? #572
-
Hi, thanks to your work, I have a simple question: For example, we have the origin line: ["Hello", "World"] But why the whitespace |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Good question! The whitespace at the ends of the lines is removed since it's normally unwanted. The idea is that each line now takes up at most 10 columns. If the trailing whitespace was left there, then this would not be true. It goes further than this: the whitespace between the words is attached to the left word, and it is removed at the end of lines. So running pub fn main() {
dbg!(textwrap::wrap("This is a demo ", 10));
} gives me
See https://godbolt.org/z/Kn9GTPvoM for an example of this (the normal Playground gives me an error right now). What happens is that the text is split into words using the
To keep the trailing whitespace, you would need to construct your own You could implement Let me try and fix this for the next version! |
Beta Was this translation helpful? Give feedback.
Good question! The whitespace at the ends of the lines is removed since it's normally unwanted.
The idea is that each line now takes up at most 10 columns. If the trailing whitespace was left there, then this would not be true.
It goes further than this: the whitespace between the words is attached to the left word, and it is removed at the end of lines. So running
gives me
See https://godbolt.org/z/Kn9GTPvoM for an example of this (the normal Playground gives me an error right now).
What happens is that t…