Update of /cvsroot/pclasses/pclasses2/src/Util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18463/src/Util
Modified Files:
StringTool.cpp
Log Message:
i believe i fixed an endless loop involving a "too long search".
Index: StringTool.cpp
===================================================================
RCS file: /cvsroot/pclasses/pclasses2/src/Util/StringTool.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- StringTool.cpp 26 Dec 2004 13:11:02 -0000 1.5
+++ StringTool.cpp 26 Dec 2004 18:46:43 -0000 1.6
@@ -1,5 +1,5 @@
#include <pclasses/Util/StringTool.h>
-// #include <pclasses/s11n/s11n_debuggering_macros.h> // CERR
+#include <pclasses/s11n/s11n_debuggering_macros.h> // CERR
namespace P {
namespace StringTool {
@@ -9,6 +9,7 @@
if( str.empty() || ( 0 == map.size() ) ) return 0;
size_t count = 0;
std::string::size_type pos = str.npos;
+ std::string::size_type pos2 = str.npos;
EntityMap::const_iterator mit;
EntityMap::const_iterator met = map.end();
std::string key;
@@ -22,11 +23,14 @@
{
key = (*mit).second;
val = (*mit).first;
- while( str.npos != (pos = str.rfind( key )) )
+ //CERR << "reverse-map key=["<<key<<"] val=["<<val<<"]\n";
+ while( str.npos != (pos = str.rfind( key, pos2 )) )
{
++count;
+ pos2 = pos-1;
str.replace( pos, key.size(), val );
}
+ pos2 = str.size() - 1;
}
}
else
@@ -34,15 +38,21 @@
// CERR << "Translating entities in ["<<str<<"]...\n";
// treat KEY=VAL as KEY=VAL
mit = map.begin();
+ pos = 0;
+ pos2 = str.size()-1;
for( ; mit != met; ++mit )
{
key = (*mit).first;
val = (*mit).second;
- while( str.npos != (pos = str.rfind( key )) )
+ //CERR << "forward-map key=["<<key<<"] val=["<<val<<"]\n";
+ while( str.npos != (pos = str.rfind( key, pos2 )) )
{
+ //CERR << "forward-map key=["<<key<<"] val=["<<val<<"]\n";
++count;
+ pos2 = pos-1;
str.replace( pos, key.size(), val );
}
+ pos2 = str.size()-1;
}
// this code works, and is much more efficient, but only accepts keys with length of 1:
// pos = str.size() - 1;
|