Distributed under the LGPL
*/
-#include <msp/core/except.h>
#include "fmt.h"
using namespace std;
namespace Msp {
-void Fmt::parse(const char *f)
+void Fmt::parse(const char *s)
{
+ const char *f = s;
if(*f=='%') ++f;
for(; *f; ++f)
else if(*f=='i')
base = AUTOBASE;
else
- throw InvalidParameterValue("Invalid conversion specifier");
+ throw format_error(s);
if(*f=='E' || *f=='F' || *f=='G' || *f=='X' || *f=='P')
ucase = true;
++f;
if(*f)
- throw InvalidParameterValue("Extra characters in conversion specification");
+ throw format_error(s);
}
Fmt &Fmt::reset()
#define MSP_STRINGS_FMT_H_
#include <ostream>
+#include <stdexcept>
#include <string>
namespace Msp {
+class format_error: public std::logic_error
+{
+public:
+ format_error(const std::string &w): std::logic_error(w) { }
+ virtual ~format_error() throw() { }
+};
+
+
/**
Stores formatting information for converting variables into strings. Can be
applied to an std::ostream or fed to lexical_cast. Also used internally by
const string &Formatter::str() const
{
if(pos!=fmt.end())
- throw Exception("Too few arguments for format");
+ throw format_error("Too few arguments for format");
return result;
}
{
++pos;
if(pos==fmt.end())
- throw Exception("Malformed format string");
+ throw format_error("Malformed format string");
if(*pos!='%')
break;
}
Fmt Formatter::get_conversion()
{
if(pos==fmt.end())
- throw Exception("Too many arguments for format");
+ throw format_error("Too many arguments for format");
string::iterator i = pos;
for(; i!=fmt.end(); ++i)
break;
if(i==fmt.end())
- throw Exception("Malformed format string");
+ throw format_error("Malformed format string");
++i;
string c(pos, i);