This patch ensures cases like %0.6u, %06f, and %.6u are processed correctly.
The case like %06f is ambiguous and was made to match printf. Also, this patch
removes the goto statement in cprintf.cc in favor of a function call.
while (*ptr) {
switch (*ptr) {
case '%':
- if (ptr[1] != '%')
- goto processing;
-
+ if (ptr[1] != '%') {
+ process_flag();
+ return;
+ }
stream.put('%');
ptr += 2;
break;
break;
}
}
+}
- return;
-
- processing:
+void
+Print::process_flag()
+{
bool done = false;
bool end_number = false;
bool have_precision = false;
end_number = false;
number = 0;
}
- }
+
+ if (done) {
+ if ((fmt.format == Format::integer) && have_precision) {
+ // specified a . but not a float, set width
+ fmt.width = fmt.precision;
+ // precision requries digits for width, must fill with 0
+ fmt.fill_zero = true;
+ } else if ((fmt.format == Format::floating) && !have_precision &&
+ fmt.fill_zero) {
+ // ambiguous case, matching printf
+ fmt.precision = fmt.width;
+ }
+ }
+ } // end while
++ptr;
}
Format fmt;
void process();
+ void process_flag();
public:
Print(std::ostream &stream, const std::string &format);