Ice 3.7 C++11 API Reference
StringConverter.h
Go to the documentation of this file.
1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 #ifndef ICE_UTIL_STRING_CONVERTER_H
6 #define ICE_UTIL_STRING_CONVERTER_H
7 
8 #include <IceUtil/Config.h>
9 #include <IceUtil/Exception.h>
10 #include <IceUtil/Shared.h>
11 #include <IceUtil/Handle.h>
12 
13 #include <string>
14 
15 namespace IceUtil
16 {
17 
24 {
25 public:
26 
33  virtual Byte* getMoreBytes(size_t howMany, Byte* firstUnused) = 0;
34 
35  virtual ~UTF8Buffer();
36 };
37 
45 template<typename charT>
47 #ifndef ICE_CPP11_MAPPING
48  : public IceUtil::Shared
49 #endif
50 {
51 public:
52 
57  virtual Byte* toUTF8(const charT* sourceStart, const charT* sourceEnd, UTF8Buffer& buf) const = 0;
58 
62  virtual void fromUTF8(const Byte* sourceStart, const Byte* sourceEnd, std::basic_string<charT>& target) const = 0;
63 
65  {
66  }
67 };
68 
69 #if defined(__clang__) && !defined(ICE_STATIC_LIBS)
70 //
71 // Explicit template instantiation so that dynamic_cast of derived exported
72 // classes works well with clang, see ICE-7473.
73 //
74 template class ICE_API BasicStringConverter<char>;
75 template class ICE_API BasicStringConverter<wchar_t>;
76 #endif
77 
81 
85 
91 
97 
103 
109 
115 
124 ICE_API std::string
125 wstringToString(const std::wstring& str,
126  const StringConverterPtr& nc = 0,
127  const WstringConverterPtr& wc = 0);
128 
137 ICE_API std::wstring
138 stringToWstring(const std::string& str,
139  const StringConverterPtr& nc = 0,
140  const WstringConverterPtr& wc = 0);
141 
149 ICE_API std::string
150 nativeToUTF8(const std::string& str, const StringConverterPtr& nc);
151 
159 ICE_API std::string
160 UTF8ToNative(const std::string& str, const StringConverterPtr& nc);
161 
162 }
163 
164 namespace IceUtilInternal
165 {
166 
167 //
168 // Convert from UTF-8 to UTF-16/32
169 //
170 ICE_API std::vector<unsigned short> toUTF16(const std::vector<IceUtil::Byte>&);
171 ICE_API std::vector<unsigned int> toUTF32(const std::vector<IceUtil::Byte>&);
172 
173 //
174 // Convert from UTF-32 to UTF-8
175 //
176 ICE_API std::vector<IceUtil::Byte> fromUTF32(const std::vector<unsigned int>&);
177 
178 }
179 
180 #ifdef _WIN32
181 namespace IceUtil
182 {
183 
190 ICE_API StringConverterPtr createWindowsStringConverter(unsigned int page);
191 
192 }
193 #endif
194 
195 #endif
IceUtil::getProcessWstringConverter
WstringConverterPtr getProcessWstringConverter()
Retrieves the per-process wide string converter.
IceUtil::UTF8Buffer::~UTF8Buffer
virtual ~UTF8Buffer()
ICE_DEFINE_PTR
#define ICE_DEFINE_PTR(TPtr, T)
Definition: Config.h:359
IceUtil::BasicStringConverter::fromUTF8
virtual void fromUTF8(const Byte *sourceStart, const Byte *sourceEnd, std::basic_string< charT > &target) const =0
Unmarshals a UTF-8 sequence into a basic_string.
IceUtil::WstringConverterPtr
::std::shared_ptr< WstringConverter > WstringConverterPtr
Definition: StringConverter.h:84
Handle.h
IceUtil::nativeToUTF8
std::string nativeToUTF8(const std::string &str, const StringConverterPtr &nc)
Converts the given string from the native narrow string encoding to UTF-8 using the given converter.
IceUtil
Definition: Optional.h:1095
ICE_API
#define ICE_API
Definition: Config.h:197
IceUtil::setProcessStringConverter
void setProcessStringConverter(const StringConverterPtr &c)
Sets the per-process narrow string converter.
IceUtil::UTF8ToNative
std::string UTF8ToNative(const std::string &str, const StringConverterPtr &nc)
Converts the given string from UTF-8 to the native narrow string encoding using the given converter.
IceUtil::StringConverter
BasicStringConverter< char > StringConverter
A narrow string converter.
Definition: StringConverter.h:79
IceUtil::BasicStringConverter::~BasicStringConverter
virtual ~BasicStringConverter()
Definition: StringConverter.h:64
IceUtil::Byte
unsigned char Byte
Definition: Config.h:326
IceUtil::UTF8Buffer::getMoreBytes
virtual Byte * getMoreBytes(size_t howMany, Byte *firstUnused)=0
Obtains more bytes.
IceUtil::WstringConverter
BasicStringConverter< wchar_t > WstringConverter
A wide string converter.
Definition: StringConverter.h:83
IceUtil::UTF8Buffer
Provides bytes to toUTF8.
Definition: StringConverter.h:24
Shared.h
Exception.h
IceUtil::BasicStringConverter::toUTF8
virtual Byte * toUTF8(const charT *sourceStart, const charT *sourceEnd, UTF8Buffer &buf) const =0
Returns a pointer to byte after the last written byte (which may be past the last byte returned by ge...
IceUtil::stringToWstring
std::wstring stringToWstring(const std::string &str, const StringConverterPtr &nc=0, const WstringConverterPtr &wc=0)
Converts the given narrow string to a wide string.
IceUtil::StringConverterPtr
::std::shared_ptr< StringConverter > StringConverterPtr
Definition: StringConverter.h:80
Config.h
IceUtil::getProcessStringConverter
StringConverterPtr getProcessStringConverter()
Retrieves the per-process narrow string converter.
IceUtil::setProcessWstringConverter
void setProcessWstringConverter(const WstringConverterPtr &c)
Sets the per process wide string converter.
IceUtil::createUnicodeWstringConverter
WstringConverterPtr createUnicodeWstringConverter()
Creates a WstringConverter that converts to and from UTF-16 or UTF-32 depending on sizeof(wchar_t).
IceUtil::Shared
Definition: Shared.h:78
IceUtil::BasicStringConverter
A StringConverter converts narrow or wide-strings to and from UTF-8 byte sequences.
Definition: StringConverter.h:50
IceUtil::wstringToString
std::string wstringToString(const std::wstring &str, const StringConverterPtr &nc=0, const WstringConverterPtr &wc=0)
Converts the given wide string to a narrow string.