8#ifndef BOOST_LOCALE_ENCODING_HPP_INCLUDED
9#define BOOST_LOCALE_ENCODING_HPP_INCLUDED
11#include <boost/locale/config.hpp>
12#include <boost/locale/detail/encoding.hpp>
13#include <boost/locale/encoding_errors.hpp>
14#include <boost/locale/encoding_utf.hpp>
15#include <boost/locale/info.hpp>
16#include <boost/locale/util/string.hpp>
21# pragma warning(disable : 4275 4251 4231 4660)
24namespace boost {
namespace locale {
38 template<
typename CharType>
39 BOOST_LOCALE_DECL std::basic_string<CharType>
47 template<
typename CharType>
48 BOOST_LOCALE_DECL std::string
from_utf(
const CharType* begin,
50 const std::string& charset,
58 template<
typename CharType>
59 std::basic_string<CharType>
62 return to_utf<CharType>(text.c_str(), text.c_str() + text.size(), charset, how);
70 template<
typename CharType>
71 std::basic_string<CharType>
84 template<
typename CharType>
85 std::basic_string<CharType>
88 return to_utf<CharType>(begin, end, std::use_facet<info>(loc).encoding(), how);
97 template<
typename CharType>
98 std::basic_string<CharType>
110 template<
typename CharType>
121 template<
typename CharType>
125 return from_utf(text.c_str(), text.c_str() + text.size(), charset, how);
133 template<
typename CharType>
145 template<
typename CharType>
149 return from_utf(begin, end, std::use_facet<info>(loc).encoding(), how);
158 template<
typename CharType>
162 return from_utf(text, std::use_facet<info>(loc).encoding(), how);
171 template<
typename CharType>
174 return from_utf(text, std::use_facet<info>(loc).encoding(), how);
186 const std::string& to_encoding,
187 const std::string& from_encoding,
197 const std::string& to_encoding,
198 const std::string& from_encoding,
210 inline std::string
between(
const std::string& text,
211 const std::string& to_encoding,
212 const std::string& from_encoding,
215 return between(text.c_str(), text.c_str() + text.size(), to_encoding, from_encoding, how);
221 template<
typename CharType>
223 std::unique_ptr<detail::utf_encoder<CharType>> impl_;
226 using char_type = CharType;
227 using string_type = std::basic_string<CharType>;
234 impl_(detail::make_utf_encoder<CharType>(charset, how))
240 string_type
convert(
const char* begin,
const char* end)
const {
return impl_->convert(begin, end); }
244 string_type
convert(
const core::string_view text)
const {
return impl_->convert(text); }
252 template<
typename CharType>
254 std::unique_ptr<detail::utf_decoder<CharType>> impl_;
257 using char_type = CharType;
258 using stringview_type = core::basic_string_view<CharType>;
265 impl_(detail::make_utf_decoder<CharType>(charset, how))
271 std::string
convert(
const CharType* begin,
const CharType* end)
const {
return impl_->convert(begin, end); }
275 std::string
convert(
const stringview_type& text)
const {
return impl_->convert(text); }
283 std::unique_ptr<detail::narrow_converter> impl_;
290 const std::string& target_encoding,
292 impl_(detail::make_narrow_converter(src_encoding, target_encoding, how))
298 std::string
convert(
const char* begin,
const char* end)
const {
return impl_->convert(begin, end); }
302 std::string
convert(
const core::string_view text)
const {
return impl_->convert(text); }
Definition encoding.hpp:282
std::string convert(const core::string_view text) const
Definition encoding.hpp:302
narrow_converter(const std::string &src_encoding, const std::string &target_encoding, method_type how=default_method)
Definition encoding.hpp:289
std::string convert(const char *begin, const char *end) const
Definition encoding.hpp:298
std::string operator()(const core::string_view text) const
Definition encoding.hpp:306
Converter class to decode an UTF string and encode it using a local encoding.
Definition encoding.hpp:253
utf_decoder(const std::string &charset, method_type how=default_method)
Definition encoding.hpp:264
std::string convert(const CharType *begin, const CharType *end) const
Definition encoding.hpp:271
std::string operator()(const stringview_type &text) const
Definition encoding.hpp:279
std::string convert(const stringview_type &text) const
Definition encoding.hpp:275
Converter class to decode a narrow string using a local encoding and encode it with UTF.
Definition encoding.hpp:222
string_type convert(const char *begin, const char *end) const
Definition encoding.hpp:240
utf_encoder(const std::string &charset, method_type how=default_method)
Definition encoding.hpp:233
string_type convert(const core::string_view text) const
Definition encoding.hpp:244
string_type operator()(const core::string_view text) const
Definition encoding.hpp:248
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.