That's great! But what if the string itself has double quotes inside of it? The output would be confusing. Or, some strings might contain non-printable characters like 0x08, or awkwardly-printable characters like a tab (\t).
The ? presentation type is the "debug string" format, which not only double-quotes the string but also converts non-printable characters into their \xNN hex code, so that the output is a string literal that can be pasted back into either C++ or Python.
Unfortunately, our Jammy copy of fmt is just slightly too old to contain this feature, so we need to polyfill it until we drop jammy.
Towards #22078.
Sometimes we want to print or log a string. Imagine this function:
For logging, we might try:
That would print e.g.
However, we'll usually want to print the quoted string value, so that the user can see e.g. if they have training whitespace:
That would print e.g.
That's great! But what if the string itself has double quotes inside of it? The output would be confusing. Or, some strings might contain non-printable characters like 0x08, or awkwardly-printable characters like a tab (
\t
).Format has a solution for that:
The
?
presentation type is the "debug string" format, which not only double-quotes the string but also converts non-printable characters into their\xNN
hex code, so that the output is a string literal that can be pasted back into either C++ or Python.Unfortunately, our Jammy copy of fmt is just slightly too old to contain this feature, so we need to polyfill it until we drop jammy.
This change is