00001
00002
00003
00004
00005
00006
00007
00008 #ifndef BOOST_LOCALE_CONVERTER_HPP_INCLUDED
00009 #define BOOST_LOCALE_CONVERTER_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 <locale>
00017
00018
00019 namespace boost {
00020 namespace locale {
00021
00028
00030 namespace impl {
00031 typedef enum {
00032 normalization,
00033 upper_case,
00034 lower_case,
00035 case_folding,
00036 title_case
00037 } conversion_type;
00038
00039 BOOST_LOCALE_DECL std::string convert(conversion_type how,char const *begin,char const *end,int flags,std::locale const *loc=0);
00040 #ifndef BOOST_NO_STD_WSTRING
00041 BOOST_LOCALE_DECL std::wstring convert(conversion_type how,wchar_t const *begin,wchar_t const *end,int flags,std::locale const *loc=0);
00042 #endif
00043 #ifdef BOOST_HAS_CHAR16_T
00044 BOOST_LOCALE_DECL std::u16string convert(conversion_type how,char16_t const *begin,char16_t const *end,int flags,std::locale const *loc=0);
00045 #endif
00046 #ifdef BOOST_HAS_CHAR32_T
00047 BOOST_LOCALE_DECL std::u32string convert(conversion_type how,char32_t const *begin,char32_t const *end,int flags,std::locale const *loc=0);
00048 #endif
00049
00050 }
00052
00056
00057 typedef enum {
00058 norm_nfd,
00059 norm_nfc,
00060 norm_nfkd,
00061 norm_nfkc,
00062 norm_default = norm_nfc,
00063 } norm_type;
00064
00072 template<typename CharType>
00073 std::basic_string<CharType> normalize(std::basic_string<CharType> const &str,norm_type n=norm_default)
00074 {
00075 return impl::convert(impl::normalization,str.data(),str.data() + str.size(),n);
00076 }
00077
00085 template<typename CharType>
00086 std::basic_string<CharType> normalize(CharType const *str,norm_type n=norm_default)
00087 {
00088 CharType const *end=str;
00089 while(*end)
00090 end++;
00091 return impl::convert(impl::normalization,str,end,n);
00092 }
00093
00101 template<typename CharType>
00102 std::basic_string<CharType> normalize(CharType const *begin,CharType const *end,norm_type n=norm_default)
00103 {
00104 return impl::convert(impl::normalization,begin,end,n);
00105 }
00106
00108
00112
00113 template<typename CharType>
00114 std::basic_string<CharType> to_upper(std::basic_string<CharType> const &str,std::locale const &loc=std::locale())
00115 {
00116 return impl::convert(impl::upper_case,str.data(),str.data()+str.size(),0,&loc);
00117 }
00118
00122 template<typename CharType>
00123 std::basic_string<CharType> to_upper(CharType const *str,std::locale const &loc=std::locale())
00124 {
00125 CharType const *end=str;
00126 while(*end)
00127 end++;
00128 return impl::convert(impl::upper_case,str,end,0,&loc);
00129 }
00130
00134 template<typename CharType>
00135 std::basic_string<CharType> to_upper(CharType const *begin,CharType const *end,std::locale const &loc=std::locale())
00136 {
00137 return impl::convert(impl::upper_case,begin,end,0,&loc);
00138 }
00139
00141
00145
00146 template<typename CharType>
00147 std::basic_string<CharType> to_lower(std::basic_string<CharType> const &str,std::locale const &loc=std::locale())
00148 {
00149 return impl::convert(impl::lower_case,str.data(),str.data()+str.size(),0,&loc);
00150 }
00151
00155 template<typename CharType>
00156 std::basic_string<CharType> to_lower(CharType const *str,std::locale const &loc=std::locale())
00157 {
00158 CharType const *end=str;
00159 while(*end)
00160 end++;
00161 return impl::convert(impl::lower_case,str,end,0,&loc);
00162 }
00163
00167 template<typename CharType>
00168 std::basic_string<CharType> to_lower(CharType const *begin,CharType const *end,std::locale const &loc=std::locale())
00169 {
00170 return impl::convert(impl::lower_case,begin,end,0,&loc);
00171 }
00173
00177
00178 template<typename CharType>
00179 std::basic_string<CharType> to_title(std::basic_string<CharType> const &str,std::locale const &loc=std::locale())
00180 {
00181 return impl::convert(impl::title_case,str.data(),str.data()+str.size(),0,&loc);
00182 }
00183
00187 template<typename CharType>
00188 std::basic_string<CharType> to_title(CharType const *str,std::locale const &loc=std::locale())
00189 {
00190 CharType const *end=str;
00191 while(*end)
00192 end++;
00193 return impl::convert(impl::title_case,str,end,0,&loc);
00194 }
00195
00199 template<typename CharType>
00200 std::basic_string<CharType> to_title(CharType const *begin,CharType const *end,std::locale const &loc=std::locale())
00201 {
00202 return impl::convert(impl::title_case,begin,end,0,&loc);
00203 }
00204
00206
00210
00211 template<typename CharType>
00212 std::basic_string<CharType> fold_case(std::basic_string<CharType> const &str,std::locale const &loc=std::locale())
00213 {
00214 return impl::convert(impl::case_folding,str.data(),str.data()+str.size(),0,&loc);
00215 }
00216
00220 template<typename CharType>
00221 std::basic_string<CharType> fold_case(CharType const *str,std::locale const &loc=std::locale())
00222 {
00223 CharType const *end=str;
00224 while(*end)
00225 end++;
00226 return impl::convert(impl::case_folding,str,end,0,&loc);
00227 }
00228
00232 template<typename CharType>
00233 std::basic_string<CharType> fold_case(CharType const *begin,CharType const *end,std::locale const &loc=std::locale())
00234 {
00235 return impl::convert(impl::case_folding,begin,end,0,&loc);
00236 }
00237
00241 }
00242
00243 }
00244
00245 #ifdef BOOST_MSVC
00246 #pragma warning(pop)
00247 #endif
00248
00249
00250 #endif
00251
00261
00262
00263