X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCounters.cpp;h=a0f1d139d7cce2f0819eb31949629c7f1f26caf4;hb=0a7705a6736a85c3c751f7b4e9998833cdb71fc9;hp=a79bc6b36d64bdf491cc92259cafbf8897214a77;hpb=834bfe5e2143179ac3ccb6dd9a0618d349bf6958;p=lyx.git diff --git a/src/Counters.cpp b/src/Counters.cpp index a79bc6b36d..a0f1d139d7 100644 --- a/src/Counters.cpp +++ b/src/Counters.cpp @@ -171,18 +171,20 @@ bool Counters::hasCounter(docstring const & c) const } -bool Counters::read(Lexer & lex, docstring const & name) +bool Counters::read(Lexer & lex, docstring const & name, bool makenew) { if (hasCounter(name)) { LYXERR(Debug::TCLASS, "Reading existing counter " << to_utf8(name)); return counterList_[name].read(lex); } + LYXERR(Debug::TCLASS, "Reading new counter " << to_utf8(name)); Counter cnt; bool success = cnt.read(lex); - if (success) + // if makenew is false, we will just discard what we read + if (success && makenew) counterList_[name] = cnt; - else + else if (!success) LYXERR0("Error reading counter `" << name << "'!"); return success; } @@ -249,6 +251,10 @@ void Counters::reset() appendix_ = false; subfloat_ = false; current_float_.erase(); + CounterList::iterator it = counterList_.begin(); + CounterList::iterator const end = counterList_.end(); + for (; it != end; ++it) + it->second.reset(); } @@ -417,7 +423,7 @@ docstring Counters::theCounter(docstring const & counter, if (it == counterList_.end()) return from_ascii("??"); Counter const & ctr = it->second; - Counter::StringMap sm = ctr.flatLabelStrings(appendix()); + Counter::StringMap & sm = ctr.flatLabelStrings(appendix()); Counter::StringMap::iterator smit = sm.find(lang); if (smit != sm.end()) return counterLabel(smit->second, lang); @@ -489,9 +495,10 @@ docstring Counters::counterLabel(docstring const & format, // FIXME: Using regexps would be better, but we compile boost without // wide regexps currently. + docstring const the = from_ascii("\\the"); while (true) { - //lyxerr << "label=" << to_utf8(label) << endl; - size_t const i = label.find(from_ascii("\\the"), 0); + //lyxerr << "label=" << label << endl; + size_t const i = label.find(the, 0); if (i == docstring::npos) break; size_t const j = i + 4; @@ -499,12 +506,11 @@ docstring Counters::counterLabel(docstring const & format, while (k < label.size() && lowercase(label[k]) >= 'a' && lowercase(label[k]) <= 'z') ++k; - docstring const newc = label.substr(j, k - j); - docstring const repl = theCounter(newc, lang); - label.replace(i, k - j + 4, repl); + docstring const newc(label, j, k - j); + label.replace(i, k - i, theCounter(newc, lang)); } while (true) { - //lyxerr << "label=" << to_utf8(label) << endl; + //lyxerr << "label=" << label << endl; size_t const i = label.find('\\', 0); if (i == docstring::npos) @@ -517,11 +523,9 @@ docstring Counters::counterLabel(docstring const & format, 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, docstring::npos); + label.replace(i, k + 1 - i, labelItem(counter, numbertype)); } - //lyxerr << "DONE! label=" << to_utf8(label) << endl; + //lyxerr << "DONE! label=" << label << endl; return label; }