X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fcounters.C;h=573eeb63c35ee7311eb709a70727c1263a74ad91;hb=9ee46b846e5e84ad40ceda4f4af94aeb86cd90a2;hp=851b87e0574743596037cc26267aa459d29215cf;hpb=44cd0fc9a1687cc63911c7f98d978594458e7813;p=lyx.git diff --git a/src/counters.C b/src/counters.C index 851b87e057..573eeb63c3 100644 --- a/src/counters.C +++ b/src/counters.C @@ -16,11 +16,12 @@ #include "debug.h" #include "support/lstrings.h" -#include "support/std_sstream.h" -#include "support/tostr.h" +#include "support/convert.h" #include +#include + using std::endl; using std::ostringstream; using std::string; @@ -77,10 +78,10 @@ void Counter::setMaster(string const & m) void Counters::newCounter(string const & newc) { // First check if newc already exist - CounterList::iterator cit = counterList.find(newc); + CounterList::iterator const cit = counterList.find(newc); // if already exist give warning and return if (cit != counterList.end()) { - lyxerr << "The new counter already exists." << endl; + lyxerr << "New counter already exists: " << newc << endl; return; } counterList[newc]; @@ -90,17 +91,17 @@ void Counters::newCounter(string const & newc) void Counters::newCounter(string const & newc, string const & masterc) { // First check if newc already exists - CounterList::iterator cit = counterList.find(newc); + CounterList::iterator const cit = counterList.find(newc); // if already existant give warning and return if (cit != counterList.end()) { - lyxerr << "The new counter already exists." << endl; + lyxerr << "New counter already exists: " << newc << endl; return; } // then check if masterc exists - CounterList::iterator it = counterList.find(masterc); + CounterList::iterator const it = counterList.find(masterc); // if not give warning and return if (it == counterList.end()) { - lyxerr << "The master counter does not exist." << endl; + lyxerr << "Master counter does not exist: " << masterc << endl; return; } @@ -108,9 +109,9 @@ void Counters::newCounter(string const & newc, string const & masterc) } -void Counters::set(string const & ctr, int val) +void Counters::set(string const & ctr, int const val) { - CounterList::iterator it = counterList.find(ctr); + CounterList::iterator const it = counterList.find(ctr); if (it == counterList.end()) { lyxerr << "set: Counter does not exist: " << ctr << endl; return; @@ -119,9 +120,9 @@ void Counters::set(string const & ctr, int val) } -void Counters::addto(string const & ctr, int val) +void Counters::addto(string const & ctr, int const val) { - CounterList::iterator it = counterList.find(ctr); + CounterList::iterator const it = counterList.find(ctr); if (it == counterList.end()) { lyxerr << "addto: Counter does not exist: " << ctr << endl; return; @@ -132,7 +133,7 @@ void Counters::addto(string const & ctr, int val) int Counters::value(string const & ctr) const { - CounterList::const_iterator cit = counterList.find(ctr); + CounterList::const_iterator const cit = counterList.find(ctr); if (cit == counterList.end()) { lyxerr << "value: Counter does not exist: " << ctr << endl; return 0; @@ -151,7 +152,7 @@ void Counters::step(string const & ctr) it->second.step(); it = counterList.begin(); - CounterList::iterator end = counterList.end(); + CounterList::iterator const end = counterList.end(); for (; it != end; ++it) { if (it->second.master() == ctr) { it->second.reset(); @@ -163,7 +164,7 @@ void Counters::step(string const & ctr) void Counters::reset() { CounterList::iterator it = counterList.begin(); - CounterList::iterator end = counterList.end(); + CounterList::iterator const end = counterList.end(); for (; it != end; ++it) { it->second.reset(); } @@ -197,7 +198,7 @@ void Counters::copy(Counters & from, Counters & to, string const & match) namespace { -char loweralphaCounter(int n) +char loweralphaCounter(int const n) { if (n < 1 || n > 26) return '?'; @@ -205,7 +206,7 @@ char loweralphaCounter(int n) } -char alphaCounter(int n) +char alphaCounter(int const n) { if (n < 1 || n > 26) return '?'; @@ -213,7 +214,7 @@ char alphaCounter(int n) } -char hebrewCounter(int n) +char hebrewCounter(int const n) { static const char hebrew[22] = { 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', @@ -227,9 +228,9 @@ char hebrewCounter(int n) } -string const lowerromanCounter(int n) +string const lowerromanCounter(int const n) { - static char const * roman[20] = { + static char const * const roman[20] = { "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x", "xi", "xii", "xiii", "xiv", "xv", @@ -242,9 +243,9 @@ string const lowerromanCounter(int n) } -string const romanCounter(int n) +string const romanCounter(int const n) { - static char const * roman[20] = { + static char const * const roman[20] = { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", @@ -281,7 +282,7 @@ string Counters::labelItem(string const & ctr, string const & numbertype) if (numbertype == "Roman") return romanCounter(value(ctr)); - return tostr(value(ctr)); + return convert(value(ctr)); } @@ -289,7 +290,9 @@ string Counters::counterLabel(string const & format) { string label = format; while (true) { -#warning Using boost::regex would make this code a lot simpler... (Lgb) +#ifdef WITH_WARNINGS +#warning Using boost::regex or boost::spirit would make this code a lot simpler... (Lgb) +#endif size_t const i = label.find('\\', 0); if (i == string::npos) @@ -310,31 +313,3 @@ string Counters::counterLabel(string const & format) //lyxerr << "counterLabel: " << format << " -> " << label << endl; return label; } - - -string Counters::enumLabel(string const & ctr, string const & langtype) -{ - ostringstream os; - - if (langtype == "hebrew") { - if (ctr == "enumi") - os << '.' << value("enumi"); - else if (ctr == "enumii") - os << '(' << hebrewCounter(value("enumii")) << ')'; - else if (ctr == "enumiii") - os << '.' << lowerromanCounter(value("enumiii")); - else if (ctr == "enumiv") - os << '.' << alphaCounter(value("enumiv")); - } else { - if (ctr == "enumi") - os << value("enumi") << '.'; - else if (ctr == "enumii") - os << '(' << loweralphaCounter(value("enumii")) << ')'; - else if (ctr == "enumiii") - os << lowerromanCounter(value("enumiii")) << '.'; - else if (ctr == "enumiv") - os << alphaCounter(value("enumiv")) << '.'; - } - - return os.str(); -}