You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the precision for string output the string may get truncated. It would be great if the output has a marker indicating the output is truncated. I created a small proof of concept patch that provides this behaviour [1]. The patch is against 5.3.0 in a local project so the git index is bogus. It modifies the following syntax: ["." precision]
to ["." precision["," truncate]]
Where truncate is a single character. That means the following code: fmt::print(FMT_STRING("{:.5}\n{:.5,#}\n"), "foobar", "foobar");
will output
fooba
foob#
The patch doesn't work with the { arg_id } precision syntax. I actually would like the ellipse …, but that seems related to #1109.
Is this behaviour wanted and would this be the proper approach?
Thanks for the suggestions. I would rather not complicate the format specifications for such a relatively narrow use case but you can implement this using the extension API without changing the core library by wrapping a string in some type:
structtrunc {
std::string_view s;
};
structfmt::formatter<trunc> {
// Implement custom parsing and formatting with truncation marker.
};
fmt::print(FMT_STRING("{:.5}\n{:.5,#}\n"), "foobar", trunc("foobar"));
Truncation marker can either be part of a format string or an argument to trunc. This will also work with named arguments.
When using the precision for string output the string may get truncated. It would be great if the output has a marker indicating the output is truncated. I created a small proof of concept patch that provides this behaviour [1]. The patch is against 5.3.0 in a local project so the git index is bogus. It modifies the following syntax:
["." precision]
to
["." precision["," truncate]]
Where truncate is a single character. That means the following code:
fmt::print(FMT_STRING("{:.5}\n{:.5,#}\n"), "foobar", "foobar");
will output
The patch doesn't work with the { arg_id } precision syntax. I actually would like the ellipse …, but that seems related to #1109.
Is this behaviour wanted and would this be the proper approach?
[1] https://filebin.ca/4eMhuevLFfia/truncate.patch
The text was updated successfully, but these errors were encountered: