Date: Friday, November 25, 2005 @ 15:32:27
Author: marc
Path: /cvsroot/carob/carob
Modified: include/Common.hpp (1.11 -> 1.12) src/Common.cpp (1.5 -> 1.6)
src/JavaSocket.cpp (1.13 -> 1.14)
replaced "in place" converters
void toWString(wstring&, string&)
by functional ones
wstring toWString(string&)
--------------------+
include/Common.hpp | 14 ++++++--------
src/Common.cpp | 20 ++++++++++++--------
src/JavaSocket.cpp | 29 +++++++++++++++++++++--------
3 files changed, 39 insertions(+), 24 deletions(-)
Index: carob/include/Common.hpp
diff -u carob/include/Common.hpp:1.11 carob/include/Common.hpp:1.12
--- carob/include/Common.hpp:1.11 Thu Nov 24 12:18:18 2005
+++ carob/include/Common.hpp Fri Nov 25 15:32:27 2005
@@ -112,19 +112,17 @@
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)
+ * String to Wide-String conversion. FIXME: throw exception on error
* @param in original string
- * @return true if conversion ok, false otherwise
+ * @return converted wstring
*/
-extern bool stringToWString(std::wstring& out, const std::string& in);
+extern std::wstring toWString(const std::string& in);
/**
- * Wide-String to String conversion.
- * @param out string resulting from conversion (if success)
+ * Wide-String to String conversion. FIXME: throw exception on error
* @param in original wide string
- * @return true if conversion ok, false otherwise
+ * @return converted string
*/
-extern bool wstringToString(std::string& out, const std::wstring& in);
+extern std::string toString(const std::wstring& in);
/**
* Converts integers to wstring
* @param i integer to convert
Index: carob/src/Common.cpp
diff -u carob/src/Common.cpp:1.5 carob/src/Common.cpp:1.6
--- carob/src/Common.cpp:1.5 Thu Nov 10 12:00:31 2005
+++ carob/src/Common.cpp Fri Nov 25 15:32:27 2005
@@ -101,7 +101,7 @@
return result;
}
-bool stringToWString(wstring& out, const string& in)
+wstring toWString(const string& in)
{
bool ret = true;
const char* inarray = in.c_str();
@@ -113,7 +113,7 @@
memset((void*)&mbstate, 0, sizeof(mbstate));
// FIXME: this C function considers with NULL-terminated strings
- // find a real C++ substitute
+ // replace this code by a codecvt
size_t countConverted = mbsrtowcs(destwarray, &inarray, destWArrayLen,
&mbstate);
if (countConverted == (size_t)-1 || inarray != NULL)
{
@@ -121,13 +121,15 @@
}
else
{
- out = destwarray;
+ ; // out = destwarray;
}
+ wstring wsret(destwarray);
delete[] destwarray;
- return ret;
+ return wsret;
+ // return ret; FIXME throws instead
}
-bool wstringToString(string& out, const wstring& in)
+string toString(const wstring& in)
{
bool ret = true;
const wchar_t* inwarray = in.c_str();
@@ -138,7 +140,7 @@
memset((void*)&mbstate, 0, sizeof(mbstate));
// FIXME: this C function considers with NULL-terminated strings
- // find a real C++ substitute
+ // replace this code by a codecvt
size_t countConverted = wcsrtombs(destarray, &inwarray, destMBArrayLen,
&mbstate);
if (countConverted == (size_t)-1 || inwarray != NULL)
{
@@ -146,10 +148,12 @@
}
else
{
- out = destarray;
+ ; // out = destarray;
}
+ string sret(destarray);
delete[] destarray;
- return ret;
+ return sret;
+ // return ret; FIXME throws instead
}
wstring toWString(const int32_t& arg)
Index: carob/src/JavaSocket.cpp
diff -u carob/src/JavaSocket.cpp:1.13 carob/src/JavaSocket.cpp:1.14
--- carob/src/JavaSocket.cpp:1.13 Thu Nov 24 12:18:18 2005
+++ carob/src/JavaSocket.cpp Fri Nov 25 15:32:27 2005
@@ -100,7 +100,10 @@
*addressInfoPtr;
sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
- string hostAsString;
+ // try
+ string hostAsString = toString(host);
+#if 0
+ // FIXME catch conversion error/exception here
if (!wstringToString(hostAsString, host))
{
if (isErrorEnabled())
@@ -108,14 +111,14 @@
connected = false;
throw ConnectionException(L"Host string conversion failed");
}
-
+#endif
+
int error = getaddrinfo(hostAsString.c_str(), NULL, NULL, &addressInfoList);
if (error)
{
const char* gaiMsg = gai_strerror(error);
- wstring wMsg;
- stringToWString(wMsg, gaiMsg);
+ wstring wMsg = toWString(gaiMsg);
if (isErrorEnabled())
logError(fctName, wMsg);
connected = false;
@@ -173,6 +176,10 @@
return true;
}
+
+// Localization (Chapter 22) in
+// /usr/share/doc/gcc-4.0-base/libstdc++/html/documentation.html
+
size_t JavaSocket::writeJavaUTF(const wstring& str) const
throw (SocketIOException, UnexpectedException)
{
@@ -192,6 +199,7 @@
if (isVerboseEnabled())
logVerbose(fctName, L"Converting string...");
+ // FIXME: don't use this locale converter, we need to send UTF-8!
countConverted = wcsrtombs((char*)utfStr, &oriStr,
strlenPlusOne, &mbstate);
if (countConverted == (size_t)-1)
@@ -241,16 +249,21 @@
{
// FIXME: we don't support inline zeros. We should get rid of c_str
string received((const char*)utfStr);
- if (!stringToWString(s, received))
+
+ // FIXME: don't use this locale converter cause received is ALWAYS UTF-8!
+ s = toWString(received);
+
+#if 0 // FIXME catch conversion exception
{
delete[] utfStr;
throw SocketIOException(fctName
+ L"An error occured while converting the string.");
}
- else
- {
+#endif
+
sizeRead = (size_t)lenRec;
- }
+
+
}
delete[] utfStr;
}
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits