Date: Monday, December 19, 2005 @ 19:32:03
Author: zsolt
Path: /cvsroot/carob/carob
Modified: include/Common.hpp (1.24 -> 1.25) src/Common.cpp (1.17 -> 1.18)
create function replaceAll() which replace all occurence of a string with
another string
--------------------+
include/Common.hpp | 12 +++++++++++-
src/Common.cpp | 11 +++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
Index: carob/include/Common.hpp
diff -u carob/include/Common.hpp:1.24 carob/include/Common.hpp:1.25
--- carob/include/Common.hpp:1.24 Mon Dec 19 16:48:46 2005
+++ carob/include/Common.hpp Mon Dec 19 19:32:02 2005
@@ -16,7 +16,7 @@
* limitations under the License.
*
* Initial developer(s): Gilles Rayrat
- * Contributor(s):
+ * Contributor(s): Zsolt Simon
*/
#ifndef _COMMON_H_
#define _COMMON_H_
@@ -188,6 +188,16 @@
template <class T> bool wstringTo(T& t, const std::wstring& s);
/**
+ * Replace all occurence of string <code>from</code> to string <code>to</code>
+ * in string <code>src</code>
+ * @param src source string
+ * @param from string to searched
+ * @param to replacement string
+ * @return the replaced string
+ */
+std::wstring replaceAll(std::wstring src, const std::wstring &from, const
std::wstring &to);
+
+/**
* Defines data type that can be found in ResultSets
*/
union ResultSetDataType
Index: carob/src/Common.cpp
diff -u carob/src/Common.cpp:1.17 carob/src/Common.cpp:1.18
--- carob/src/Common.cpp:1.17 Mon Dec 19 16:48:46 2005
+++ carob/src/Common.cpp Mon Dec 19 19:32:03 2005
@@ -128,3 +128,14 @@
// Explicit instanciation for types actually used
// More info here: http://www.codeproject.com/cpp/templatesourceorg.asp
template bool CarobNS::wstringTo<int>(int&, const std::wstring&);
+
+wstring CarobNS::replaceAll(wstring src, const wstring &from, const wstring
&to)
+{
+ wstring::size_type found = src.find(from);
+ while (found != wstring::npos)
+ {
+ src.replace(found, from.length(), to);
+ found = src.find(from, found+to.length());
+ }
+ return src;
+}
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits