Improve handling of lines containing only indentation#162
Merged
jimhester merged 2 commits intotidyverse:masterfrom Feb 4, 2020
alandipert:trim-fix-blank-lines
Merged
Improve handling of lines containing only indentation#162jimhester merged 2 commits intotidyverse:masterfrom alandipert:trim-fix-blank-lines
jimhester merged 2 commits intotidyverse:masterfrom
alandipert:trim-fix-blank-lines
Conversation
2 tasks
Collaborator
|
Thanks!
|
Contributor
Author
|
OK I updated the NEWS and created #163, which I should be to make another PR for today. Please let me know if there's anything else I can do on this one 👍 |
Collaborator
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_indentnumber of characters are trimmed from the beginning of lines by seekingicharacters ahead in the input string.However, after setting
i += min_indent,iwas incremented again right before thewhileloop continued viastr[j++] = xx[i++]. This causedito 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_indentand 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_indentwill removed from every line after the first, in themin_indentcalculation pass we could tally newlines and multiply that tally by the size ofmin_indentto determine how much smaller the output string needs to be.TODO