#include "counters.h"
#include "debug.h"
#include "support/lstrings.h"
+#include "support/LAssert.h"
using std::endl;
using std::vector;
sects.push_back("subsubsection");
sects.push_back("paragraph");
sects.push_back("subparagraph");
-
+
// Enumeration counters:
newCounter("enumi");
newCounter("enumii", "enumi");
enums.push_back("enumii");
enums.push_back("enumiii");
enums.push_back("enumiv");
-
+
// Biblio:
newCounter("bibitem");
-
+
// Float counters:
newCounter("Figure");
newCounter("Table");
counterList[newc];
cit = counterList.find(newc);
- cit->second.setMaster(masterc);
+ cit->second.setMaster(masterc);
}
}
}
+
+void Counters::reset()
+{
+ CounterList::iterator it = counterList.begin();
+ CounterList::iterator end = counterList.end();
+ for (; it != end; ++it) {
+ it->second.reset();
+ }
+}
+
+
void Counters::reset(string const & match)
{
+ lyx::Assert(!match.empty());
+
CounterList::iterator it = counterList.begin();
CounterList::iterator end = counterList.end();
for (; it != end; ++it) {
- if (it->first.find(match) != string::npos || match == "")
+ if (it->first.find(match) != string::npos)
it->second.reset();
- }
+ }
}
+
void Counters::copy(Counters & from, Counters & to, string const & match)
{
CounterList::iterator it = counterList.begin();
for (; it != end; ++it) {
if (it->first.find(match) != string::npos || match == "") {
to.set(it->first, from.value(it->first));
- }
- }
+ }
+ }
}
namespace {
-
+
inline
char loweralphaCounter(int n)
{
return 'a' + n - 1;
}
+
inline
char alphaCounter(int n)
{
return 'A' + n - 1;
}
+
inline
char hebrewCounter(int n)
{
return hebrew[n-1];
}
+
inline
string const romanCounter(int n)
{
} // namespace anon
+
string Counters::labelItem(string const & ctr,
- string const & numbertype,
- string const & langtype,
- bool first)
+ string const & numbertype,
+ string const & langtype,
+ bool first)
{
ostringstream s, o;
CounterList::iterator it = counterList.find(ctr);
return s.str();
}
+
string Counters::numberLabel(string const & ctr,
- string const & numbertype,
- string const & langtype,
- int head)
+ string const & numbertype,
+ string const & langtype,
+ int head)
{
ostringstream s, o;
if (numbertype == "sectioning" || numbertype == "appendix") {
s << numberLabel("chapter", numbertype, langtype, head)
<< labelItem("section", numbertype, langtype, head == 1);
} else if (ctr == "subsection" && head <= 2) {
- s << numberLabel("section", numbertype, langtype, head)
+ s << numberLabel("section", numbertype, langtype, head)
<< labelItem("subsection", numbertype, langtype, head == 2);
} else if (ctr == "subsubsection" && head <= 3) {
- s << numberLabel("subsection", numbertype, langtype, head)
+ s << numberLabel("subsection", numbertype, langtype, head)
<< labelItem("subsubsection", numbertype, langtype, head == 3);
} else if (ctr == "paragraph" && head <= 4) {
- s << numberLabel("subsubsection", numbertype, langtype, head)
+ s << numberLabel("subsubsection", numbertype, langtype, head)
<< labelItem("paragraph", numbertype, langtype, head == 4);
} else if (ctr == "subparagraph" && head <= 5) {
- s << numberLabel("paragraph", numbertype, langtype, head)
+ s << numberLabel("paragraph", numbertype, langtype, head)
<< labelItem("subparagraph", numbertype, langtype, head == 5);
} else if (ctr == "Figure" || ctr == "Table") {
// figure, table, ...
s << numberLabel("chapter", numbertype, langtype, head)
<< labelItem(ctr, numbertype, langtype, head == 1);
}
-
+
} else if (numbertype == "enumeration") {
ostringstream ei, eii, eiii, eiv;
//string ei, eiii, eiv;
eiv << alphaCounter(value("enumiv")) << '.';
}
if (ctr == "enumii") {
- s << eii.str();
+ s << eii.str();
} else if (ctr == "enumi") {
- s << ei.str();
+ s << ei.str();
} else if (ctr == "enumiii") {
s << eiii.str();
} else if (ctr == "enumiv") {
s << eiv.str();
}
- }
+ }
return s.str();
}