X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fstrings%2Fformat.cpp;h=42926e158d593a8a5d84ffb88dfcdddce26a80d5;hp=4b5bcd0c43e2cf734a54dfd65c18f95b405c19cc;hb=HEAD;hpb=967785734be5c3fc6f75da122c2d93ebbb338271 diff --git a/source/strings/format.cpp b/source/strings/format.cpp index 4b5bcd0..42926e1 100644 --- a/source/strings/format.cpp +++ b/source/strings/format.cpp @@ -11,10 +11,23 @@ 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()) @@ -23,11 +36,6 @@ const string &Formatter::str() const 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) @@ -45,16 +53,12 @@ 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 format_error("Too many arguments for format"); - string::iterator i = pos; + auto i = pos; for(; i!=fmt.end(); ++i) if(isalpha(*i)) break;