return true
}
}
- s.errorString("bad verb %" + string(verb) + " for " + typ)
+ s.errorString("bad verb '%" + string(verb) + "' for " + typ)
return false
}
for i < len(format) {
fmtc, w := utf8.DecodeRuneInString(format[i:])
if fmtc == '%' {
+ // % at end of string is an error.
+ if i+w == len(format) {
+ s.errorString("missing verb: % at end of format string")
+ }
// %% acts like a real percent
nextc, _ := utf8.DecodeRuneInString(format[i+w:]) // will not match % if string is empty
if nextc != '%' {
}
if numProcessed >= len(a) { // out of operands
- s.errorString("too few operands for format %" + format[i-w:])
+ s.errorString("too few operands for format '%" + format[i-w:] + "'")
break
}
arg := a[numProcessed]
// Interesting formats
{"here is\tthe value:%d", "here is the\tvalue:118\n", &intVal, 118},
{"%% %%:%d", "% %:119\n", &intVal, 119},
+ {"%d%%", "42%", &intVal, 42}, // %% at end of string.
// Corner cases
{"%x", "FFFFFFFF\n", &uint32Val, uint32(0xFFFFFFFF)},
{"%d %d", "23 18 27", args(&i, &j, &k), args(23, 18), "too many operands"},
{"%c", "\u0100", args(&int8Val), nil, "overflow"},
{"X%d", "10X", args(&intVal), nil, "input does not match format"},
+ {"%d%", "42%", args(&intVal), args(42), "missing verb: % at end of format string"},
+ {"%d% ", "42%", args(&intVal), args(42), "too few operands for format '% '"}, // Slightly odd error, but correct.
// Bad UTF-8: should see every byte.
{"%c%c%c", "\xc2X\xc2", args(&r1, &r2, &r3), args(utf8.RuneError, 'X', utf8.RuneError), ""},