summaryrefslogtreecommitdiff
path: root/src/core/xbstring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/xbstring.cpp')
-rwxr-xr-xsrc/core/xbstring.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/core/xbstring.cpp b/src/core/xbstring.cpp
index 872062f..81e67b8 100755
--- a/src/core/xbstring.cpp
+++ b/src/core/xbstring.cpp
@@ -1358,6 +1358,61 @@ xbString &xbString::Remove(xbUInt32 ulStartPos, xbUInt32 ulDelSize ) {
}
+
+
+
+/************************************************************************/
+//! @brief Replace a value within a string with another value
+/*!
+ \param sReplace - Character string to replace.
+ \param sReplaceWith - Character string to replace with
+ \param iOption - 0 = All occurrences, 1 = first occurrence
+ \returns Reference to this string.
+*/
+
+//the new size includes the null termination byte
+xbString &xbString::Replace( const char *sReplace, const char *sReplaceWith, xbInt16 iOption ){
+
+ xbBool bDone = xbFalse;
+ xbUInt32 ulPos;
+ xbUInt32 ulNewSize;
+ xbUInt32 ulSp2;
+ char *sBuf2;
+
+ while( !bDone ){
+ ulPos = Pos( sReplace );
+ if( ulPos == 0 ){
+ bDone = xbTrue;
+ } else {
+
+ ulNewSize = this->size + sizeof( sReplaceWith ) - sizeof( sReplace );
+ sBuf2 = (char *) calloc( 1, ulNewSize );
+
+ // copy part1
+ for( xbUInt32 ul = 0; ul < ulPos-1; ul++ )
+ sBuf2[ul] = data[ul];
+
+ // copy part2
+ strcat( sBuf2, sReplaceWith );
+
+ // copy part3
+ ulSp2 = ulPos + strlen( sReplace );
+ char *p = data;
+ p+= (ulSp2 - 1);
+ strcat( sBuf2, p );
+
+ if( iOption )
+ bDone = xbTrue;
+
+ free(data);
+ data = sBuf2;
+
+ }
+ }
+
+ return *this;
+}
+
/************************************************************************/
//! @brief Resize a string
/*!