stream->fill(' ');
stream->flags((ios::fmtflags)0);
- Format fmt;
-
while (*p) {
switch (*p) {
case '%': {
continue;
}
- if (objects.empty())
- format_invalid(*stream);
-
- Base *data = objects.front();
-
- fmt.clear();
+ Format fmt;
bool done = false;
bool end_number = false;
bool have_precision = false;
}
}
- ios::fmtflags saved_flags = stream->flags();
- char old_fill = stream->fill();
- int old_precision = stream->precision();
+ if (!objects.empty())
+ {
+ Base *data = objects.front();
+ objects.pop_front();
+
+ ios::fmtflags saved_flags = stream->flags();
+ char old_fill = stream->fill();
+ int old_precision = stream->precision();
- data->process(*stream, fmt);
+ data->process(*stream, fmt);
- stream->flags(saved_flags);
- stream->fill(old_fill);
- stream->precision(old_precision);
+ stream->flags(saved_flags);
+ stream->fill(old_fill);
+ stream->precision(old_precision);
+
+ delete data;
+ } else {
+ *stream << "<missing arg for format>";
+ }
- delete data;
- objects.pop_front();
++p;
}
break;
}
while (!objects.empty()) {
+ *stream << "<extra arg>";
Base *data = objects.front();
- data->process(*stream, fmt);
- delete data;
objects.pop_front();
+ delete data;
}
}
int precision;
int width;
- Format() { }
- void clear() {
+ Format() { clear(); }
+
+ void clear()
+ {
alternate_form = false;
flush_left = false;
print_sign = false;
}
};
-inline void
-format_invalid(std::ostream &out)
-{
- using namespace std;
-
- out << "format invalid!!!" << endl;
-}
-
-
template <typename T>
inline void
_format_char(std::ostream &out, const T& data, Format &fmt)
template <typename T>
inline void
format_char(std::ostream &out, const T& data, Format &fmt)
-{ format_invalid(out); }
+{ out << "<bad arg type for char format>"; }
inline void
format_char(std::ostream &out, char data, Format &fmt)
template <typename T>
inline void
format_float(std::ostream &out, const T& data, Format &fmt)
-{ format_invalid(out); }
+{ out << "<bad arg type for float format>"; }
inline void
format_float(std::ostream &out, float data, Format &fmt)