Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take newlines into account when wrapping #122

Closed
axelchalon opened this issue Jan 17, 2018 · 0 comments
Closed

Take newlines into account when wrapping #122

axelchalon opened this issue Jan 17, 2018 · 0 comments

Comments

@axelchalon
Copy link
Contributor

axelchalon commented Jan 17, 2018

println!("{}",fill("1 3 5 7
1 3 5 7",11));

/*
Expected:
1 3 5 7
1 3 5 7

Actual output:
1 3 5 7
1 3
5 7
*/

Currently, it seems that fill considers line breaks like any other whitespace character. It would be nice if the function could take line breaks into account when computing the wrapping!

@axelchalon axelchalon changed the title Add support for line-breaks in 'fill' Add support for line-breaks in 'fill' (support multi-line input) Jan 17, 2018
mgeisler added a commit that referenced this issue Mar 31, 2018
@mgeisler mgeisler changed the title Add support for line-breaks in 'fill' (support multi-line input) Take newlines into account when wrapping Apr 28, 2018
mgeisler added a commit that referenced this issue Nov 8, 2020
This is a complete rewrite of the core word wrapping functionality.
Before, we would step though the input string and (attempt to) keep
track of all aspects of the state. This didn't always work (see at
least #122, #158, #158, and #193) and it's inflexible.

This commit replaces the old algorithm with a new one which works on a
more abstract level. We now first

1. First split the input string into "words". A word is a substring of
   the original string, including any trailing whitespace.

2. We split each word according to the `WordSplitter`.

3. We then simply put the words into lines based on the display width.

This is slower than the previous algorithm. The `fill/1600` benchmark
shows that is now takes ~18 microseconds to wrap a 1600 character long
string. That is around 8 microseconds longer than before.
mgeisler added a commit that referenced this issue Nov 8, 2020
This is a complete rewrite of the core word wrapping functionality.
Before, we would step though the input string and (attempt to) keep
track of all aspects of the state. This didn't always work (see at
least #122, #158, #158, and #193) and it's inflexible.

This commit replaces the old algorithm with a new one which works on a
more abstract level. We now first

1. First split the input string into "words". A word is a substring of
   the original string, including any trailing whitespace.

2. We split each word according to the `WordSplitter`.

3. We then simply put the words into lines based on the display width.

This is slower than the previous algorithm. The `fill/1600` benchmark
shows that is now takes ~18 microseconds to wrap a 1600 character long
string. That is around 8 microseconds longer than before.
mgeisler added a commit that referenced this issue Nov 8, 2020
This is a complete rewrite of the core word wrapping functionality.
Before, we would step though the input string and (attempt to) keep
track of all aspects of the state. This didn't always work (see at
least #122, #158, #158, and #193) and it's inflexible.

This commit replaces the old algorithm with a new one which works on a
more abstract level. We now first

1. First split the input string into "words". A word is a substring of
   the original string, including any trailing whitespace.

2. We split each word according to the `WordSplitter`.

3. We then simply put the words into lines based on the display width.

This is slower than the previous algorithm. The `fill/1600` benchmark
shows that is now takes ~18 microseconds to wrap a 1600 character long
string. That is around 8 microseconds longer than before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant