Fixed an accumulator bug that was mangling errors

This commit is contained in:
John Wiegley 2009-02-21 21:57:55 -04:00
parent 4b159527a5
commit c6d2420d09

View file

@ -46,6 +46,7 @@ std::streamsize straccbuf::xsputn(const char * s, std::streamsize num)
// Every item thereafter is an argument that substitutes for %# in the // Every item thereafter is an argument that substitutes for %# in the
// format string // format string
bool matched = false;
for (const char * p = str.c_str(); *p; p++) { for (const char * p = str.c_str(); *p; p++) {
if (*p == '%') { if (*p == '%') {
const char * q = p + 1; const char * q = p + 1;
@ -53,6 +54,7 @@ std::streamsize straccbuf::xsputn(const char * s, std::streamsize num)
std::size_t(*q - '0') == index) { std::size_t(*q - '0') == index) {
p++; p++;
buf << std::string(s, num); buf << std::string(s, num);
matched = true;
} else { } else {
buf << *p; buf << *p;
} }
@ -60,9 +62,11 @@ std::streamsize straccbuf::xsputn(const char * s, std::streamsize num)
buf << *p; buf << *p;
} }
} }
if (! matched)
buf << std::string(s, num);
str = buf.str(); str = buf.str();
index++; index++;
return num; return num;
} }
} }