summaryrefslogtreecommitdiff
path: root/src/core/xbstring.cpp
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2023-01-29 15:45:51 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2023-01-29 15:45:51 +0100
commit517ad9d4b6eae320b708d03a9340a22893b0cab7 (patch)
tree37cf1907008821b4155cf90718b8d7b00a9d3461 /src/core/xbstring.cpp
parent4875a3dd9b183dcd2256e2abfc4ccf7484c233b4 (diff)
New upstream version 4.0.3upstream/4.0.3
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
/*!