1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
10 * ====================================================== */
18 #include "support/lstrings.h"
19 #include "support/LAssert.h"
31 void Counter::set(int v)
37 void Counter::addto(int v)
43 int Counter::value() const
61 string Counter::master() const
67 void Counter::setMaster(string const & m)
74 void Counters::newCounter(string const & newc)
76 // First check if newc already exist
77 CounterList::iterator cit = counterList.find(newc);
78 // if already exist give warning and return
79 if (cit != counterList.end()) {
80 lyxerr << "The new counter already exists." << endl;
87 void Counters::newCounter(string const & newc, string const & masterc)
89 // First check if newc already exists
90 CounterList::iterator cit = counterList.find(newc);
91 // if already existant give warning and return
92 if (cit != counterList.end()) {
93 lyxerr << "The new counter already exists." << endl;
96 // then check if masterc exists
97 CounterList::iterator it = counterList.find(masterc);
98 // if not give warning and return
99 if (it == counterList.end()) {
100 lyxerr << "The master counter does not exist." << endl;
104 counterList[newc].setMaster(masterc);
108 void Counters::set(string const & ctr, int val)
110 CounterList::iterator it = counterList.find(ctr);
111 if (it == counterList.end()) {
112 lyxerr << "set: Counter does not exist: " << ctr << endl;
119 void Counters::addto(string const & ctr, int val)
121 CounterList::iterator it = counterList.find(ctr);
122 if (it == counterList.end()) {
123 lyxerr << "addto: Counter does not exist: " << ctr << endl;
126 it->second.addto(val);
130 int Counters::value(string const & ctr) const
132 CounterList::const_iterator cit = counterList.find(ctr);
133 if (cit == counterList.end()) {
134 lyxerr << "value: Counter does not exist: " << ctr << endl;
137 return cit->second.value();
141 void Counters::step(string const & ctr)
143 CounterList::iterator it = counterList.find(ctr);
144 if (it == counterList.end()) {
145 lyxerr << "step: Counter does not exist: " << ctr << endl;
150 it = counterList.begin();
151 CounterList::iterator end = counterList.end();
152 for (; it != end; ++it) {
153 if (it->second.master() == ctr) {
160 void Counters::reset()
162 CounterList::iterator it = counterList.begin();
163 CounterList::iterator end = counterList.end();
164 for (; it != end; ++it) {
170 void Counters::reset(string const & match)
172 lyx::Assert(!match.empty());
174 CounterList::iterator it = counterList.begin();
175 CounterList::iterator end = counterList.end();
176 for (; it != end; ++it) {
177 if (it->first.find(match) != string::npos)
183 void Counters::copy(Counters & from, Counters & to, string const & match)
185 CounterList::iterator it = counterList.begin();
186 CounterList::iterator end = counterList.end();
187 for (; it != end; ++it) {
188 if (it->first.find(match) != string::npos || match == "") {
189 to.set(it->first, from.value(it->first));
198 char loweralphaCounter(int n)
208 char alphaCounter(int n)
218 char hebrewCounter(int n)
220 static const char hebrew[22] = {
221 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è',
222 'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö',
233 string const romanCounter(int n)
235 static char const * roman[20] = {
236 "i", "ii", "iii", "iv", "v",
237 "vi", "vii", "viii", "ix", "x",
238 "xi", "xii", "xiii", "xiv", "xv",
239 "xvi", "xvii", "xviii", "xix", "xx"
250 string Counters::labelItem(string const & ctr,
251 string const & numbertype,
252 string const & langtype,
258 CounterList::iterator it = counterList.find(ctr);
259 if (it == counterList.end()) {
260 lyxerr << "Counter does not exist." << endl;
265 s << '.' << value(ctr);
267 if (numbertype == "sectioning" || numbertype == "appendix") {
268 if (numbertype == "appendix") {
269 if (langtype == "hebrew") {
270 o << hebrewCounter(value(ctr));
272 o << alphaCounter(value(ctr));
274 } else o << value(ctr);
279 return STRCONV(s.str());
283 string Counters::numberLabel(string const & ctr,
284 string const & numbertype,
285 string const & langtype,
290 if (numbertype == "sectioning" || numbertype == "appendix") {
291 if (ctr == "chapter" && head == 0) {
292 s << labelItem("chapter", numbertype, langtype, true);
293 } else if (ctr == "section" && head <= 1) {
294 s << numberLabel("chapter", numbertype, langtype, head)
295 << labelItem("section", numbertype, langtype, head == 1);
296 } else if (ctr == "subsection" && head <= 2) {
297 s << numberLabel("section", numbertype, langtype, head)
298 << labelItem("subsection", numbertype, langtype, head == 2);
299 } else if (ctr == "subsubsection" && head <= 3) {
300 s << numberLabel("subsection", numbertype, langtype, head)
301 << labelItem("subsubsection", numbertype, langtype, head == 3);
302 } else if (ctr == "paragraph" && head <= 4) {
303 s << numberLabel("subsubsection", numbertype, langtype, head)
304 << labelItem("paragraph", numbertype, langtype, head == 4);
305 } else if (ctr == "subparagraph" && head <= 5) {
306 s << numberLabel("paragraph", numbertype, langtype, head)
307 << labelItem("subparagraph", numbertype, langtype, head == 5);
308 } else if (ctr == "figure" || ctr == "table") {
309 // figure, table, ...
310 lyxerr << "Counter:" << ctr << endl;
311 s << numberLabel("chapter", numbertype, langtype, head)
312 << labelItem(ctr, numbertype, langtype, head == 1);
315 } else if (numbertype == "enumeration") {
321 if (langtype == "hebrew") {
322 ei << '.' << value("enumi");
323 eii << '(' << hebrewCounter(value("enumii")) << ')';
324 eiii << '.' << romanCounter(value("enumiii"));
325 eiv << '.' << alphaCounter(value("enumiv"));
327 ei << value("enumi") << '.';
328 eii << '(' << loweralphaCounter(value("enumii")) << ')';
329 eiii << romanCounter(value("enumiii")) << '.';
330 eiv << alphaCounter(value("enumiv")) << '.';
332 if (ctr == "enumii") {
334 } else if (ctr == "enumi") {
336 } else if (ctr == "enumiii") {
338 } else if (ctr == "enumiv") {
343 return STRCONV(s.str());