X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fstrings%2Fformat.cpp;h=42926e158d593a8a5d84ffb88dfcdddce26a80d5;hb=85ef592fb1eab68283b12607701e4fb9b9014630;hp=dfd3800841033cbafba518b9b1417f193c30ab77;hpb=3a965c87750250c8facc9dbff02aeb3a88e19f05;p=libs%2Fcore.git diff --git a/source/strings/format.cpp b/source/strings/format.cpp index dfd3800..42926e1 100644 --- a/source/strings/format.cpp +++ b/source/strings/format.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspstrings -Copyright © 2006-2007 Mikko Rasa -Distributed under the LGPL -*/ - #include "format.h" using namespace std; @@ -18,23 +11,31 @@ Formatter::Formatter(const string &f): advance(); } -/** -Returns the result of the formatting operation. Will throw if not enough -values have been fed to the formatter. -*/ +Formatter::Formatter(const Formatter &other): + fmt(other.fmt), + pos(fmt.begin()+(other.pos-other.fmt.begin())), + result(other.result) +{ } + +Formatter &Formatter::operator=(const Formatter &other) +{ + if(&other==this) + return *this; + + fmt = other.fmt; + pos = fmt.begin()+(other.pos-other.fmt.begin()); + result = other.result; + return *this; +} + 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; } -/** -Advances the pos iterator to the next conversion, adding literal characters to -the result. The iterator is left at the second character of the conversion -(i.e. after the %). -*/ void Formatter::advance() { for(; pos!=fmt.end(); ++pos) @@ -43,7 +44,7 @@ void Formatter::advance() { ++pos; if(pos==fmt.end()) - throw Exception("Malformed format string"); + throw format_error("Malformed format string"); if(*pos!='%') break; } @@ -52,22 +53,18 @@ void Formatter::advance() } } -/** -Reads the next conversion from the format string and returns a corresponding -Fmt object. -*/ 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; + auto i = pos; for(; i!=fmt.end(); ++i) if(isalpha(*i)) break; if(i==fmt.end()) - throw Exception("Malformed format string"); + throw format_error("Malformed format string"); ++i; string c(pos, i);