summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2014-05-16 10:42:54 -0400
committerBernard Normier <bernard@zeroc.com>2014-05-16 10:42:54 -0400
commit5c41870b1df650b874069095fab2d29e93c76d3f (patch)
treeacbdeba2738a258f05b26c4f2597d7ba80fa7a2d /cpp/src/IceUtil
parentFixed ICE-710: error handling test for Unicode functions (diff)
downloadice-5c41870b1df650b874069095fab2d29e93c76d3f.tar.bz2
ice-5c41870b1df650b874069095fab2d29e93c76d3f.tar.xz
ice-5c41870b1df650b874069095fab2d29e93c76d3f.zip
Renamed wnativeToNative/nativeToWnative to wstringToString/stringToWstring
Diffstat (limited to 'cpp/src/IceUtil')
-rw-r--r--cpp/src/IceUtil/ConvertUTF.cpp1
-rw-r--r--cpp/src/IceUtil/ConvertUTF.h2
-rw-r--r--cpp/src/IceUtil/Exception.cpp56
-rw-r--r--cpp/src/IceUtil/FileUtil.cpp40
-rw-r--r--cpp/src/IceUtil/StringConverter.cpp67
-rw-r--r--cpp/src/IceUtil/StringUtil.cpp2
-rw-r--r--cpp/src/IceUtil/Unicode.cpp107
7 files changed, 87 insertions, 188 deletions
diff --git a/cpp/src/IceUtil/ConvertUTF.cpp b/cpp/src/IceUtil/ConvertUTF.cpp
index d6abc324738..0797c332062 100644
--- a/cpp/src/IceUtil/ConvertUTF.cpp
+++ b/cpp/src/IceUtil/ConvertUTF.cpp
@@ -49,6 +49,7 @@
#include <IceUtil/ConvertUTF.h>
+#include <IceUtil/StringConverter.h>
#ifdef CVTUTF_DEBUG
#include <stdio.h>
diff --git a/cpp/src/IceUtil/ConvertUTF.h b/cpp/src/IceUtil/ConvertUTF.h
index ce182b74213..17a638f320c 100644
--- a/cpp/src/IceUtil/ConvertUTF.h
+++ b/cpp/src/IceUtil/ConvertUTF.h
@@ -135,7 +135,7 @@ ConversionResult ConvertUTF32toUTF8(
UTF8** targetStart, UTF8* targetEnd, IceUtil::ConversionFlags flags);
//
-// isLegalUTFSequence is declared in IceUtil/Unicode.h
+// isLegalUTFSequence is declared in IceUtil/StringConverter.h
//
/* --------------------------------------------------------------------- */
diff --git a/cpp/src/IceUtil/Exception.cpp b/cpp/src/IceUtil/Exception.cpp
index 8498a6a5f55..36d3e017899 100644
--- a/cpp/src/IceUtil/Exception.cpp
+++ b/cpp/src/IceUtil/Exception.cpp
@@ -224,14 +224,14 @@ getStackTrace()
//
// Don't need to use pass a wide string converter in the bellow
- // calls to wnativeToNative as the wide strings come from
+ // calls to wstringToString as the wide strings come from
// Windows API.
//
BOOL ok = SymFromAddr(process, address, 0, symbol);
if(ok)
{
#ifdef DBGHELP_TRANSLATE_TCHAR
- s << IceUtil::wnativeToNative(converter, 0, symbol->Name);
+ s << IceUtil::wstringToString(symbol->Name, converter);
#else
s << symbol->Name;
#endif
@@ -240,7 +240,7 @@ getStackTrace()
{
s << " at line " << line.LineNumber << " in "
#ifdef DBGHELP_TRANSLATE_TCHAR
- << IceUtil::wnativeToNative(converter, 0, line.FileName);
+ << IceUtil::wstringToString(line.FileName, converter);
#else
<< line.FileName;
#endif
@@ -552,6 +552,56 @@ IceUtil::IllegalArgumentException::reason() const
return _reason;
}
+//
+// IllegalConversionException
+//
+
+const char* IceUtil::IllegalConversionException::_name = "IceUtil::IllegalConversionException";
+
+IceUtil::IllegalConversionException::IllegalConversionException(const char* file, int line):
+ Exception(file, line)
+{}
+
+IceUtil::IllegalConversionException::IllegalConversionException(const char* file, int line,
+ const string& reason):
+ Exception(file, line),
+ _reason(reason)
+{}
+
+string
+IceUtil::IllegalConversionException::ice_name() const
+{
+ return _name;
+}
+
+void
+IceUtil::IllegalConversionException::ice_print(ostream& out) const
+{
+ Exception::ice_print(out);
+ out << ": " << _reason;
+
+}
+
+IceUtil::IllegalConversionException*
+IceUtil::IllegalConversionException::ice_clone() const
+{
+ return new IllegalConversionException(*this);
+}
+
+void
+IceUtil::IllegalConversionException::ice_throw() const
+{
+ throw *this;
+}
+
+string
+IceUtil::IllegalConversionException::reason() const
+{
+ return _reason;
+}
+
+
+
IceUtil::SyscallException::SyscallException(const char* file, int line, int err ):
Exception(file, line),
_error(err)
diff --git a/cpp/src/IceUtil/FileUtil.cpp b/cpp/src/IceUtil/FileUtil.cpp
index d9080a3c62d..89379f5f3b6 100644
--- a/cpp/src/IceUtil/FileUtil.cpp
+++ b/cpp/src/IceUtil/FileUtil.cpp
@@ -104,8 +104,8 @@ IceUtilInternal::freopen(const std::string& path, const std::string& mode, FILE*
// to Windows API.
//
const IceUtil::StringConverterPtr converter = IceUtil::getProcessStringConverter();
- return _wfreopen(IceUtil::nativeToWnative(converter, 0, path).c_str(),
- IceUtil::nativeToWnative(converter, 0, mode).c_str(), stderr);
+ return _wfreopen(IceUtil::stringToWstring(path, converter).c_str(),
+ IceUtil::stringToWstring(mode, converter).c_str(), stderr);
# else
return freopen(path.c_str(), mode.c_str(), stderr);
# endif
@@ -124,13 +124,13 @@ IceUtilInternal::stat(const string& path, structstat* buffer)
// Don't need to use a wide string converter, the wide string is directly passed
// to Windows API.
//
- return _wstat(IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, path).c_str(), buffer);
+ return _wstat(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str(), buffer);
}
int
IceUtilInternal::remove(const string& path)
{
- return ::_wremove(IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, path).c_str());
+ return ::_wremove(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str());
}
int
@@ -141,8 +141,8 @@ IceUtilInternal::rename(const string& from, const string& to)
// to Windows API.
//
const IceUtil::StringConverterPtr converter = IceUtil::getProcessStringConverter();
- return ::_wrename(IceUtil::nativeToWnative(converter, 0, from).c_str(),
- IceUtil::nativeToWnative(converter, 0, to).c_str());
+ return ::_wrename(IceUtil::stringToWstring(from, converter).c_str(),
+ IceUtil::stringToWstring(to, converter).c_str());
}
int
@@ -152,7 +152,7 @@ IceUtilInternal::rmdir(const string& path)
// Don't need to use a wide string converter, the wide string is directly passed
// to Windows API.
//
- return ::_wrmdir(IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, path).c_str());
+ return ::_wrmdir(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str());
}
int
@@ -162,7 +162,7 @@ IceUtilInternal::mkdir(const string& path, int)
// Don't need to use a wide string converter, the wide string is directly passed
// to Windows API.
//
- return ::_wmkdir(IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, path).c_str());
+ return ::_wmkdir(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str());
}
FILE*
@@ -173,8 +173,8 @@ IceUtilInternal::fopen(const string& path, const string& mode)
// to Windows API.
//
const IceUtil::StringConverterPtr converter = IceUtil::getProcessStringConverter();
- return ::_wfopen(IceUtil::nativeToWnative(converter, 0, path).c_str(),
- IceUtil::nativeToWnative(converter, 0, mode).c_str());
+ return ::_wfopen(IceUtil::stringToWstring(path, converter).c_str(),
+ IceUtil::stringToWstring(mode, converter).c_str());
}
int
@@ -186,12 +186,12 @@ IceUtilInternal::open(const string& path, int flags)
//
if(flags & _O_CREAT)
{
- return ::_wopen(IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, path).c_str(),
+ return ::_wopen(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str(),
flags, _S_IREAD | _S_IWRITE);
}
else
{
- return ::_wopen(IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, path).c_str(), flags);
+ return ::_wopen(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str(), flags);
}
}
@@ -208,7 +208,7 @@ IceUtilInternal::getcwd(string& cwd)
{
return -1;
}
- cwd = IceUtil::wnativeToNative(IceUtil::getProcessStringConverter(), 0, cwdbuf);
+ cwd = IceUtil::wstringToString(cwdbuf, IceUtil::getProcessStringConverter());
return 0;
}
#endif
@@ -220,7 +220,7 @@ IceUtilInternal::unlink(const string& path)
// Don't need to use a wide string converter, the wide string is directly passed
// to Windows API.
//
- return _wunlink(IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, path).c_str());
+ return _wunlink(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str());
}
int
@@ -242,12 +242,12 @@ IceUtilInternal::FileLock::FileLock(const std::string& path) :
// to Windows API.
//
#ifndef ICE_OS_WINRT
- _fd = ::CreateFileW(IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, path).c_str(),
+ _fd = ::CreateFileW(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str(),
GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
#else
CREATEFILE2_EXTENDED_PARAMETERS params;
params.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
- _fd = ::CreateFile2(IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, path).c_str(),
+ _fd = ::CreateFile2(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str(),
GENERIC_WRITE, 0, OPEN_ALWAYS, &params);
#endif
_path = path;
@@ -306,7 +306,7 @@ IceUtilInternal::ifstream::ifstream(const string& path, ios_base::openmode mode)
// Don't need to use a wide string converter, the wide string is directly passed
// to Windows API.
//
- std::ifstream(IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, path).c_str(), mode)
+ std::ifstream(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str(), mode)
#endif
{
}
@@ -321,7 +321,7 @@ IceUtilInternal::ifstream::open(const string& path, ios_base::openmode mode)
// Don't need to use a wide string converter, the wide string is directly passed
// to Windows API.
//
- std::ifstream::open(IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, path).c_str(), mode);
+ std::ifstream::open(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str(), mode);
#endif
}
@@ -337,7 +337,7 @@ IceUtilInternal::ofstream::ofstream(const string& path, ios_base::openmode mode)
// Don't need to use a wide string converter, the wide string is directly passed
// to Windows API.
//
- std::ofstream(IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, path).c_str(), mode)
+ std::ofstream(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str(), mode)
#endif
{
}
@@ -352,7 +352,7 @@ IceUtilInternal::ofstream::open(const string& path, ios_base::openmode mode)
// Don't need to use a wide string converter, the wide string is directly passed
// to Windows API.
//
- std::ofstream::open(IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, path).c_str(), mode);
+ std::ofstream::open(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str(), mode);
#endif
}
diff --git a/cpp/src/IceUtil/StringConverter.cpp b/cpp/src/IceUtil/StringConverter.cpp
index 9b4d6e2c8f2..c76a636ac17 100644
--- a/cpp/src/IceUtil/StringConverter.cpp
+++ b/cpp/src/IceUtil/StringConverter.cpp
@@ -4,6 +4,7 @@
#include <IceUtil/Mutex.h>
#include <IceUtil/ScopedArray.h>
#include <IceUtil/StringUtil.h>
+#include <IceUtil/Unicode.h>
using namespace IceUtil;
using namespace IceUtilInternal;
@@ -34,54 +35,6 @@ public:
Init init;
-const char* __IceUtil__IllegalConversionException_name = "IceUtil::IllegalConversionException";
-
-}
-
-IllegalConversionException::IllegalConversionException(const char* file, int line) :
- ::IceUtil::Exception(file, line)
-{
-}
-
-IllegalConversionException::IllegalConversionException(const char* file, int line, const string& reason) :
- ::IceUtil::Exception(file, line),
- _reason(reason)
-{
-}
-
-IllegalConversionException::~IllegalConversionException() throw()
-{
-}
-
-string
-IllegalConversionException::ice_name() const
-{
- return __IceUtil__IllegalConversionException_name;
-}
-
-void
-IllegalConversionException::ice_print(ostream& out) const
-{
- Exception::ice_print(out);
- out << ": " << _reason;
-}
-
-IceUtil::IllegalConversionException*
-IllegalConversionException::ice_clone() const
-{
- return new IllegalConversionException(*this);
-}
-
-void
-IllegalConversionException::ice_throw() const
-{
- throw *this;
-}
-
-string
-IllegalConversionException::reason() const
-{
- return _reason;
}
@@ -197,7 +150,8 @@ IceUtil::UTF8ToNative(const IceUtil::StringConverterPtr& converter, const string
}
string
-IceUtil::wnativeToNative(const StringConverterPtr& converter, const WstringConverterPtr& wConverter, const wstring& v)
+IceUtil::wstringToString(const wstring& v, const StringConverterPtr& converter, const WstringConverterPtr& wConverter,
+ IceUtil::ConversionFlags flags)
{
string target;
if(!v.empty())
@@ -224,14 +178,14 @@ IceUtil::wnativeToNative(const StringConverterPtr& converter, const WstringConve
ConversionResult cr =
convertUTFWstringToUTF8(
sourceStart, sourceStart + v.size(),
- targetStart, targetEnd, lenientConversion);
+ targetStart, targetEnd, flags);
if(cr != conversionOK)
{
delete[] outBuf;
assert(cr == sourceExhausted || cr == sourceIllegal);
- throw UTFConversionException(__FILE__, __LINE__,
- cr == sourceExhausted ? partialCharacter : badEncoding);
+ throw IllegalConversionException(__FILE__, __LINE__,
+ cr == sourceExhausted ? "partial character" : "bad encoding");
}
target = string(reinterpret_cast<char*>(outBuf), static_cast<size_t>(targetStart - outBuf));
@@ -254,7 +208,8 @@ IceUtil::wnativeToNative(const StringConverterPtr& converter, const WstringConve
}
wstring
-IceUtil::nativeToWnative(const StringConverterPtr& converter, const WstringConverterPtr& wConverter, const string& v)
+IceUtil::stringToWstring(const string& v, const StringConverterPtr& converter,
+ const WstringConverterPtr& wConverter, IceUtil::ConversionFlags flags)
{
wstring target;
if(!v.empty())
@@ -288,14 +243,14 @@ IceUtil::nativeToWnative(const StringConverterPtr& converter, const WstringConve
const Byte* sourceStart = reinterpret_cast<const Byte*>(tmp.data());
ConversionResult cr =
- convertUTF8ToUTFWstring(sourceStart, sourceStart + tmp.size(), target, lenientConversion);
+ convertUTF8ToUTFWstring(sourceStart, sourceStart + tmp.size(), target, flags);
if(cr != conversionOK)
{
assert(cr == sourceExhausted || cr == sourceIllegal);
- throw UTFConversionException(__FILE__, __LINE__,
- cr == sourceExhausted ? partialCharacter : badEncoding);
+ throw IllegalConversionException(__FILE__, __LINE__,
+ cr == sourceExhausted ? "partial character" : "bad encoding");
}
}
}
diff --git a/cpp/src/IceUtil/StringUtil.cpp b/cpp/src/IceUtil/StringUtil.cpp
index 16d7c9f18bf..e8b234f91e3 100644
--- a/cpp/src/IceUtil/StringUtil.cpp
+++ b/cpp/src/IceUtil/StringUtil.cpp
@@ -575,7 +575,7 @@ IceUtilInternal::errorToString(int error, LPCVOID source)
LocalFree(msg);
}
#endif
- return wnativeToNative(getProcessStringConverter(), getProcessWstringConverter(), result);
+ return wstringToString(result, getProcessStringConverter(), getProcessWstringConverter());
}
else
{
diff --git a/cpp/src/IceUtil/Unicode.cpp b/cpp/src/IceUtil/Unicode.cpp
index 14da4fb3b5a..ad6e2e659bd 100644
--- a/cpp/src/IceUtil/Unicode.cpp
+++ b/cpp/src/IceUtil/Unicode.cpp
@@ -129,110 +129,3 @@ IceUtilInternal::convertUTF8ToUTFWstring(const Byte*& sourceStart, const Byte* s
}
-//
-// wstringToString and stringToWstring
-//
-
-const char* IceUtil::UTFConversionException::_name = "IceUtil::UTFConversionException";
-
-IceUtil::UTFConversionException::UTFConversionException(const char* file, int line,
- ConversionError ce):
- Exception(file, line),
- _conversionError(ce)
-{}
-
-string
-IceUtil::UTFConversionException::ice_name() const
-{
- return _name;
-}
-
-void
-IceUtil::UTFConversionException::ice_print(ostream& os) const
-{
- Exception::ice_print(os);
- switch(_conversionError)
- {
- case partialCharacter:
- os << ": partial character";
- break;
- case badEncoding:
- os << ": bad encoding";
- break;
- default:
- assert(0);
- break;
- };
-}
-
-IceUtil::UTFConversionException*
-IceUtil::UTFConversionException::ice_clone() const
-{
- return new UTFConversionException(*this);
-}
-
-void
-IceUtil::UTFConversionException::ice_throw() const
-{
- throw *this;
-}
-
-IceUtil::ConversionError
-IceUtil::UTFConversionException::conversionError() const
-{
- return _conversionError;
-}
-
-
-string
-IceUtil::wstringToString(const wstring& wstr, ConversionFlags flags)
-{
- string target;
-
- size_t size = wstr.size() * 3 * (sizeof(wchar_t) / 2);
-
- Byte* outBuf = new Byte[size];
- Byte* targetStart = outBuf;
- Byte* targetEnd = outBuf + size;
-
- const wchar_t* sourceStart = wstr.data();
-
- ConversionResult cr =
- convertUTFWstringToUTF8(
- sourceStart, sourceStart + wstr.size(),
- targetStart, targetEnd, flags);
-
- if(cr != conversionOK)
- {
- delete[] outBuf;
- assert(cr == sourceExhausted || cr == sourceIllegal);
- throw UTFConversionException(__FILE__, __LINE__,
- cr == sourceExhausted ? partialCharacter : badEncoding);
- }
-
- string s(reinterpret_cast<char*>(outBuf),
- static_cast<size_t>(targetStart - outBuf));
- s.swap(target);
- delete[] outBuf;
- return target;
-}
-
-wstring
-IceUtil::stringToWstring(const string& str, ConversionFlags flags)
-{
- wstring result;
- const Byte* sourceStart = reinterpret_cast<const Byte*>(str.data());
-
- ConversionResult cr
- = convertUTF8ToUTFWstring(sourceStart, sourceStart + str.size(),
- result, flags);
-
- if(cr != conversionOK)
- {
- assert(cr == sourceExhausted || cr == sourceIllegal);
-
- throw UTFConversionException(__FILE__, __LINE__,
- cr == sourceExhausted ? partialCharacter : badEncoding);
- }
- return result;
-}