mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Simplify format specs to not use a per-character state machine
This commit is contained in:
@@ -7,19 +7,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
enum FormatState {
|
||||
FORMAT_SIGN, // expects '+' or ' ' (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
|
||||
};
|
||||
|
||||
class FormatSpec {
|
||||
FormatState state;
|
||||
int sign;
|
||||
bool exact;
|
||||
bool alignLeft;
|
||||
@@ -30,15 +18,13 @@ class FormatSpec {
|
||||
bool hasPrec;
|
||||
size_t precision;
|
||||
int type;
|
||||
bool valid;
|
||||
bool parsed;
|
||||
|
||||
public:
|
||||
bool isEmpty() const { return !state; }
|
||||
bool isValid() const { return valid || state == FORMAT_DONE; }
|
||||
bool isFinished() const { return state >= FORMAT_DONE; }
|
||||
bool isValid() const { return !!type; }
|
||||
bool isParsed() const { return parsed; }
|
||||
|
||||
void useCharacter(int c);
|
||||
void finishCharacters();
|
||||
size_t parseSpec(char const *spec);
|
||||
|
||||
void appendString(std::string &str, std::string const &value) const;
|
||||
void appendNumber(std::string &str, uint32_t value) const;
|
||||
|
||||
Reference in New Issue
Block a user