diff options
Diffstat (limited to 'cpp/include')
-rw-r--r-- | cpp/include/Ice/BasicStream.h | 13 | ||||
-rw-r--r-- | cpp/include/Ice/DynamicLibrary.h | 4 | ||||
-rw-r--r-- | cpp/include/Ice/Ice.h | 3 | ||||
-rw-r--r-- | cpp/include/Ice/Initialize.h | 12 | ||||
-rw-r--r-- | cpp/include/Ice/StringConverter.h | 161 | ||||
-rw-r--r-- | cpp/include/IceUtil/Exception.h | 21 | ||||
-rw-r--r-- | cpp/include/IceUtil/FileUtil.h | 1 | ||||
-rw-r--r-- | cpp/include/IceUtil/IceUtil.h | 4 | ||||
-rw-r--r-- | cpp/include/IceUtil/IconvStringConverter.h (renamed from cpp/include/Ice/IconvStringConverter.h) | 139 | ||||
-rw-r--r-- | cpp/include/IceUtil/StringConverter.h | 193 | ||||
-rw-r--r-- | cpp/include/IceUtil/UndefSysMacros.h (renamed from cpp/include/Ice/UndefSysMacros.h) | 4 | ||||
-rw-r--r-- | cpp/include/IceUtil/Unicode.h | 7 |
12 files changed, 266 insertions, 296 deletions
diff --git a/cpp/include/Ice/BasicStream.h b/cpp/include/Ice/BasicStream.h index 3f546fd52a8..bd18dbf7b8a 100644 --- a/cpp/include/Ice/BasicStream.h +++ b/cpp/include/Ice/BasicStream.h @@ -10,6 +10,7 @@ #ifndef ICE_BASIC_STREAM_H #define ICE_BASIC_STREAM_H +#include <IceUtil/StringConverter.h> #include <Ice/InstanceF.h> #include <Ice/Object.h> #include <Ice/ProxyF.h> @@ -27,14 +28,6 @@ namespace Ice class UserException; -template<typename charT> class BasicStringConverter; - -typedef BasicStringConverter<char> StringConverter; -typedef IceUtil::Handle<StringConverter> StringConverterPtr; - -typedef BasicStringConverter<wchar_t> WstringConverter; -typedef IceUtil::Handle<WstringConverter> WstringConverterPtr; - } namespace IceInternal @@ -1244,8 +1237,8 @@ private: const Container::size_type _messageSizeMax; bool _unlimited; - const Ice::StringConverterPtr& _stringConverter; - const Ice::WstringConverterPtr& _wstringConverter; + const IceUtil::StringConverterPtr _stringConverter; + const IceUtil::WstringConverterPtr _wstringConverter; int _startSeq; int _minSeqSize; diff --git a/cpp/include/Ice/DynamicLibrary.h b/cpp/include/Ice/DynamicLibrary.h index 093870759aa..09e5956d93c 100644 --- a/cpp/include/Ice/DynamicLibrary.h +++ b/cpp/include/Ice/DynamicLibrary.h @@ -11,7 +11,6 @@ #define ICE_DYNAMIC_LIBRARY_H #include <Ice/DynamicLibraryF.h> -#include <Ice/StringConverter.h> #include <IceUtil/Shared.h> namespace IceInternal @@ -21,7 +20,7 @@ class ICE_API DynamicLibrary : public ::IceUtil::Shared { public: - DynamicLibrary(const Ice::StringConverterPtr&); + DynamicLibrary(); ~DynamicLibrary(); #ifdef _WIN32 @@ -88,7 +87,6 @@ private: void* _hnd; #endif std::string _err; - const Ice::StringConverterPtr _stringConverter; }; class ICE_API DynamicLibraryList : public ::IceUtil::Shared diff --git a/cpp/include/Ice/Ice.h b/cpp/include/Ice/Ice.h index 2c66ed00022..ffb233b40de 100644 --- a/cpp/include/Ice/Ice.h +++ b/cpp/include/Ice/Ice.h @@ -47,8 +47,5 @@ #ifndef ICE_OS_WINRT # include <Ice/Service.h> #endif -#ifndef _WIN32 -# include <Ice/IconvStringConverter.h> -#endif #endif diff --git a/cpp/include/Ice/Initialize.h b/cpp/include/Ice/Initialize.h index 0424731bc37..1422e0552e5 100644 --- a/cpp/include/Ice/Initialize.h +++ b/cpp/include/Ice/Initialize.h @@ -18,10 +18,10 @@ #include <Ice/StatsF.h> #include <Ice/InstrumentationF.h> #include <Ice/Dispatcher.h> -#include <Ice/StringConverter.h> #include <Ice/FactoryTable.h> #include <Ice/BuiltinSequences.h> #include <Ice/Version.h> +#include <Ice/Plugin.h> namespace Ice { @@ -34,8 +34,6 @@ ICE_API StringSeq argsToStringSeq(int, char*[]); ICE_API StringSeq argsToStringSeq(int, wchar_t*[]); -ICE_API StringSeq argsToStringSeq(int, wchar_t*[], const StringConverterPtr&); - #endif // @@ -46,9 +44,9 @@ ICE_API StringSeq argsToStringSeq(int, wchar_t*[], const StringConverterPtr&); // ICE_API void stringSeqToArgs(const StringSeq&, int&, char*[]); -ICE_API PropertiesPtr createProperties(const StringConverterPtr& = 0); -ICE_API PropertiesPtr createProperties(StringSeq&, const PropertiesPtr& = 0, const StringConverterPtr& = 0); -ICE_API PropertiesPtr createProperties(int&, char*[], const PropertiesPtr& = 0, const StringConverterPtr& = 0); +ICE_API PropertiesPtr createProperties(); +ICE_API PropertiesPtr createProperties(StringSeq&, const PropertiesPtr& = 0); +ICE_API PropertiesPtr createProperties(int&, char*[], const PropertiesPtr& = 0); // // This class is used to notify user of when Ice threads are started @@ -88,8 +86,6 @@ struct InitializationData LoggerPtr logger; StatsPtr stats; Instrumentation::CommunicatorObserverPtr observer; - StringConverterPtr stringConverter; - WstringConverterPtr wstringConverter; ThreadNotificationPtr threadHook; DispatcherPtr dispatcher; CompactIdResolverPtr compactIdResolver; diff --git a/cpp/include/Ice/StringConverter.h b/cpp/include/Ice/StringConverter.h deleted file mode 100644 index 90b302cbad8..00000000000 --- a/cpp/include/Ice/StringConverter.h +++ /dev/null @@ -1,161 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#ifndef ICE_STRING_CONVERTER_H -#define ICE_STRING_CONVERTER_H - -#include <Ice/Config.h> -#include <Ice/CommunicatorF.h> -#include <Ice/Plugin.h> -#include <IceUtil/Exception.h> -#include <IceUtil/Shared.h> -#include <IceUtil/Handle.h> -#include <IceUtil/Unicode.h> - -#include <string> - -namespace Ice -{ - -// -// Provides bytes to toUTF8. Raises MemoryLimitException when too many -// bytes are requested. -// -class ICE_API UTF8Buffer -{ -public: - virtual Byte* getMoreBytes(size_t howMany, Byte* firstUnused) = 0; - - virtual ~UTF8Buffer() {} -}; - -// -// A StringConverter converts narrow or wide-strings to and from UTF-8 byte sequences. -// It's used by the communicator during marshaling (toUTF8) and unmarshaling (fromUTF8). -// It report errors by raising StringConversionFailed or MemoryLimitException. -// -template<typename charT> -class BasicStringConverter : public IceUtil::Shared -{ -public: - - // - // Returns a pointer to byte after the last written byte (which may be - // past the last byte returned by getMoreBytes). - // - virtual Byte* toUTF8(const charT* sourceStart, const charT* sourceEnd, - UTF8Buffer&) const = 0; - - // - // Unmarshals a UTF-8 sequence into a basic_string - // - virtual void fromUTF8(const Byte* sourceStart, const Byte* sourceEnd, - std::basic_string<charT>& target) const = 0; -}; - -typedef BasicStringConverter<char> StringConverter; -typedef IceUtil::Handle<StringConverter> StringConverterPtr; - -typedef BasicStringConverter<wchar_t> WstringConverter; -typedef IceUtil::Handle<WstringConverter> WstringConverterPtr; - - -// -// Converts to and from UTF-16 or UTF-32 depending on sizeof(wchar_t) -// -class ICE_API UnicodeWstringConverter : public WstringConverter -{ -public: - - UnicodeWstringConverter(IceUtil::ConversionFlags = IceUtil::lenientConversion); - - virtual Byte* toUTF8(const wchar_t*, const wchar_t*, UTF8Buffer&) const; - - virtual void fromUTF8(const Byte*, const Byte*, std::wstring&) const; - -private: - const IceUtil::ConversionFlags _conversionFlags; -}; - -#ifdef _WIN32 - -// -// Converts to/from UTF-8 using MultiByteToWideChar and WideCharToMultiByte -// - -class ICE_API WindowsStringConverter : public StringConverter -{ -public: - - explicit WindowsStringConverter(unsigned int); - - virtual Byte* toUTF8(const char*, const char*, UTF8Buffer&) const; - - virtual void fromUTF8(const Byte*, const Byte*, std::string& target) const; - -private: - unsigned int _cp; - UnicodeWstringConverter _unicodeWstringConverter; -}; -#endif - - -// -// A special plug-in that sets stringConverter and wstringConverter during -// construction (when the provided stringConverter resp. wstringConverter -// are not null). Both initialize and destroy are no-op. See Ice::InitializationData. -// - -class ICE_API StringConverterPlugin : public Ice::Plugin -{ -public: - - StringConverterPlugin(const CommunicatorPtr& communicator, - const StringConverterPtr&, const WstringConverterPtr& = 0); - - virtual void initialize(); - - virtual void destroy(); -}; - -// -// Converts the given string from the native narrow string encoding to -// UTF8 using the given converter. If the converter is null, returns -// the given string. -// -ICE_API std::string -nativeToUTF8(const Ice::StringConverterPtr&, const std::string&); - -// -// Converts the given string from the native narrow string encoding to -// UTF8 using the communicator's converter. If the converter is null, -// returns the given string. -// -ICE_API std::string -nativeToUTF8(const Ice::CommunicatorPtr&, const std::string&); - -// -// Converts the given string from UTF8 to the native narrow string -// encoding using the given converter. If the converter is null, -// returns the given string. -// -ICE_API std::string -UTF8ToNative(const Ice::StringConverterPtr&, const std::string&); - -// -// Converts the given string from UTF8 to the native narrow string -// encoding using the communicator's converter. If the converter is -// null, returns the given string. -// -ICE_API std::string -UTF8ToNative(const Ice::CommunicatorPtr&, const std::string&); - -} - -#endif diff --git a/cpp/include/IceUtil/Exception.h b/cpp/include/IceUtil/Exception.h index 2709b64ee31..b3dca7824d5 100644 --- a/cpp/include/IceUtil/Exception.h +++ b/cpp/include/IceUtil/Exception.h @@ -135,6 +135,27 @@ private: static const char* _name; }; +#ifndef _WIN32 +class ICE_UTIL_API IconvInitializationException : public Exception +{ +public: + + IconvInitializationException(const char*, int, const std::string&); + virtual ~IconvInitializationException() throw(); + virtual std::string ice_name() const; + virtual void ice_print(std::ostream&) const; + virtual IconvInitializationException* ice_clone() const; + virtual void ice_throw() const; + + std::string reason() const; + +private: + + static const char* _name; + std::string _reason; +}; +#endif + } #endif diff --git a/cpp/include/IceUtil/FileUtil.h b/cpp/include/IceUtil/FileUtil.h index 7cb2cd55407..7fabce927b9 100644 --- a/cpp/include/IceUtil/FileUtil.h +++ b/cpp/include/IceUtil/FileUtil.h @@ -70,6 +70,7 @@ ICE_UTIL_API int rmdir(const std::string&); ICE_UTIL_API int mkdir(const std::string&, int); ICE_UTIL_API FILE* fopen(const std::string&, const std::string&); +ICE_UTIL_API FILE* freopen(const std::string&, const std::string&, FILE*); ICE_UTIL_API int open(const std::string&, int); #ifndef ICE_OS_WINRT diff --git a/cpp/include/IceUtil/IceUtil.h b/cpp/include/IceUtil/IceUtil.h index cba2207c079..b5e126a34c2 100644 --- a/cpp/include/IceUtil/IceUtil.h +++ b/cpp/include/IceUtil/IceUtil.h @@ -41,4 +41,8 @@ #include <IceUtil/Unicode.h> #include <IceUtil/UniquePtr.h> +#ifndef _WIN32 +# include <IceUtil/IconvStringConverter.h> +#endif + #endif diff --git a/cpp/include/Ice/IconvStringConverter.h b/cpp/include/IceUtil/IconvStringConverter.h index 23c683bf78a..e6bef3c6d82 100644 --- a/cpp/include/Ice/IconvStringConverter.h +++ b/cpp/include/IceUtil/IconvStringConverter.h @@ -7,18 +7,16 @@ // // ********************************************************************** -#ifndef ICE_ICONV_STRING_CONVERTER -#define ICE_ICONV_STRING_CONVERTER +#ifndef ICE_UTIL_ICONV_STRING_CONVERTER +#define ICE_UTIL_ICONV_STRING_CONVERTER -#include <Ice/StringConverter.h> -#include <Ice/UndefSysMacros.h> +#include <IceUtil/StringConverter.h> +#include <IceUtil/UndefSysMacros.h> #include <algorithm> #include <iconv.h> - -#ifndef _WIN32 #include <langinfo.h> -#endif +#include <string.h> // For strerror #if (defined(__APPLE__) && _LIBICONV_VERSION < 0x010B) || defined(__FreeBSD__) // @@ -27,14 +25,7 @@ # define ICE_CONST_ICONV_INBUF 1 #endif -// -// On Windows, we need to be very careful with errno: if we use different C -// runtime libraries for the main program and the libiconv DLL, we end up with -// two different errnos ... a not-so-good work-around is to ignore errno -// altogether, by defining ICE_NO_ERRNO -// - -namespace Ice +namespace IceUtil { // @@ -45,21 +36,17 @@ namespace Ice // // template<typename charT> -class IconvStringConverter : public Ice::BasicStringConverter<charT> +class IconvStringConverter : public BasicStringConverter<charT> { public: -#ifdef _WIN32 - IconvStringConverter(const char*); -#else IconvStringConverter(const char* = nl_langinfo(CODESET)); -#endif virtual ~IconvStringConverter(); - virtual Ice::Byte* toUTF8(const charT*, const charT*, Ice::UTF8Buffer&) const; + virtual Byte* toUTF8(const charT*, const charT*, UTF8Buffer&) const; - virtual void fromUTF8(const Ice::Byte*, const Ice::Byte*, std::basic_string<charT>&) const; + virtual void fromUTF8(const Byte*, const Byte*, std::basic_string<charT>&) const; private: @@ -69,11 +56,7 @@ private: static void cleanupKey(void*); static void close(std::pair<iconv_t, iconv_t>); -#ifdef _WIN32 - DWORD _key; -#else mutable pthread_key_t _key; -#endif const std::string _internalCode; }; @@ -99,48 +82,29 @@ IconvStringConverter<charT>::IconvStringConverter(const char* internalCode) : { close(createDescriptors()); } - catch(const Ice::StringConversionException& sce) + catch(const IllegalConversionException& sce) { - throw Ice::InitializationException(__FILE__, __LINE__, sce.reason); + throw IconvInitializationException(__FILE__, __LINE__, sce.reason()); } // // Create thread-specific key // -#ifdef _WIN32 - _key = TlsAlloc(); - if(_key == TLS_OUT_OF_INDEXES) - { - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } -#else - #ifdef __SUNPRO_CC +#ifdef __SUNPRO_CC int rs = pthread_key_create(&_key, reinterpret_cast<IcePthreadKeyDestructor>(&cleanupKey)); - #else +#else int rs = pthread_key_create(&_key, &cleanupKey); - #endif +#endif if(rs != 0) { - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, rs); + throw ThreadSyscallException(__FILE__, __LINE__, rs); } -#endif } template<typename charT> IconvStringConverter<charT>::~IconvStringConverter() { -#ifdef _WIN32 - void* val = TlsGetValue(_key); - if(val != 0) - { - cleanupKey(val); - } - if(TlsFree(_key) == 0) - { - assert(0); - } -#else void* val = pthread_getspecific(_key); if(val != 0) { @@ -150,7 +114,6 @@ IconvStringConverter<charT>::~IconvStringConverter() { assert(0); } -#endif } template<typename charT> std::pair<iconv_t, iconv_t> @@ -163,20 +126,18 @@ IconvStringConverter<charT>::createDescriptors() const cdp.first = iconv_open(_internalCode.c_str(), externalCode); if(cdp.first == iconv_t(-1)) { - throw Ice::StringConversionException( - __FILE__, __LINE__, - std::string("iconv cannot convert from ") - + externalCode + " to " + _internalCode); + std::ostringstream os; + os << "iconv cannot convert from " << externalCode << " to " << _internalCode; + throw IllegalConversionException(__FILE__, __LINE__, os.str()); } cdp.second = iconv_open(externalCode, _internalCode.c_str()); if(cdp.second == iconv_t(-1)) { iconv_close(cdp.first); - - throw Ice::StringConversionException( - __FILE__, __LINE__, - std::string("iconv cannot convert from ") + _internalCode + " to " + externalCode); + std::ostringstream os; + os << "iconv cannot convert from " << _internalCode << " to " << externalCode; + throw IllegalConversionException(__FILE__, __LINE__, os.str()); } return cdp; } @@ -184,11 +145,7 @@ IconvStringConverter<charT>::createDescriptors() const template<typename charT> std::pair<iconv_t, iconv_t> IconvStringConverter<charT>::getDescriptors() const { -#ifdef _WIN32 - void* val = TlsGetValue(_key); -#else void* val = pthread_getspecific(_key); -#endif if(val != 0) { return *static_cast<std::pair<iconv_t, iconv_t>*>(val); @@ -196,19 +153,11 @@ IconvStringConverter<charT>::getDescriptors() const else { std::pair<iconv_t, iconv_t> cdp = createDescriptors(); - -#ifdef _WIN32 - if(TlsSetValue(_key, new std::pair<iconv_t, iconv_t>(cdp)) == 0) - { - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } -#else int rs = pthread_setspecific(_key, new std::pair<iconv_t, iconv_t>(cdp)); if(rs != 0) { - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, rs); + throw ThreadSyscallException(__FILE__, __LINE__, rs); } -#endif return cdp; } } @@ -237,8 +186,8 @@ IconvStringConverter<charT>::close(std::pair<iconv_t, iconv_t> cdp) #endif } -template<typename charT> Ice::Byte* -IconvStringConverter<charT>::toUTF8(const charT* sourceStart, const charT* sourceEnd, Ice::UTF8Buffer& buf) const +template<typename charT> Byte* +IconvStringConverter<charT>::toUTF8(const charT* sourceStart, const charT* sourceEnd, UTF8Buffer& buf) const { iconv_t cd = getDescriptors().second; @@ -267,30 +216,19 @@ IconvStringConverter<charT>::toUTF8(const charT* sourceStart, const charT* sourc do { size_t howMany = std::max(inbytesleft, size_t(4)); - outbuf = reinterpret_cast<char*>(buf.getMoreBytes(howMany, reinterpret_cast<Ice::Byte*>(outbuf))); + outbuf = reinterpret_cast<char*>(buf.getMoreBytes(howMany, reinterpret_cast<Byte*>(outbuf))); count = iconv(cd, &inbuf, &inbytesleft, &outbuf, &howMany); -#ifdef ICE_NO_ERRNO - } while(count == size_t(-1)); -#else } while(count == size_t(-1) && errno == E2BIG); -#endif if(count == size_t(-1)) { - std::string msg = "Unknown error"; -#ifndef ICE_NO_ERRNO - if(errno != 0) - { - msg = strerror(errno); - } -#endif - throw Ice::StringConversionException(__FILE__, __LINE__, msg); + throw IllegalConversionException(__FILE__, __LINE__, errno != 0 ? strerror(errno) : "Unknown error"); } - return reinterpret_cast<Ice::Byte*>(outbuf); + return reinterpret_cast<Byte*>(outbuf); } template<typename charT> void -IconvStringConverter<charT>::fromUTF8(const Ice::Byte* sourceStart, const Ice::Byte* sourceEnd, +IconvStringConverter<charT>::fromUTF8(const Byte* sourceStart, const Byte* sourceEnd, std::basic_string<charT>& target) const { iconv_t cd = getDescriptors().first; @@ -308,7 +246,7 @@ IconvStringConverter<charT>::fromUTF8(const Ice::Byte* sourceStart, const Ice::B #ifdef ICE_CONST_ICONV_INBUF const char* inbuf = reinterpret_cast<const char*>(sourceStart); #else - char* inbuf = reinterpret_cast<char*>(const_cast<Ice::Byte*>(sourceStart)); + char* inbuf = reinterpret_cast<char*>(const_cast<Byte*>(sourceStart)); #endif size_t inbytesleft = sourceEnd - sourceStart; @@ -329,15 +267,13 @@ IconvStringConverter<charT>::fromUTF8(const Ice::Byte* sourceStart, const Ice::B do { size_t increment = std::max(inbytesleft * sizeof(wchar_t), size_t(8)); - bufsize += increment; - + bufsize += increment; char* newbuf = static_cast<char*>(realloc(buf, bufsize)); if(newbuf == 0) { free(buf); - throw Ice::StringConversionException( - __FILE__, __LINE__, "Out of memory"); + throw IllegalConversionException(__FILE__, __LINE__, "Out of memory"); } outbuf = newbuf + (outbuf - buf); @@ -346,23 +282,12 @@ IconvStringConverter<charT>::fromUTF8(const Ice::Byte* sourceStart, const Ice::B buf = newbuf; count = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); -#ifdef ICE_NO_ERRNO - } while(count == size_t(-1)); -#else } while(count == size_t(-1) && errno == E2BIG); -#endif if(count == size_t(-1)) { - std::string msg = "Unknown error"; -#ifndef ICE_NO_ERRNO - if(errno != 0) - { - msg = strerror(errno); - } -#endif free(buf); - throw Ice::StringConversionException(__FILE__, __LINE__, msg); + throw IllegalConversionException(__FILE__, __LINE__, errno != 0 ? strerror(errno) : "Unknown error"); } size_t length = (bufsize - outbytesleft) / sizeof(charT); diff --git a/cpp/include/IceUtil/StringConverter.h b/cpp/include/IceUtil/StringConverter.h new file mode 100644 index 00000000000..b3e8d62f2b7 --- /dev/null +++ b/cpp/include/IceUtil/StringConverter.h @@ -0,0 +1,193 @@ +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef ICE_UTIL_STRING_CONVERTER_H +#define ICE_UTIL_STRING_CONVERTER_H + +#include <IceUtil/Config.h> +#include <IceUtil/Exception.h> +#include <IceUtil/Shared.h> +#include <IceUtil/Handle.h> +#include <IceUtil/Unicode.h> + +#include <string> + +namespace IceUtil +{ + +// +// Raised by string converters when an encoding converseion fails. +// +class ICE_UTIL_API IllegalConversionException : public ::IceUtil::Exception +{ +public: + + IllegalConversionException(const char*, int); + IllegalConversionException(const char*, int, const ::std::string&); + virtual ~IllegalConversionException() throw(); + + virtual ::std::string ice_name() const; + virtual void ice_print(::std::ostream&) const; + virtual IllegalConversionException* ice_clone() const; + virtual void ice_throw() const; + + std::string reason() const; + +private: + + std::string _reason; +}; + +// +// Provides bytes to toUTF8. Raises MemoryLimitException when too many +// bytes are requested. +// +class ICE_UTIL_API UTF8Buffer +{ +public: + virtual Byte* getMoreBytes(size_t howMany, Byte* firstUnused) = 0; + + virtual ~UTF8Buffer() {} +}; + +// +// A StringConverter converts narrow or wide-strings to and from UTF-8 byte sequences. +// It's used by the communicator during marshaling (toUTF8) and unmarshaling (fromUTF8). +// It report errors by raising IllegalConversionException or MemoryLimitException. +// +template<typename charT> +class BasicStringConverter : public IceUtil::Shared +{ +public: + // + // Returns a pointer to byte after the last written byte (which may be + // past the last byte returned by getMoreBytes). + // + virtual Byte* toUTF8(const charT* sourceStart, const charT* sourceEnd, + UTF8Buffer&) const = 0; + + // + // Unmarshals a UTF-8 sequence into a basic_string + // + virtual void fromUTF8(const Byte* sourceStart, const Byte* sourceEnd, + std::basic_string<charT>& target) const = 0; +}; + +typedef BasicStringConverter<char> StringConverter; +typedef IceUtil::Handle<StringConverter> StringConverterPtr; + +typedef BasicStringConverter<wchar_t> WstringConverter; +typedef IceUtil::Handle<WstringConverter> WstringConverterPtr; + +// +// Converts to and from UTF-16 or UTF-32 depending on sizeof(wchar_t) +// +class ICE_UTIL_API UnicodeWstringConverter : public WstringConverter +{ +public: + + UnicodeWstringConverter(ConversionFlags = lenientConversion); + + virtual Byte* toUTF8(const wchar_t*, const wchar_t*, UTF8Buffer&) const; + + virtual void fromUTF8(const Byte*, const Byte*, std::wstring&) const; + +private: + const ConversionFlags _conversionFlags; +}; + +#ifdef _WIN32 + +// +// Converts to/from UTF-8 using MultiByteToWideChar and WideCharToMultiByte +// +class ICE_UTIL_API WindowsStringConverter : public StringConverter +{ +public: + + explicit WindowsStringConverter(unsigned int); + + virtual Byte* toUTF8(const char*, const char*, UTF8Buffer&) const; + + virtual void fromUTF8(const Byte*, const Byte*, std::string& target) const; + +private: + unsigned int _cp; + UnicodeWstringConverter _unicodeWstringConverter; +}; +#endif + +// +// Retrive the per process narrow string converter. Access to the +// converter is protected by a static mutex. +// +ICE_UTIL_API StringConverterPtr getProcessStringConverter(); + +// +// Set the per process narrow string converter. Access to the +// converter is protected by a static mutex. +// +ICE_UTIL_API void setProcessStringConverter(const StringConverterPtr&); + +// +// Retrive the per process wide string converter. Access to the +// converter is protected by a static mutex. +// +ICE_UTIL_API WstringConverterPtr getProcessWstringConverter(); + +// +// Set the per process wide string converter. Access to the +// converter is protected by a static mutex. +// +ICE_UTIL_API void setProcessWstringConverter(const WstringConverterPtr&); + +// +// Convert the given wide string from the native wide string encoding to a +// narrow string with the native narrow string encoding. +// +// The StringConverter param can be null in that case the default narrow +// string encoding is assumed to be UTF8. +// +// The WstringConverter param can be null in that case the default wide +// string encoding is assumed, that would be UTF16 or UTF32 depending of +// the platform. +// +ICE_UTIL_API std::string +wnativeToNative(const StringConverterPtr&, const WstringConverterPtr&, const std::wstring&); + +// +// Convert the given narrow string from the native narrow string encoding +// to a wide string with the native wide string encoding. +// +// The StringConverter param can be null in that case the default narrow +// string encoding is assumed to be UTF8. +// +// The WstringConverter param can be null in that case the default wide +// string encoding is assumed, that would be UTF16 or UTF32 depending of +// the platform. +// +ICE_UTIL_API std::wstring +nativeToWnative(const StringConverterPtr&, const WstringConverterPtr&, const std::string&); + +// +// Converts the given string from the native narrow string encoding to +// UTF8 using the given converter. If the converter is null, returns +// the given string. +// +ICE_UTIL_API std::string +nativeToUTF8(const StringConverterPtr&, const std::string&); + +// +// Converts the given string from UTF8 to the native narrow string +// encoding using the given converter. If the converter is null, +// returns the given string. +// +ICE_UTIL_API std::string +UTF8ToNative(const StringConverterPtr&, const std::string&); + +} + +#endif diff --git a/cpp/include/Ice/UndefSysMacros.h b/cpp/include/IceUtil/UndefSysMacros.h index d135180f1b7..2dc931daf08 100644 --- a/cpp/include/Ice/UndefSysMacros.h +++ b/cpp/include/IceUtil/UndefSysMacros.h @@ -7,8 +7,8 @@ // // ********************************************************************** -#ifndef ICE_UNDEF_SYS_MACROS_H -#define ICE_UNDEF_SYS_MACROS_H +#ifndef ICE_UTIL_UNDEF_SYS_MACROS_H +#define ICE_UTIL_UNDEF_SYS_MACROS_H // // This header includes macros that can end up being dragged into diff --git a/cpp/include/IceUtil/Unicode.h b/cpp/include/IceUtil/Unicode.h index 40f002fa545..71a52b3e62f 100644 --- a/cpp/include/IceUtil/Unicode.h +++ b/cpp/include/IceUtil/Unicode.h @@ -22,8 +22,11 @@ enum ConversionFlags lenientConversion }; -ICE_UTIL_API std::string wstringToString(const std::wstring&, ConversionFlags = lenientConversion); -ICE_UTIL_API std::wstring stringToWstring(const std::string&, ConversionFlags = lenientConversion); +ICE_DEPRECATED_API std::string +wstringToString(const std::wstring&, ConversionFlags = lenientConversion); + +ICE_DEPRECATED_API std::wstring +stringToWstring(const std::string&, ConversionFlags = lenientConversion); typedef unsigned char Byte; |