Improve string/interpolation formatting (#1491)

- The '#' component for type 's' now escapes the string characters
- The '#' component for type 'f' now prints a precision suffix
- The new 'q' component specifies a precision value
This commit is contained in:
Sylvie
2024-09-01 12:54:26 -04:00
committed by GitHub
parent 2fb76ce584
commit 6b8d33529e
13 changed files with 128 additions and 48 deletions

View File

@@ -9,10 +9,11 @@
enum FormatState {
FORMAT_SIGN, // expects '+' or ' ' (optional)
FORMAT_PREFIX, // expects '#' (optional)
FORMAT_EXACT, // expects '#' (optional)
FORMAT_ALIGN, // expects '-' (optional)
FORMAT_WIDTH, // expects '0'-'9', max 255 (optional) (leading '0' indicates pad)
FORMAT_FRAC, // got '.', expects '0'-'9', max 255 (optional)
FORMAT_PREC, // got 'q', expects '0'-'9', range 1-31 (optional)
FORMAT_DONE, // got [duXxbofs] (required)
FORMAT_INVALID, // got unexpected character
};
@@ -20,12 +21,14 @@ enum FormatState {
class FormatSpec {
FormatState state;
int sign;
bool prefix;
bool exact;
bool alignLeft;
bool padZero;
size_t width;
bool hasFrac;
size_t fracWidth;
bool hasPrec;
size_t precision;
int type;
bool valid;