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

Demonstrate and extend printf truncation #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

knz
Copy link
Contributor

@knz knz commented Sep 3, 2021

See the individual commits for details.
Supersedes #25

Also a new feature:

When the flag ! is passed in combination with a
precision (e.g. %!.3v), the truncation code now adds an
ellipsis () if truncation has actually occurred.

For example:

printf("%!.3s", "hel") -> ‹hel›
printf("%!.3s", "hello") -> ‹hel…›


This change is Reviewable

@knz knz force-pushed the 20210903-truncation branch 2 times, most recently from 808ab05 to 26eff89 Compare September 3, 2021 11:38
The upstream printf code already has support for string
truncation. This commit demonstrates/tests it via unit tests.
This should have been done when format.go moved to a new package.
(Using the refresh.sh script)
When the flag `!` is passed in combination with a
precision (e.g. `%!.3v`), the truncation code now adds an
ellipsis (`…`) if truncation has actually occurred.

For example:

`printf("%!.3s", "hel")` -> `‹hel›`
`printf("%!.3s", "hello")` -> `‹hel…›`
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