7#ifndef BOOST_LOCALE_ENCODING_HPP_INCLUDED
8#define BOOST_LOCALE_ENCODING_HPP_INCLUDED
10#include <boost/locale/config.hpp>
11#include <boost/locale/detail/encoding.hpp>
12#include <boost/locale/encoding_errors.hpp>
13#include <boost/locale/encoding_utf.hpp>
14#include <boost/locale/info.hpp>
15#include <boost/locale/util/string.hpp>
20# pragma warning(disable : 4275 4251 4231 4660)
23namespace boost {
namespace locale {
37 template<
typename CharType>
38 BOOST_LOCALE_DECL std::basic_string<CharType>
46 template<
typename CharType>
47 BOOST_LOCALE_DECL std::string
from_utf(
const CharType* begin,
49 const std::string& charset,
57 template<
typename CharType>
58 std::basic_string<CharType>
61 return to_utf<CharType>(text.c_str(), text.c_str() + text.size(), charset, how);
69 template<
typename CharType>
70 std::basic_string<CharType>
73 return to_utf<CharType>(text,
util::str_end(text), charset, how);
83 template<
typename CharType>
84 std::basic_string<CharType>
87 return to_utf<CharType>(begin, end, std::use_facet<info>(loc).encoding(), how);
96 template<
typename CharType>
97 std::basic_string<CharType>
100 return to_utf<CharType>(text, std::use_facet<info>(loc).encoding(), how);
109 template<
typename CharType>
112 return to_utf<CharType>(text, std::use_facet<info>(loc).encoding(), how);
120 template<
typename CharType>
124 return from_utf(text.c_str(), text.c_str() + text.size(), charset, how);
132 template<
typename CharType>
144 template<
typename CharType>
148 return from_utf(begin, end, std::use_facet<info>(loc).encoding(), how);
157 template<
typename CharType>
161 return from_utf(text, std::use_facet<info>(loc).encoding(), how);
170 template<
typename CharType>
173 return from_utf(text, std::use_facet<info>(loc).encoding(), how);
185 const std::string& to_encoding,
186 const std::string& from_encoding,
196 const std::string& to_encoding,
197 const std::string& from_encoding,
209 inline std::string
between(
const std::string& text,
210 const std::string& to_encoding,
211 const std::string& from_encoding,
214 return between(text.c_str(), text.c_str() + text.size(), to_encoding, from_encoding, how);
220 template<
typename CharType>
222 std::unique_ptr<detail::utf_encoder<CharType>> impl_;
225 using char_type = CharType;
226 using string_type = std::basic_string<CharType>;
233 impl_(detail::make_utf_encoder<CharType>(charset, how))
239 string_type
convert(
const char* begin,
const char* end)
const {
return impl_->convert(begin, end); }
243 string_type
convert(
const boost::string_view& text)
const {
return impl_->convert(text); }
251 template<
typename CharType>
253 std::unique_ptr<detail::utf_decoder<CharType>> impl_;
256 using char_type = CharType;
257 using stringview_type = boost::basic_string_view<CharType>;
264 impl_(detail::make_utf_decoder<CharType>(charset, how))
270 std::string
convert(
const CharType* begin,
const CharType* end)
const {
return impl_->convert(begin, end); }
274 std::string
convert(
const stringview_type& text)
const {
return impl_->convert(text); }
282 std::unique_ptr<detail::narrow_converter> impl_;
289 const std::string& target_encoding,
291 impl_(detail::make_narrow_converter(src_encoding, target_encoding, how))
297 std::string
convert(
const char* begin,
const char* end)
const {
return impl_->convert(begin, end); }
301 std::string
convert(
const boost::string_view& text)
const {
return impl_->convert(text); }
Definition: encoding.hpp:281
std::string convert(const boost::string_view &text) const
Definition: encoding.hpp:301
narrow_converter(const std::string &src_encoding, const std::string &target_encoding, method_type how=default_method)
Definition: encoding.hpp:288
std::string convert(const char *begin, const char *end) const
Definition: encoding.hpp:297
std::string operator()(const boost::string_view &text) const
Definition: encoding.hpp:305
Converter class to decode an UTF string and encode it using a local encoding.
Definition: encoding.hpp:252
utf_decoder(const std::string &charset, method_type how=default_method)
Definition: encoding.hpp:263
std::string convert(const CharType *begin, const CharType *end) const
Definition: encoding.hpp:270
std::string operator()(const stringview_type &text) const
Definition: encoding.hpp:278
std::string convert(const stringview_type &text) const
Definition: encoding.hpp:274
Converter class to decode a narrow string using a local encoding and encode it with UTF.
Definition: encoding.hpp:221
string_type convert(const char *begin, const char *end) const
Definition: encoding.hpp:239
utf_encoder(const std::string &charset, method_type how=default_method)
Definition: encoding.hpp:232
string_type operator()(const boost::string_view &text) const
Definition: encoding.hpp:247
string_type convert(const boost::string_view &text) const
Definition: encoding.hpp:243
std::basic_string< CharType > to_utf(const char *begin, const char *end, const std::string &charset, method_type how=default_method)
std::string from_utf(const CharType *begin, const CharType *end, const std::string &charset, method_type how=default_method)
std::string between(const char *begin, const char *end, const std::string &to_encoding, const std::string &from_encoding, method_type how=default_method)
method_type
enum that defines conversion policy
Definition: encoding_errors.hpp:41
@ default_method
Default method - skip.
Definition: encoding_errors.hpp:44
Char * str_end(Char *str)
Return the end of a C-string, i.e. the pointer to the trailing NULL byte.
Definition: string.hpp:16
@ convert
Generate conversion facets.