00001
00002
00003
00004
00005
00006
00007
00008 #ifndef BOOST_LOCALE_CODEPAGE_HPP_INCLUDED
00009 #define BOOST_LOCALE_CODEPAGE_HPP_INCLUDED
00010
00011 #include <boost/locale/config.hpp>
00012 #ifdef BOOST_MSVC
00013 # pragma warning(push)
00014 # pragma warning(disable : 4275 4251 4231 4660)
00015 #endif
00016 #include <boost/locale/info.hpp>
00017 #include <boost/cstdint.hpp>
00018 #include <stdexcept>
00019
00020
00021
00022 namespace boost {
00023 namespace locale {
00024
00030 template<typename CharType>
00031 std::codecvt<CharType,char,mbstate_t> *create_codecvt(info const &inf);
00032
00034 template<>
00035 BOOST_LOCALE_DECL std::codecvt<char,char,mbstate_t> *create_codecvt(info const &inf);
00036
00037 #ifndef BOOST_NO_STD_WSTRING
00038 template<>
00039 BOOST_LOCALE_DECL std::codecvt<wchar_t,char,mbstate_t> *create_codecvt(info const &inf);
00040 #endif
00041
00042 #ifdef BOOST_HAS_CHAR16_T
00043 template<>
00044 BOOST_LOCALE_DECL std::codecvt<char16_t,char,mbstate_t> *create_codecvt(info const &inf);
00045 #endif
00046
00047 #ifdef BOOST_HAS_CHAR32_T
00048 template<>
00049 BOOST_LOCALE_DECL std::codecvt<char32_t,char,mbstate_t> *create_codecvt(info const &inf);
00050 #endif
00052
00056 namespace conv {
00061
00065 class conversion_error : public std::runtime_error {
00066 public:
00067 conversion_error() : std::runtime_error("Conversion failed") {}
00068 };
00069
00070
00074 typedef enum {
00075 skip = 0,
00076 stop = 1,
00077 default_method = skip
00078 } method_type;
00079
00083 template<typename CharType>
00084 std::basic_string<CharType> to_utf(char const *begin,char const *end,std::string const &charset,method_type how=default_method);
00085
00089 template<typename CharType>
00090 std::string from_utf(CharType const *begin,CharType const *end,std::string const &charset,method_type how=default_method);
00091
00095 template<typename CharType>
00096 std::basic_string<CharType> to_utf(char const *begin,char const *end,std::locale const &loc,method_type how=default_method)
00097 {
00098 return to_utf<CharType>(begin,end,std::use_facet<info>(loc).encoding(),how);
00099 }
00100
00104 template<typename CharType>
00105 std::string from_utf(CharType const *begin,CharType const *end,std::locale const &loc,method_type how=default_method)
00106 {
00107 return from_utf(begin,end,std::use_facet<info>(loc).encoding(),how);
00108 }
00109
00113
00114 template<typename CharType>
00115 std::basic_string<CharType> to_utf(std::string const &text,std::string const &charset,method_type how=default_method)
00116 {
00117 return to_utf<CharType>(text.c_str(),text.c_str()+text.size(),charset,how);
00118 }
00119
00123 template<typename CharType>
00124 std::string from_utf(std::basic_string<CharType> const &text,std::string const &charset,method_type how=default_method)
00125 {
00126 return from_utf(text.c_str(),text.c_str()+text.size(),charset,how);
00127 }
00128
00132 template<typename CharType>
00133 std::basic_string<CharType> to_utf(char const *text,std::string const &charset,method_type how=default_method)
00134 {
00135 char const *text_end = text;
00136 while(*text_end)
00137 text_end++;
00138 return to_utf<CharType>(text,text_end,charset,how);
00139 }
00140
00144 template<typename CharType>
00145 std::string from_utf(CharType const *text,std::string const &charset,method_type how=default_method)
00146 {
00147 CharType const *text_end = text;
00148 while(*text_end)
00149 text_end++;
00150 return from_utf(text,text_end,charset,how);
00151 }
00152
00156 template<typename CharType>
00157 std::basic_string<CharType> to_utf(std::string const &text,std::locale const &loc,method_type how=default_method)
00158 {
00159 return to_utf<CharType>(text.c_str(),text.c_str()+text.size(),loc,how);
00160 }
00161
00165 template<typename CharType>
00166 std::string from_utf(std::basic_string<CharType> const &text,std::locale const &loc,method_type how=default_method)
00167 {
00168 return from_utf(text.c_str(),text.c_str()+text.size(),loc,how);
00169 }
00170
00174 template<typename CharType>
00175 std::basic_string<CharType> to_utf(char const *text,std::locale const &loc,method_type how=default_method)
00176 {
00177 char const *text_end = text;
00178 while(*text_end)
00179 text_end++;
00180 return to_utf<CharType>(text,text_end,loc,how);
00181 }
00182
00186 template<typename CharType>
00187 std::string from_utf(CharType const *text,std::locale const &loc,method_type how=default_method)
00188 {
00189 CharType const *text_end = text;
00190 while(*text_end)
00191 text_end++;
00192 return from_utf(text,text_end,loc,how);
00193 }
00194
00196
00198
00199 template<>
00200 BOOST_LOCALE_DECL std::basic_string<char> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
00201
00202 template<>
00203 BOOST_LOCALE_DECL std::string from_utf(char const *begin,char const *end,std::string const &charset,method_type how);
00204
00205 #ifndef BOOST_NO_STD_WSTRING
00206 template<>
00207 BOOST_LOCALE_DECL std::basic_string<wchar_t> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
00208
00209 template<>
00210 BOOST_LOCALE_DECL std::string from_utf(wchar_t const *begin,wchar_t const *end,std::string const &charset,method_type how);
00211 #endif
00212
00213 #ifdef BOOST_HAS_CHAR16_T
00214 template<>
00215 BOOST_LOCALE_DECL std::basic_string<char16_t> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
00216
00217 template<>
00218 BOOST_LOCALE_DECL std::string from_utf(char16_t const *begin,char16_t const *end,std::string const &charset,method_type how);
00219 #endif
00220
00221 #ifdef BOOST_HAS_CHAR32_T
00222 template<>
00223 BOOST_LOCALE_DECL std::basic_string<char32_t> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
00224
00225 template<>
00226 BOOST_LOCALE_DECL std::string from_utf(char32_t const *begin,char32_t const *end,std::string const &charset,method_type how);
00227 #endif
00228
00230 }
00231
00232 }
00233 }
00234
00235 #ifdef BOOST_MSVC
00236 #pragma warning(pop)
00237 #endif
00238
00239 #endif
00240
00241
00242