#include <config.h>
#include "Counters.h"
-#include "debug.h"
-#include "support/lstrings.h"
#include "support/convert.h"
+#include "support/debug.h"
+#include "support/lstrings.h"
-#include <boost/assert.hpp>
+#include "support/lassert.h"
#include <sstream>
-using std::endl;
-using std::ostringstream;
-using std::string;
+using namespace std;
+using namespace lyx::support;
namespace lyx {
-using support::lowercase;
Counter::Counter()
{
void Counters::reset()
{
appendix_ = false;
+ subfloat_ = false;
current_float_.erase();
CounterList::iterator it = counterList.begin();
CounterList::iterator const end = counterList.end();
void Counters::reset(docstring const & match)
{
- BOOST_ASSERT(!match.empty());
+ LASSERT(!match.empty(), /**/);
CounterList::iterator it = counterList.begin();
CounterList::iterator end = counterList.end();
docstring const lowerromanCounter(int const n)
{
- return support::lowercase(romanCounter(n));
+ return lowercase(romanCounter(n));
}
} // namespace anon
docstring Counters::theCounter(docstring const & counter)
+{
+ std::set<docstring> callers;
+ return theCounter(counter, callers);
+}
+
+docstring Counters::theCounter(docstring const & counter,
+ std::set<docstring> & 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<std::set<docstring>::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 + "}";
+ if (ls.empty()) {
+ if (!c.master().empty())
+ ls = from_ascii("\\the") + c.master() + from_ascii(".");
+ ls += from_ascii("\\arabic{") + counter + "}";
+ }
+
+ label = counterLabel(ls, &callers);
+
+ 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<docstring> * callers)
{
docstring label = 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;