Skip to content

Avoid truncation for inputs close to limit#57

Open
bhavanki wants to merge 1 commit intomuesli:masterfrom
segmentio:avoid-needless-truncation
Open

Avoid truncation for inputs close to limit#57
bhavanki wants to merge 1 commit intomuesli:masterfrom
segmentio:avoid-needless-truncation

Conversation

@bhavanki
Copy link
Copy Markdown

Previous truncation code always truncated and added a tail once the processed input width exceeded the limit minus the tail width. For example, the input "foobar" truncated to width 6 with a tail "." would come out as "fooba.".

Now, when the rune scanning loop passes into the danger zone where truncation might be required, but before the truncation limit is breached, it buffers runes instead of writing them out. If the truncation limit is exceeded, then the tail is written as usual. If it ends up not exceeded, then the buffered runes are written out, avoiding unnecessary truncation.

Previous truncation code always truncated and added a tail once the
processed input width exceeded the limit minus the tail width. For
example, the input "foobar" truncated to width 6 with a tail "." would
come out as "fooba.".

Now, when the rune scanning loop passes into the danger zone where
truncation might be required, but before the truncation limit is
breached, it buffers runes instead of writing them out. If the
truncation limit is exceeded, then the tail is written as usual. If it
ends up not exceeded, then the buffered runes are written out, avoiding
unnecessary truncation.
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

Successfully merging this pull request may close these issues.

1 participant