]> git.lyx.org Git - lyx.git/blobdiff - src/counters.C
* src/tabular.[Ch]: simplify plaintext methods, because there
[lyx.git] / src / counters.C
index 624d71cc33837354904ae625fa4a9d90a0cb3850..72b052bd91f57731830025b6ce40d8d0c574405c 100644 (file)
@@ -22,7 +22,8 @@
 
 #include <sstream>
 
-using lyx::docstring;
+
+namespace lyx {
 
 using std::endl;
 using std::ostringstream;
@@ -65,7 +66,7 @@ void Counter::reset()
 }
 
 
-docstring Counter::master() const
+docstring const & Counter::master() const
 {
        return master_;
 }
@@ -84,7 +85,7 @@ void Counters::newCounter(docstring const & newc)
        // if already exist give warning and return
        if (cit != counterList.end()) {
                lyxerr << "New counter already exists: "
-                      << lyx::to_utf8(newc)
+                      << to_utf8(newc)
                       << endl;
                return;
        }
@@ -100,7 +101,7 @@ void Counters::newCounter(docstring const & newc,
        // if already existant give warning and return
        if (cit != counterList.end()) {
                lyxerr << "New counter already exists: "
-                      << lyx::to_utf8(newc)
+                      << to_utf8(newc)
                       << endl;
                return;
        }
@@ -109,7 +110,7 @@ void Counters::newCounter(docstring const & newc,
        // if not give warning and return
        if (it == counterList.end()) {
                lyxerr << "Master counter does not exist: "
-                      << lyx::to_utf8(masterc)
+                      << to_utf8(masterc)
                       << endl;
                return;
        }
@@ -123,7 +124,7 @@ void Counters::set(docstring const & ctr, int const val)
        CounterList::iterator const it = counterList.find(ctr);
        if (it == counterList.end()) {
                lyxerr << "set: Counter does not exist: "
-                      << lyx::to_utf8(ctr) << endl;
+                      << to_utf8(ctr) << endl;
                return;
        }
        it->second.set(val);
@@ -135,7 +136,7 @@ void Counters::addto(docstring const & ctr, int const val)
        CounterList::iterator const it = counterList.find(ctr);
        if (it == counterList.end()) {
                lyxerr << "addto: Counter does not exist: "
-                      << lyx::to_utf8(ctr) << endl;
+                      << to_utf8(ctr) << endl;
                return;
        }
        it->second.addto(val);
@@ -147,7 +148,7 @@ int Counters::value(docstring const & ctr) const
        CounterList::const_iterator const cit = counterList.find(ctr);
        if (cit == counterList.end()) {
                lyxerr << "value: Counter does not exist: "
-                      << lyx::to_utf8(ctr) << endl;
+                      << to_utf8(ctr) << endl;
                return 0;
        }
        return cit->second.value();
@@ -159,7 +160,7 @@ void Counters::step(docstring const & ctr)
        CounterList::iterator it = counterList.find(ctr);
        if (it == counterList.end()) {
                lyxerr << "step: Counter does not exist: "
-                      << lyx::to_utf8(ctr) << endl;
+                      << to_utf8(ctr) << endl;
                return;
        }
 
@@ -251,8 +252,8 @@ docstring const lowerromanCounter(int const n)
        };
 
        if (n < 1 || n > 20)
-               return lyx::from_ascii("??");
-       return lyx::from_ascii(roman[n - 1]);
+               return from_ascii("??");
+       return from_ascii(roman[n - 1]);
 }
 
 
@@ -266,8 +267,8 @@ docstring const romanCounter(int const n)
        };
 
        if (n < 1 || n > 20)
-               return lyx::from_ascii("??");
-       return lyx::from_ascii(roman[n - 1]);
+               return from_ascii("??");
+       return from_ascii(roman[n - 1]);
 }
 
 } // namespace anon
@@ -276,29 +277,32 @@ docstring const romanCounter(int const n)
 docstring Counters::labelItem(docstring const & ctr,
                              docstring const & numbertype)
 {
-       if (counterList.find(ctr) == counterList.end()) {
+       CounterList::const_iterator const cit = counterList.find(ctr);
+       if (cit == counterList.end()) {
                lyxerr << "Counter "
-                      << lyx::to_utf8(ctr)
+                      << to_utf8(ctr)
                       << " does not exist." << endl;
                return docstring();
        }
 
+       int val = cit->second.value();
+
        if (numbertype == "hebrew")
-               return docstring(1, hebrewCounter(value(ctr)));
+               return docstring(1, hebrewCounter(val));
 
        if (numbertype == "alph")
-               return docstring(1, loweralphaCounter(value(ctr)));
+               return docstring(1, loweralphaCounter(val));
 
        if (numbertype == "Alph")
-               return docstring(1, alphaCounter(value(ctr)));
+               return docstring(1, alphaCounter(val));
 
        if (numbertype == "roman")
-               return lowerromanCounter(value(ctr));
+               return lowerromanCounter(val);
 
        if (numbertype == "Roman")
-               return romanCounter(value(ctr));
+               return romanCounter(val);
 
-       return convert<docstring>(value(ctr));
+       return convert<docstring>(val);
 }
 
 
@@ -317,15 +321,19 @@ docstring Counters::counterLabel(docstring const & format)
                if (j == docstring::npos)
                        break;
                size_t const k = label.find('}', j + 1);
-               if (k == string::npos)
+               if (k == docstring::npos)
                        break;
                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);
+               label = docstring(label, 0, i) + rep 
+                       + docstring(label, k + 1, docstring::npos);
                //lyxerr << "  : " << " (" << counter  << ","
                //      << numbertype << ") -> " << label << endl;
        }
        //lyxerr << "counterLabel: " << format  << " -> "       << label << endl;
        return label;
 }
+
+
+} // namespace lyx