I believe that this makes more sense (and in the case of copy is probably 
correct too ;-) than the current code.

Martin, since I don't know the code at all or even fully understand what it 
is meant to be doing, perhaps you could have a look at the patch and 
ascertain that it is doing what you meant it to be doing in the ffirst place?

Index: src/counters.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/counters.C,v
retrieving revision 1.10
diff -u -p -r1.10 counters.C
--- src/counters.C	9 Aug 2002 12:15:18 -0000	1.10
+++ src/counters.C	9 Aug 2002 12:19:12 -0000
@@ -18,6 +18,8 @@
 #include "counters.h"
 #include "debug.h"
 #include "support/lstrings.h"
+#include "support/LAssert.h"
+
 
 using std::endl;
 using std::vector;
@@ -111,6 +113,8 @@ Counters::Counters()
 
 void Counters::newCounter(string const & newc)
 {
+	lyx::Assert(!newc.empty());
+
 	// First check if newc already exist
 	CounterList::iterator cit = counterList.find(newc);
 	// if already exist give warning and return
@@ -126,6 +130,8 @@ void Counters::newCounter(string const &
 
 void Counters::newCounter(string const & newc, string const & masterc)
 {
+	lyx::Assert(!newc.empty() && !masterc.empty());
+
 	// First check if newc already exists
 	CounterList::iterator cit = counterList.find(newc);
 	// if already existant give warning and return
@@ -198,24 +204,38 @@ void Counters::step(string const & ctr)
 	}
 }
 
+
+void Counters::reset()
+{
+	CounterList::iterator it  = counterList.begin();
+	CounterList::iterator end = counterList.end();
+
+	for (; it != end; ++it) {
+		it->second.reset();
+	}
+}
+
+
 void Counters::reset(string const & match)
 {
-	CounterList::iterator it = counterList.begin();
+	lyx::Assert(!match.empty());
+
+	CounterList::iterator it  = counterList.begin();
 	CounterList::iterator end = counterList.end();
+
 	for (; it != end; ++it) {
-		if (it->first.find(match) != string::npos || match == "")
+		if (it->first.find(match) != string::npos)
 			it->second.reset();
 	}
 }
 
-void Counters::copy(Counters & from, Counters & to, string const & match)
+
+void Counters::copy(Counters const & from)
 {
-	CounterList::iterator it = counterList.begin();
+	CounterList::iterator it  = counterList.begin();
 	CounterList::iterator end = counterList.end();
 	for (; it != end; ++it) {
-		if (it->first.find(match) != string::npos || match == "") {
-			to.set(it->first, from.value(it->first));
-		}
+		it->second.set(from.value(it->first));
 	}
 }
 
Index: src/counters.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/counters.h,v
retrieving revision 1.9
diff -u -p -r1.9 counters.h
--- src/counters.h	7 Aug 2002 14:15:06 -0000	1.9
+++ src/counters.h	9 Aug 2002 12:19:12 -0000
@@ -75,12 +75,15 @@ public:
 	/// NOTE sub-slaves not zeroed! That happens at slave's
 	/// first step 0->1. Seems to be sufficient.
 	void step(string const & ctr);
-	/// Reset counters matched by match string. Empty string matches
-	/// all.
-	void reset(string const & match = string());
-	/// Copy counters whose name matches match from the &from to 
-	/// the &to array of counters. Empty string matches all.
-	void copy(Counters & from, Counters & to, string const & match = string());
+	/// Reset all counters
+	void reset();
+	/// Reset counters that contain match as a sub-string.
+	/// Do not use match == string().
+	void reset(string const & match);
+
+	/// copy all counters from from to *this.
+	void copy(Counters const & from);
+
 	/// A numeric label's single item, like .1 for subsection number in
 	/// the 2.1.4 subsubsection number label. "first" indicates if this
 	/// is the first item to be displayed, usually chapter or section.
Index: src/text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.243
diff -u -p -r1.243 text2.C
--- src/text2.C	7 Aug 2002 16:31:45 -0000	1.243
+++ src/text2.C	9 Aug 2002 12:19:13 -0000
@@ -1222,17 +1222,17 @@ void LyXText::setCounter(Buffer const * 
 	// unless this is the first paragraph
 	if (par->previous()) {
 
-		par->counters().copy(par->previous()->counters(), par->counters(), "");
+		par->counters().copy(par->previous()->counters());
 		
 		par->params().appendix(par->previous()->params().appendix());
 		if (!par->params().appendix() && par->params().startOfAppendix()) {
 			par->params().appendix(true);
-			par->counters().reset("");
+			par->counters().reset();
 		}
 		par->enumdepth = par->previous()->enumdepth;
 		par->itemdepth = par->previous()->itemdepth;
 	} else {
-		par->counters().reset("");
+		par->counters().reset();
 		par->params().appendix(par->params().startOfAppendix());
 		par->enumdepth = 0;
 		par->itemdepth = 0;

Reply via email to