Improve handling of lines containing only indentation #162
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, after a
'\n'
was encountered while copying,min_indent
number of characters are trimmed from the beginning of lines by seekingi
characters ahead in the input string.However, after setting
i += min_indent
,i
was incremented again right before thewhile
loop continued viastr[j++] = xx[i++]
. This causedi
to point to the character after the'\n
' that terminated the line, and so leading indentation on the following line was not recognized as such, and so was improperly copied to the output string.While working on this, I also ran into a few other possible bugs:
min_indent
and so could cause the succeeding line to contain spurious leading indentation. Currently,trim()
only works properly if there's either no whitespace on the blank line, or if there is an amount of whitespace of at leastmin_indent
.Let me know if it would be helpful for me to create issues for those possible bugs. I didn't create issues because maybe these are features 😄
It also occurred to @wch and I while working on this that we could probably be smarter about the size of the output string we allocate. Since we know that
min_indent
will removed from every line after the first, in themin_indent
calculation pass we could tally newlines and multiply that tally by the size ofmin_indent
to determine how much smaller the output string needs to be.TODO