1 #include <msp/strings/utils.h>
2 #include "articlenumber.h"
9 ArticleNumber::ArticleNumber(unsigned n)
14 parts.push_back(part);
17 ArticleNumber::ArticleNumber(const string &s)
19 vector<string> sparts = split(s, '-');
20 for(vector<string>::iterator i=sparts.begin(); i!=sparts.end(); ++i)
23 throw invalid_argument("ArticleNumber::ArticleNumber");
25 unsigned nondigit = i->size();
26 for(unsigned j=0; j<i->size(); ++j)
33 if(!nondigit || nondigit<i->size()-1)
34 throw invalid_argument("ArticleNumber::ArticleNumber");
37 part.number = lexical_cast<unsigned>(i->substr(0, nondigit));
38 part.letter = nondigit<i->size() ? (*i)[nondigit] : 0;
39 parts.push_back(part);
43 string ArticleNumber::str() const
46 for(vector<Part>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
51 result += lexical_cast<string>(i->number);
59 bool ArticleNumber::operator<(const ArticleNumber &other) const
61 return parts<other.parts;
65 bool ArticleNumber::Part::operator<(const Part &other) const
67 if(number!=other.number)
68 return number<other.number;
69 return letter<other.letter;
73 void operator>>(const LexicalConverter &conv, ArticleNumber &art_nr)
75 art_nr = ArticleNumber(conv.get());
78 void operator<<(LexicalConverter &conv, const ArticleNumber &art_nr)
80 conv.result(art_nr.str());