File indexing completed on 2025-09-15 08:39:12
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_LOCALE_ENCODING_HPP_INCLUDED
0009 #define BOOST_LOCALE_ENCODING_HPP_INCLUDED
0010
0011 #include <boost/locale/config.hpp>
0012 #include <boost/locale/detail/encoding.hpp>
0013 #include <boost/locale/encoding_errors.hpp>
0014 #include <boost/locale/encoding_utf.hpp>
0015 #include <boost/locale/info.hpp>
0016 #include <boost/locale/util/string.hpp>
0017 #include <memory>
0018
0019 #ifdef BOOST_MSVC
0020 # pragma warning(push)
0021 # pragma warning(disable : 4275 4251 4231 4660)
0022 #endif
0023
0024 namespace boost { namespace locale {
0025
0026
0027 namespace conv {
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 template<typename CharType>
0039 BOOST_LOCALE_DECL std::basic_string<CharType>
0040 to_utf(const char* begin, const char* end, const std::string& charset, method_type how = default_method);
0041
0042
0043
0044
0045
0046
0047 template<typename CharType>
0048 BOOST_LOCALE_DECL std::string from_utf(const CharType* begin,
0049 const CharType* end,
0050 const std::string& charset,
0051 method_type how = default_method);
0052
0053
0054
0055
0056
0057
0058 template<typename CharType>
0059 std::basic_string<CharType>
0060 to_utf(const std::string& text, const std::string& charset, method_type how = default_method)
0061 {
0062 return to_utf<CharType>(text.c_str(), text.c_str() + text.size(), charset, how);
0063 }
0064
0065
0066
0067
0068
0069
0070 template<typename CharType>
0071 std::basic_string<CharType>
0072 to_utf(const char* text, const std::string& charset, method_type how = default_method)
0073 {
0074 return to_utf<CharType>(text, util::str_end(text), charset, how);
0075 }
0076
0077
0078
0079
0080
0081
0082
0083
0084 template<typename CharType>
0085 std::basic_string<CharType>
0086 to_utf(const char* begin, const char* end, const std::locale& loc, method_type how = default_method)
0087 {
0088 return to_utf<CharType>(begin, end, std::use_facet<info>(loc).encoding(), how);
0089 }
0090
0091
0092
0093
0094
0095
0096
0097 template<typename CharType>
0098 std::basic_string<CharType>
0099 to_utf(const std::string& text, const std::locale& loc, method_type how = default_method)
0100 {
0101 return to_utf<CharType>(text, std::use_facet<info>(loc).encoding(), how);
0102 }
0103
0104
0105
0106
0107
0108
0109
0110 template<typename CharType>
0111 std::basic_string<CharType> to_utf(const char* text, const std::locale& loc, method_type how = default_method)
0112 {
0113 return to_utf<CharType>(text, std::use_facet<info>(loc).encoding(), how);
0114 }
0115
0116
0117
0118
0119
0120
0121 template<typename CharType>
0122 std::string
0123 from_utf(const std::basic_string<CharType>& text, const std::string& charset, method_type how = default_method)
0124 {
0125 return from_utf(text.c_str(), text.c_str() + text.size(), charset, how);
0126 }
0127
0128
0129
0130
0131
0132
0133 template<typename CharType>
0134 std::string from_utf(const CharType* text, const std::string& charset, method_type how = default_method)
0135 {
0136 return from_utf(text, util::str_end(text), charset, how);
0137 }
0138
0139
0140
0141
0142
0143
0144
0145 template<typename CharType>
0146 std::string
0147 from_utf(const CharType* begin, const CharType* end, const std::locale& loc, method_type how = default_method)
0148 {
0149 return from_utf(begin, end, std::use_facet<info>(loc).encoding(), how);
0150 }
0151
0152
0153
0154
0155
0156
0157
0158 template<typename CharType>
0159 std::string
0160 from_utf(const std::basic_string<CharType>& text, const std::locale& loc, method_type how = default_method)
0161 {
0162 return from_utf(text, std::use_facet<info>(loc).encoding(), how);
0163 }
0164
0165
0166
0167
0168
0169
0170
0171 template<typename CharType>
0172 std::string from_utf(const CharType* text, const std::locale& loc, method_type how = default_method)
0173 {
0174 return from_utf(text, std::use_facet<info>(loc).encoding(), how);
0175 }
0176
0177
0178
0179
0180
0181
0182
0183 BOOST_LOCALE_DECL
0184 std::string between(const char* begin,
0185 const char* end,
0186 const std::string& to_encoding,
0187 const std::string& from_encoding,
0188 method_type how = default_method);
0189
0190
0191
0192
0193
0194
0195
0196 inline std::string between(const char* text,
0197 const std::string& to_encoding,
0198 const std::string& from_encoding,
0199 method_type how = default_method)
0200 {
0201 return between(text, util::str_end(text), to_encoding, from_encoding, how);
0202 }
0203
0204
0205
0206
0207
0208
0209
0210 inline std::string between(const std::string& text,
0211 const std::string& to_encoding,
0212 const std::string& from_encoding,
0213 method_type how = default_method)
0214 {
0215 return between(text.c_str(), text.c_str() + text.size(), to_encoding, from_encoding, how);
0216 }
0217
0218
0219
0220
0221 template<typename CharType>
0222 class utf_encoder {
0223 std::unique_ptr<detail::utf_encoder<CharType>> impl_;
0224
0225 public:
0226 using char_type = CharType;
0227 using string_type = std::basic_string<CharType>;
0228
0229
0230
0231
0232
0233 utf_encoder(const std::string& charset, method_type how = default_method) :
0234 impl_(detail::make_utf_encoder<CharType>(charset, how))
0235 {}
0236
0237
0238
0239
0240 string_type convert(const char* begin, const char* end) const { return impl_->convert(begin, end); }
0241
0242
0243
0244 string_type convert(const core::string_view text) const { return impl_->convert(text); }
0245
0246
0247
0248 string_type operator()(const core::string_view text) const { return convert(text); }
0249 };
0250
0251
0252 template<typename CharType>
0253 class utf_decoder {
0254 std::unique_ptr<detail::utf_decoder<CharType>> impl_;
0255
0256 public:
0257 using char_type = CharType;
0258 using stringview_type = core::basic_string_view<CharType>;
0259
0260
0261
0262
0263
0264 utf_decoder(const std::string& charset, method_type how = default_method) :
0265 impl_(detail::make_utf_decoder<CharType>(charset, how))
0266 {}
0267
0268
0269
0270
0271 std::string convert(const CharType* begin, const CharType* end) const { return impl_->convert(begin, end); }
0272
0273
0274
0275 std::string convert(const stringview_type& text) const { return impl_->convert(text); }
0276
0277
0278
0279 std::string operator()(const stringview_type& text) const { return convert(text); }
0280 };
0281
0282 class narrow_converter {
0283 std::unique_ptr<detail::narrow_converter> impl_;
0284
0285 public:
0286
0287
0288
0289 narrow_converter(const std::string& src_encoding,
0290 const std::string& target_encoding,
0291 method_type how = default_method) :
0292 impl_(detail::make_narrow_converter(src_encoding, target_encoding, how))
0293 {}
0294
0295
0296
0297
0298 std::string convert(const char* begin, const char* end) const { return impl_->convert(begin, end); }
0299
0300
0301
0302 std::string convert(const core::string_view text) const { return impl_->convert(text); }
0303
0304
0305
0306 std::string operator()(const core::string_view text) const { return convert(text); }
0307 };
0308 }
0309 }}
0310
0311 #ifdef BOOST_MSVC
0312 # pragma warning(pop)
0313 #endif
0314
0315 #endif