Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // note: we don't need a real printf format parser.
- // enough to simply find the subtitution tokens and feed them to the real printf after checking types.
- // https://en.wikipedia.org/wiki/Printf_format_string#Format_placeholder_specification
- FString output;
- bool in_fmt = false;
- FString fmt_current;
- int argnum = -1;
- int argauto = paramnum+1;
- // % = starts
- // [0-9], -, +, \s, 0, #, . continue
- // %, s, d, i, u, fF, eE, gG, xX, o, c, p, aA terminate
- // the only combination that is parsed locally is %n$...
- for (int i = 0; i < fmt.Len(); i++)
- {
- char c = fmt[i];
- if (in_fmt)
- {
- if ((c >= '0' && c <= '9') ||
- c == '-' || c == '+' || (c == ' ' && fmt_current[fmt_current.Len()-1] != ' ') || c == '#' || c == '.')
- {
- fmt_current += c;
- }
- else
- {
- if (argnum < 0) argnum = argauto;
- Printf("c = %c\n", c);
- switch (c)
- {
- case 's':
- {
- PARAM_INT_AT(argnum, _s);
- //PARAM_POINTER_AT(argnum, _s, int);
- Printf("p = %s\n", FName(_s).GetChars());
- //output += _s;
- in_fmt = false;
- break;
- }
- case 'd':
- case 'i':
- case 'u':
- case 'f':
- case 'F':
- case 'e':
- case 'E':
- case 'g':
- case 'G':
- case 'x':
- case 'X':
- case 'o':
- case 'c':
- case 'p':
- case 'a':
- case 'A':
- output += "{arg}";
- in_fmt = false;
- break;
- default:
- // invalid character
- output += fmt_current + c;
- in_fmt = false;
- break;
- }
- }
- }
- else
- {
- if (c == '%')
- {
- if (i + 1 < fmt.Len() && fmt[i + 1] == '%')
- {
- output += '%';
- i++;
- }
- else
- {
- in_fmt = true;
- fmt_current = "%";
- argnum = -1;
- }
- }
- else
- {
- output += c;
- }
- }
- }
- // list arguments for now
- /*paramnum++; // not sure if this is needed
- for (int i = 1; i < numparam; i++)
- {
- PARAM_STRING_AT()
- }*/
Advertisement
Add Comment
Please, Sign In to add comment