|
From: <axl...@us...> - 2010-01-15 21:52:24
|
Revision: 662
http://hgengine.svn.sourceforge.net/hgengine/?rev=662&view=rev
Author: axlecrusher
Date: 2010-01-15 21:52:17 +0000 (Fri, 15 Jan 2010)
Log Message:
-----------
add replace routine
Modified Paths:
--------------
Mercury2/src/MercuryString.cpp
Mercury2/src/MercuryString.h
Modified: Mercury2/src/MercuryString.cpp
===================================================================
--- Mercury2/src/MercuryString.cpp 2010-01-15 18:58:16 UTC (rev 661)
+++ Mercury2/src/MercuryString.cpp 2010-01-15 21:52:17 UTC (rev 662)
@@ -336,6 +336,17 @@
return strncmp( m_sCur + start, cmp, len );
}
+MString MString::replace(const MString& old, const MString& n)
+{
+ if (this->empty() || old.empty() || n.empty()) return *this;
+
+ int i = this->find(old);
+ if (i<0) return *this;
+
+ MString s = this->substr(0,i) + n + this->substr(i+old.length());
+ return s.replace(old, n);
+}
+
unsigned int MString::hash() const
{
unsigned int ret = 0;
Modified: Mercury2/src/MercuryString.h
===================================================================
--- Mercury2/src/MercuryString.h 2010-01-15 18:58:16 UTC (rev 661)
+++ Mercury2/src/MercuryString.h 2010-01-15 21:52:17 UTC (rev 662)
@@ -65,6 +65,8 @@
int compare( int start, int len, const MString & cmp ) const;
int compare( int start, int len, const char * cmp ) const;
+ MString replace(const MString& old, const MString& n);
+
unsigned int hash() const;
enum
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|