]> git.lyx.org Git - lyx.git/blobdiff - src/counters.C
update Basque and Romanian l10n
[lyx.git] / src / counters.C
index b794679ffe6f1b5cd91cceffccb12c714a3bcab2..78dceb03a7ebe88f28dcf9803bee31b927b4f3be 100644 (file)
 #include "debug.h"
 
 #include "support/lstrings.h"
-#include "support/std_sstream.h"
-#include "support/tostr.h"
+#include "support/convert.h"
 
 #include <boost/assert.hpp>
 
+#include <sstream>
+
+
+namespace lyx {
+
 using std::endl;
 using std::ostringstream;
+using std::string;
 
 
 Counter::Counter()
@@ -61,45 +66,52 @@ void Counter::reset()
 }
 
 
-string Counter::master() const
+docstring Counter::master() const
 {
        return master_;
 }
 
 
-void Counter::setMaster(string const & m)
+void Counter::setMaster(docstring const & m)
 {
        master_ = m;
 }
 
 
-void Counters::newCounter(string const & newc)
+void Counters::newCounter(docstring 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: "
+                      << to_utf8(newc)
+                      << endl;
                return;
        }
        counterList[newc];
 }
 
 
-void Counters::newCounter(string const & newc, string const & masterc)
+void Counters::newCounter(docstring const & newc,
+                         docstring 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: "
+                      << to_utf8(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: "
+                      << to_utf8(masterc)
+                      << endl;
                return;
        }
 
@@ -107,50 +119,54 @@ void Counters::newCounter(string const & newc, string const & masterc)
 }
 
 
-void Counters::set(string const & ctr, int val)
+void Counters::set(docstring 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;
+               lyxerr << "set: Counter does not exist: "
+                      << to_utf8(ctr) << endl;
                return;
        }
        it->second.set(val);
 }
 
 
-void Counters::addto(string const & ctr, int val)
+void Counters::addto(docstring 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;
+               lyxerr << "addto: Counter does not exist: "
+                      << to_utf8(ctr) << endl;
                return;
        }
        it->second.addto(val);
 }
 
 
-int Counters::value(string const & ctr) const
+int Counters::value(docstring 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;
+               lyxerr << "value: Counter does not exist: "
+                      << to_utf8(ctr) << endl;
                return 0;
        }
        return cit->second.value();
 }
 
 
-void Counters::step(string const & ctr)
+void Counters::step(docstring const & ctr)
 {
        CounterList::iterator it = counterList.find(ctr);
        if (it == counterList.end()) {
-               lyxerr << "step: Counter does not exist: " << ctr << endl;
+               lyxerr << "step: Counter does not exist: "
+                      << to_utf8(ctr) << endl;
                return;
        }
 
        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();
@@ -162,14 +178,14 @@ 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();
        }
 }
 
 
-void Counters::reset(string const & match)
+void Counters::reset(docstring const & match)
 {
        BOOST_ASSERT(!match.empty());
 
@@ -182,7 +198,7 @@ void Counters::reset(string const & match)
 }
 
 
-void Counters::copy(Counters & from, Counters & to, string const & match)
+void Counters::copy(Counters & from, Counters & to, docstring const & match)
 {
        CounterList::iterator it = counterList.begin();
        CounterList::iterator end = counterList.end();
@@ -196,15 +212,15 @@ 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) 
+       if (n < 1 || n > 26)
                return '?';
        return 'a' + n - 1;
 }
 
 
-char alphaCounter(int n)
+char alphaCounter(int const n)
 {
        if (n < 1 || n > 26)
                return '?';
@@ -212,7 +228,7 @@ char alphaCounter(int n)
 }
 
 
-char hebrewCounter(int n)
+char hebrewCounter(int const n)
 {
        static const char hebrew[22] = {
                'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è',
@@ -226,9 +242,9 @@ char hebrewCounter(int n)
 }
 
 
-string const lowerromanCounter(int n)
+docstring 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",
@@ -236,14 +252,14 @@ string const lowerromanCounter(int n)
        };
 
        if (n < 1 || n > 20)
-               return "??";
-       return roman[n - 1];
+               return from_ascii("??");
+       return from_ascii(roman[n - 1]);
 }
 
 
-string const romanCounter(int n)
+docstring 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",
@@ -251,28 +267,31 @@ string const romanCounter(int n)
        };
 
        if (n < 1 || n > 20)
-               return "??";
-       return roman[n - 1];
+               return from_ascii("??");
+       return from_ascii(roman[n - 1]);
 }
 
 } // namespace anon
 
 
-string Counters::labelItem(string const & ctr, string const & numbertype)
+docstring Counters::labelItem(docstring const & ctr,
+                             docstring const & numbertype)
 {
        if (counterList.find(ctr) == counterList.end()) {
-               lyxerr << "Counter " << ctr << " does not exist." << endl;
-               return string();
+               lyxerr << "Counter "
+                      << to_utf8(ctr)
+                      << " does not exist." << endl;
+               return docstring();
        }
 
        if (numbertype == "hebrew")
-               return string(1, hebrewCounter(value(ctr)));
+               return docstring(1, hebrewCounter(value(ctr)));
 
        if (numbertype == "alph")
-               return string(1, loweralphaCounter(value(ctr)));
+               return docstring(1, loweralphaCounter(value(ctr)));
 
        if (numbertype == "Alph")
-               return string(1, alphaCounter(value(ctr)));
+               return docstring(1, alphaCounter(value(ctr)));
 
        if (numbertype == "roman")
                return lowerromanCounter(value(ctr));
@@ -280,27 +299,31 @@ string Counters::labelItem(string const & ctr, string const & numbertype)
        if (numbertype == "Roman")
                return romanCounter(value(ctr));
 
-       return tostr(value(ctr));
+       return convert<docstring>(value(ctr));
 }
 
 
-string Counters::counterLabel(string const & format)
+docstring Counters::counterLabel(docstring const & format)
 {
-       string label = format;
+       docstring label = format;
        while (true) {
+#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)
+               if (i == docstring::npos)
                        break;
                size_t const j = label.find('{', i + 1);
-               if (j == string::npos)
+               if (j == docstring::npos)
                        break;
                size_t const k = label.find('}', j + 1);
                if (k == string::npos)
                        break;
-               string const numbertype(label, i + 1, j - i - 1);
-               string const counter(label, j + 1, k - j - 1);
-               string const rep = labelItem(counter, numbertype);
-               label = string(label, 0, i) + rep + string(label, k + 1, string::npos);
+               docstring const numbertype(label, i + 1, j - i - 1);
+               docstring const counter(label, j + 1, k - j - 1);
+               docstring const rep = labelItem(counter, numbertype);
+               label = docstring(label, 0, i) + rep + docstring(label, k + 1, string::npos);
                //lyxerr << "  : " << " (" << counter  << ","
                //      << numbertype << ") -> " << label << endl;
        }
@@ -309,29 +332,4 @@ string Counters::counterLabel(string const & format)
 }
 
 
-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 STRCONV(os.str());
-}
+} // namespace lyx