Date: Thursday, November 10, 2005 @ 12:00:32
Author: gilles
Path: /cvsroot/carob/carob
Modified: include/Common.hpp (1.8 -> 1.9) src/Common.cpp (1.4 -> 1.5)
Added LineSeparator constant
Added trim() function for wstrings
--------------------+
include/Common.hpp | 16 ++++++++++++++++
src/Common.cpp | 22 +++++++++++++++++++---
2 files changed, 35 insertions(+), 3 deletions(-)
Index: carob/include/Common.hpp
diff -u carob/include/Common.hpp:1.8 carob/include/Common.hpp:1.9
--- carob/include/Common.hpp:1.8 Fri Oct 28 11:06:21 2005
+++ carob/include/Common.hpp Thu Nov 10 12:00:31 2005
@@ -49,6 +49,14 @@
LOG_LEVEL_ERROR
};
+// Line separator (EOL)
+//TODO: get this at runtime => ???
+#ifdef WIN32
+#define LINE_SEPARATOR L"\r\n"
+#else
+#define LINE_SEPARATOR L"\n"
+#endif
+
/** The current log level (set by setLogLevel) */
extern LogLevel currentLogLevel;
@@ -93,6 +101,14 @@
extern bool isErrorEnabled();
/**
+ * Removes given whitespaces from the begining and end of the given string
+ * @param source the string to be trimed
+ * @param delims string representing the whitespaces to remove
+ * @return copy of the input string without whitespaces and begining nor end
+ */
+extern std::wstring trim(const std::wstring& source,
+ const wchar_t* delims = L" \t\r\n");
+/**
* String to Wide-String conversion.
* @param out wstring resulting from conversion (if success)
* @param in original string
Index: carob/src/Common.cpp
diff -u carob/src/Common.cpp:1.4 carob/src/Common.cpp:1.5
--- carob/src/Common.cpp:1.4 Thu Nov 3 19:27:00 2005
+++ carob/src/Common.cpp Thu Nov 10 12:00:31 2005
@@ -85,7 +85,23 @@
return currentLogLevel <= LOG_LEVEL_ERROR;
}
-bool stringToWString(std::wstring& out, const std::string& in)
+wstring trim(const wstring& source,
+ const wchar_t* delims)
+{
+ wstring result(source);
+ string::size_type index = result.find_last_not_of(delims);
+ if(index != string::npos)
+ result.erase(++index);
+
+ index = result.find_first_not_of(delims);
+ if(index != string::npos)
+ result.erase(0, index);
+ else
+ result.erase();
+ return result;
+}
+
+bool stringToWString(wstring& out, const string& in)
{
bool ret = true;
const char* inarray = in.c_str();
@@ -111,7 +127,7 @@
return ret;
}
-bool wstringToString(std::string& out, const std::wstring& in)
+bool wstringToString(string& out, const wstring& in)
{
bool ret = true;
const wchar_t* inwarray = in.c_str();
@@ -136,7 +152,7 @@
return ret;
}
-std::wstring toWString(const int32_t& arg)
+wstring toWString(const int32_t& arg)
{
wostringstream buffer;
buffer << arg;
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits