X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCounters.cpp;h=54fb9a720a9ff2ff416b572dcea52c6f8a973420;hb=e1453ef6873b8c6d371a62471c5d309154133866;hp=1c910b115c2e4cdf7595cac964282e2527b5bcc9;hpb=b89cc942eb458284f40f4d4e7db58890c3288979;p=lyx.git diff --git a/src/Counters.cpp b/src/Counters.cpp index 1c910b115c..54fb9a720a 100644 --- a/src/Counters.cpp +++ b/src/Counters.cpp @@ -171,6 +171,7 @@ void Counters::step(docstring const & ctr) void Counters::reset() { appendix_ = false; + subfloat_ = false; current_float_.erase(); CounterList::iterator it = counterList.begin(); CounterList::iterator const end = counterList.end(); @@ -300,7 +301,7 @@ docstring const romanCounter(int const n) docstring const lowerromanCounter(int const n) { - return support::lowercase(romanCounter(n)); + return lowercase(romanCounter(n)); } } // namespace anon @@ -339,23 +340,48 @@ docstring Counters::labelItem(docstring const & ctr, docstring Counters::theCounter(docstring const & counter) +{ + std::set callers; + return theCounter(counter, callers); +} + +docstring Counters::theCounter(docstring const & counter, + std::set & callers) { if (!hasCounter(counter)) return from_ascii("??"); - Counter const & c = counterList[counter]; - docstring ls = appendix() ? c.labelStringAppendix() : c.labelString(); + docstring label; + + if (callers.find(counter) == callers.end()) { + + pair::iterator, bool> result = callers.insert(counter); + + Counter const & c = counterList[counter]; + docstring ls = appendix() ? c.labelStringAppendix() : c.labelString(); + + if (ls.empty()) { + if (!c.master().empty()) + ls = from_ascii("\\the") + c.master() + from_ascii("."); + ls += from_ascii("\\arabic{") + counter + "}"; + } + + label = counterLabel(ls, &callers); - if (ls.empty()) { - if (!c.master().empty()) - ls = from_ascii("\\the") + c.master() + from_ascii("."); - ls += from_ascii("\\arabic{") + counter + "}"; + callers.erase(result.first); + } else { + // recursion detected + lyxerr << "Warning: Recursion in label for counter `" + << counter << "' detected" + << endl; } - return counterLabel(ls); + + return label; } -docstring Counters::counterLabel(docstring const & format) +docstring Counters::counterLabel(docstring const & format, + std::set * callers) { docstring label = format; @@ -373,10 +399,11 @@ docstring Counters::counterLabel(docstring const & format) && lowercase(label[k]) <= 'z') ++k; docstring counter = label.substr(j, k - j); - docstring repl = theCounter(counter); + docstring repl = callers? theCounter(counter, *callers): + theCounter(counter); label.replace(i, k - j + 4, repl); } - + while (true) { //lyxerr << "label=" << to_utf8(label) << endl;