/* Helper to avoid errors about ambiguous function calls since there are no
overloads of abs for unsigned types */
/* Helper to avoid errors about ambiguous function calls since there are no
overloads of abs for unsigned types */
template<typename T>
char *int_to_str(T v, const Fmt &f, char *end)
{
if(f.get_type()==Fmt::CHAR)
{
template<typename T>
char *int_to_str(T v, const Fmt &f, char *end)
{
if(f.get_type()==Fmt::CHAR)
{
if(f.get_fill()=='0')
{
/* Zero-fill, taking base/sign size into account. The expression is a
bit ugly, but saves having to write code for creating the prefix both
ways. */
if(f.get_fill()=='0')
{
/* Zero-fill, taking base/sign size into account. The expression is a
bit ugly, but saves having to write code for creating the prefix both
ways. */
- unsigned size=max(f.get_width(), max<unsigned>(f.get_precision(), sizeof(T)*8+3));
- char *buf=new char[size];
+ unsigned size = max(f.get_width(), max<unsigned>(f.get_precision(), sizeof(T)*8+3));
+ char *buf = new char[size];
string result(int_to_str(v, f, buf+size), buf+size);
delete[] buf;
return result;
string result(int_to_str(v, f, buf+size), buf+size);
delete[] buf;
return result;
- Fmt::FloatMode mode=f.get_floatmode();
- long double w=abs(v);
- char sign=(v<0 ? '-' : f.get_showpos() ? '+' : 0);
+ Fmt::FloatMode mode = f.get_floatmode();
+ long double w = abs(v);
+ char sign = (v<0 ? '-' : f.get_showpos() ? '+' : 0);
return result;
}
/* Find out the base-10 exponent. Building up the multiplier / divisor
first helps with accuracy in some cases. */
return result;
}
/* Find out the base-10 exponent. Building up the multiplier / divisor
first helps with accuracy in some cases. */
- unsigned size=max(f.get_width(), digits+8);
- char *buf=new char[size];
- char *end=buf+size;
- char *ptr=end;
+ unsigned size = max(f.get_width(), digits+8);
+ char *buf = new char[size];
+ char *end = buf+size;
+ char *ptr = end;
- ptr=int_to_str(exp, Fmt().showpos().fill('0').width(3), ptr);
- *--ptr=(f.get_uppercase() ? 'E' : 'e');
+ ptr = int_to_str(exp, Fmt().showpos().fill('0').width(3), ptr);
+ *--ptr = (f.get_uppercase() ? 'E' : 'e');
void operator>>(const LexicalConverter &c, char &v)
{
if(c.get_fmt().get_type()==Fmt::NUM)
void operator>>(const LexicalConverter &c, char &v)
{
if(c.get_fmt().get_type()==Fmt::NUM)
if(s.empty())
throw LexicalError("Empty input in character conversion");
if(s.size()>1)
throw LexicalError("Extra input in character conversion");
if(s.empty())
throw LexicalError("Empty input in character conversion");
if(s.size()>1)
throw LexicalError("Extra input in character conversion");