Ice 3.7 C++98 API Reference
Loading...
Searching...
No Matches
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
15namespace IceUtil
16{
17
24{
25public:
26
33 virtual Byte* getMoreBytes(size_t howMany, Byte* firstUnused) = 0;
34
35 virtual ~UTF8Buffer();
36};
37
45template<typename charT>
47#ifndef ICE_CPP11_MAPPING
48 : public IceUtil::Shared
49#endif
50{
51public:
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//
74template class ICE_API BasicStringConverter<char>;
75template class ICE_API BasicStringConverter<wchar_t>;
76#endif
77
81
85
91
97
103
109
115
124ICE_API std::string
125wstringToString(const std::wstring& str,
126 const StringConverterPtr& nc = 0,
127 const WstringConverterPtr& wc = 0);
128
137ICE_API std::wstring
138stringToWstring(const std::string& str,
139 const StringConverterPtr& nc = 0,
140 const WstringConverterPtr& wc = 0);
141
149ICE_API std::string
150nativeToUTF8(const std::string& str, const StringConverterPtr& nc);
151
159ICE_API std::string
160UTF8ToNative(const std::string& str, const StringConverterPtr& nc);
161
162}
163
164namespace IceUtilInternal
165{
166
167//
168// Convert from UTF-8 to UTF-16/32
169//
170ICE_API std::vector<unsigned short> toUTF16(const std::vector<IceUtil::Byte>&);
171ICE_API std::vector<unsigned int> toUTF32(const std::vector<IceUtil::Byte>&);
172
173//
174// Convert from UTF-32 to UTF-8
175//
176ICE_API std::vector<IceUtil::Byte> fromUTF32(const std::vector<unsigned int>&);
177
178}
179
180#ifdef _WIN32
181namespace IceUtil
182{
183
190ICE_API StringConverterPtr createWindowsStringConverter(unsigned int page);
191
192}
193#endif
194
195#endif
#define ICE_DEFINE_PTR(TPtr, T)
Definition Config.h:377
#define ICE_API
Definition Config.h:197
A StringConverter converts narrow or wide-strings to and from UTF-8 byte sequences.
Definition StringConverter.h:50
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...
virtual ~BasicStringConverter()
Definition StringConverter.h:64
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.
Definition Shared.h:78
Provides bytes to toUTF8.
Definition StringConverter.h:24
virtual Byte * getMoreBytes(size_t howMany, Byte *firstUnused)=0
Obtains more bytes.
Definition Cond.h:39
void setProcessStringConverter(const StringConverterPtr &c)
Sets the per-process narrow string converter.
BasicStringConverter< wchar_t > WstringConverter
A wide string converter.
Definition StringConverter.h:83
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.
void setProcessWstringConverter(const WstringConverterPtr &c)
Sets the per process wide string converter.
WstringConverterPtr createUnicodeWstringConverter()
Creates a WstringConverter that converts to and from UTF-16 or UTF-32 depending on sizeof(wchar_t).
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.
std::string wstringToString(const std::wstring &str, const StringConverterPtr &nc=0, const WstringConverterPtr &wc=0)
Converts the given wide string to a narrow string.
::IceUtil::Handle< WstringConverter > WstringConverterPtr
Definition StringConverter.h:84
::IceUtil::Handle< StringConverter > StringConverterPtr
Definition StringConverter.h:80
BasicStringConverter< char > StringConverter
A narrow string converter.
Definition StringConverter.h:79
unsigned char Byte
Definition Config.h:326
std::wstring stringToWstring(const std::string &str, const StringConverterPtr &nc=0, const WstringConverterPtr &wc=0)
Converts the given narrow string to a wide string.
WstringConverterPtr getProcessWstringConverter()
Retrieves the per-process wide string converter.
StringConverterPtr getProcessStringConverter()
Retrieves the per-process narrow string converter.
IceUtil::StringConverterPtr StringConverterPtr
Definition StringConverter.h:20