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 * ====================================================== */
17 #include "support/lstrings.h"
18 #include "support/LAssert.h"
30 void Counter::set(int v)
36 void Counter::addto(int v)
42 int Counter::value() const
60 string Counter::master() const
66 void Counter::setMaster(string const & m)
73 void Counters::newCounter(string const & newc)
75 // First check if newc already exist
76 CounterList::iterator cit = counterList.find(newc);
77 // if already exist give warning and return
78 if (cit != counterList.end()) {
79 lyxerr << "The new counter already exists." << endl;
86 void Counters::newCounter(string const & newc, string const & masterc)
88 // First check if newc already exists
89 CounterList::iterator cit = counterList.find(newc);
90 // if already existant give warning and return
91 if (cit != counterList.end()) {
92 lyxerr << "The new counter already exists." << endl;
95 // then check if masterc exists
96 CounterList::iterator it = counterList.find(masterc);
97 // if not give warning and return
98 if (it == counterList.end()) {
99 lyxerr << "The master counter does not exist." << endl;
103 counterList[newc].setMaster(masterc);
107 void Counters::set(string const & ctr, int val)
109 CounterList::iterator it = counterList.find(ctr);
110 if (it == counterList.end()) {
111 lyxerr << "set: Counter does not exist: " << ctr << endl;
118 void Counters::addto(string const & ctr, int val)
120 CounterList::iterator it = counterList.find(ctr);
121 if (it == counterList.end()) {
122 lyxerr << "addto: Counter does not exist: " << ctr << endl;
125 it->second.addto(val);
129 int Counters::value(string const & ctr) const
131 CounterList::const_iterator cit = counterList.find(ctr);
132 if (cit == counterList.end()) {
133 lyxerr << "value: Counter does not exist: " << ctr << endl;
136 return cit->second.value();
140 void Counters::step(string const & ctr)
142 CounterList::iterator it = counterList.find(ctr);
143 if (it == counterList.end()) {
144 lyxerr << "step: Counter does not exist: " << ctr << endl;
149 it = counterList.begin();
150 CounterList::iterator end = counterList.end();
151 for (; it != end; ++it) {
152 if (it->second.master() == ctr) {
159 void Counters::reset()
161 CounterList::iterator it = counterList.begin();
162 CounterList::iterator end = counterList.end();
163 for (; it != end; ++it) {
169 void Counters::reset(string const & match)
171 lyx::Assert(!match.empty());
173 CounterList::iterator it = counterList.begin();
174 CounterList::iterator end = counterList.end();
175 for (; it != end; ++it) {
176 if (it->first.find(match) != string::npos)
182 void Counters::copy(Counters & from, Counters & to, string const & match)
184 CounterList::iterator it = counterList.begin();
185 CounterList::iterator end = counterList.end();
186 for (; it != end; ++it) {
187 if (it->first.find(match) != string::npos || match == "") {
188 to.set(it->first, from.value(it->first));
197 char loweralphaCounter(int n)
207 char alphaCounter(int n)
217 char hebrewCounter(int n)
219 static const char hebrew[22] = {
220 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è',
221 'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö',
232 string const romanCounter(int n)
234 static char const * roman[20] = {
235 "i", "ii", "iii", "iv", "v",
236 "vi", "vii", "viii", "ix", "x",
237 "xi", "xii", "xiii", "xiv", "xv",
238 "xvi", "xvii", "xviii", "xix", "xx"
249 string Counters::labelItem(string const & ctr,
250 string const & numbertype,
251 string const & langtype,
257 CounterList::iterator it = counterList.find(ctr);
258 if (it == counterList.end()) {
259 lyxerr << "Counter does not exist." << endl;
264 s << '.' << value(ctr);
266 if (numbertype == "sectioning" || numbertype == "appendix") {
267 if (numbertype == "appendix") {
268 if (langtype == "hebrew") {
269 o << hebrewCounter(value(ctr));
271 o << alphaCounter(value(ctr));
273 } else o << value(ctr);
278 return STRCONV(s.str());
282 string Counters::numberLabel(string const & ctr,
283 string const & numbertype,
284 string const & langtype,
289 if (numbertype == "sectioning" || numbertype == "appendix") {
290 if (ctr == "chapter" && head == 0) {
291 s << labelItem("chapter", numbertype, langtype, true);
292 } else if (ctr == "section" && head <= 1) {
293 s << numberLabel("chapter", numbertype, langtype, head)
294 << labelItem("section", numbertype, langtype, head == 1);
295 } else if (ctr == "subsection" && head <= 2) {
296 s << numberLabel("section", numbertype, langtype, head)
297 << labelItem("subsection", numbertype, langtype, head == 2);
298 } else if (ctr == "subsubsection" && head <= 3) {
299 s << numberLabel("subsection", numbertype, langtype, head)
300 << labelItem("subsubsection", numbertype, langtype, head == 3);
301 } else if (ctr == "paragraph" && head <= 4) {
302 s << numberLabel("subsubsection", numbertype, langtype, head)
303 << labelItem("paragraph", numbertype, langtype, head == 4);
304 } else if (ctr == "subparagraph" && head <= 5) {
305 s << numberLabel("paragraph", numbertype, langtype, head)
306 << labelItem("subparagraph", numbertype, langtype, head == 5);
307 } else if (ctr == "figure" || ctr == "table") {
308 // figure, table, ...
309 lyxerr << "Counter:" << ctr << endl;
310 s << numberLabel("chapter", numbertype, langtype, head)
311 << labelItem(ctr, numbertype, langtype, head == 1);
314 } else if (numbertype == "enumeration") {
320 if (langtype == "hebrew") {
321 ei << '.' << value("enumi");
322 eii << '(' << hebrewCounter(value("enumii")) << ')';
323 eiii << '.' << romanCounter(value("enumiii"));
324 eiv << '.' << alphaCounter(value("enumiv"));
326 ei << value("enumi") << '.';
327 eii << '(' << loweralphaCounter(value("enumii")) << ')';
328 eiii << romanCounter(value("enumiii")) << '.';
329 eiv << alphaCounter(value("enumiv")) << '.';
331 if (ctr == "enumii") {
333 } else if (ctr == "enumi") {
335 } else if (ctr == "enumiii") {
337 } else if (ctr == "enumiv") {
342 return STRCONV(s.str());