CppCMS
encoding.h
1 //
2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 #ifndef BOOSTER_LOCALE_ENCODING_H_INCLUDED
9 #define BOOSTER_LOCALE_ENCODING_H_INCLUDED
10 
11 #include <booster/config.h>
12 #ifdef BOOSTER_MSVC
13 # pragma warning(push)
14 # pragma warning(disable : 4275 4251 4231 4660)
15 #endif
16 #include <booster/locale/info.h>
17 #include <booster/locale/encoding_errors.h>
18 #include <booster/locale/encoding_utf.h>
19 
20 
21 
22 namespace booster {
23  namespace locale {
24 
28  namespace conv {
33 
37  template<typename CharType>
38  std::basic_string<CharType> to_utf(char const *begin,char const *end,std::string const &charset,method_type how=default_method);
39 
43  template<typename CharType>
44  std::string from_utf(CharType const *begin,CharType const *end,std::string const &charset,method_type how=default_method);
45 
51  template<typename CharType>
52  std::basic_string<CharType> to_utf(char const *begin,char const *end,std::locale const &loc,method_type how=default_method)
53  {
54  return to_utf<CharType>(begin,end,std::use_facet<info>(loc).encoding(),how);
55  }
56 
62  template<typename CharType>
63  std::string from_utf(CharType const *begin,CharType const *end,std::locale const &loc,method_type how=default_method)
64  {
65  return from_utf(begin,end,std::use_facet<info>(loc).encoding(),how);
66  }
67 
71 
72  template<typename CharType>
73  std::basic_string<CharType> to_utf(std::string const &text,std::string const &charset,method_type how=default_method)
74  {
75  return to_utf<CharType>(text.c_str(),text.c_str()+text.size(),charset,how);
76  }
77 
81  template<typename CharType>
82  std::string from_utf(std::basic_string<CharType> const &text,std::string const &charset,method_type how=default_method)
83  {
84  return from_utf(text.c_str(),text.c_str()+text.size(),charset,how);
85  }
86 
90  template<typename CharType>
91  std::basic_string<CharType> to_utf(char const *text,std::string const &charset,method_type how=default_method)
92  {
93  char const *text_end = text;
94  while(*text_end)
95  text_end++;
96  return to_utf<CharType>(text,text_end,charset,how);
97  }
98 
102  template<typename CharType>
103  std::string from_utf(CharType const *text,std::string const &charset,method_type how=default_method)
104  {
105  CharType const *text_end = text;
106  while(*text_end)
107  text_end++;
108  return from_utf(text,text_end,charset,how);
109  }
110 
116  template<typename CharType>
117  std::basic_string<CharType> to_utf(std::string const &text,std::locale const &loc,method_type how=default_method)
118  {
119  return to_utf<CharType>(text.c_str(),text.c_str()+text.size(),loc,how);
120  }
121 
127  template<typename CharType>
128  std::string from_utf(std::basic_string<CharType> const &text,std::locale const &loc,method_type how=default_method)
129  {
130  return from_utf(text.c_str(),text.c_str()+text.size(),loc,how);
131  }
132 
138  template<typename CharType>
139  std::basic_string<CharType> to_utf(char const *text,std::locale const &loc,method_type how=default_method)
140  {
141  char const *text_end = text;
142  while(*text_end)
143  text_end++;
144  return to_utf<CharType>(text,text_end,loc,how);
145  }
146 
152  template<typename CharType>
153  std::string from_utf(CharType const *text,std::locale const &loc,method_type how=default_method)
154  {
155  CharType const *text_end = text;
156  while(*text_end)
157  text_end++;
158  return from_utf(text,text_end,loc,how);
159  }
160 
161 
165 
166  BOOSTER_API
167  std::string between(char const *begin,
168  char const *end,
169  std::string const &to_encoding,
170  std::string const &from_encoding,
172 
176 
177  inline
178  std::string between(char const *text,
179  std::string const &to_encoding,
180  std::string const &from_encoding,
182  {
183  char const *end=text;
184  while(*end)
185  end++;
186  return booster::locale::conv::between(text,end,to_encoding,from_encoding,how);
187  }
188 
192  inline
193  std::string between(std::string const &text,
194  std::string const &to_encoding,
195  std::string const &from_encoding,
197  {
198  return booster::locale::conv::between(text.c_str(),text.c_str()+text.size(),to_encoding,from_encoding,how);
199  }
200 
202 
203  template<>
204  BOOSTER_API std::basic_string<char> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
205 
206  template<>
207  BOOSTER_API std::string from_utf(char const *begin,char const *end,std::string const &charset,method_type how);
208 
209  template<>
210  BOOSTER_API std::basic_string<wchar_t> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
211 
212  template<>
213  BOOSTER_API std::string from_utf(wchar_t const *begin,wchar_t const *end,std::string const &charset,method_type how);
214 
215  #ifdef BOOSTER_HAS_CHAR16_T
216  template<>
217  BOOSTER_API std::basic_string<char16_t> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
218 
219  template<>
220  BOOSTER_API std::string from_utf(char16_t const *begin,char16_t const *end,std::string const &charset,method_type how);
221  #endif
222 
223  #ifdef BOOSTER_HAS_CHAR32_T
224  template<>
225  BOOSTER_API std::basic_string<char32_t> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
226 
227  template<>
228  BOOSTER_API std::string from_utf(char32_t const *begin,char32_t const *end,std::string const &charset,method_type how);
229  #endif
230 
231 
233 
235 
236  } // conv
237 
238  } // locale
239 } // boost
240 
241 #ifdef BOOSTER_MSVC
242 #pragma warning(pop)
243 #endif
244 
245 #endif
246 
247 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
248 
Default method - skip.
Definition: encoding_errors.h:57
BOOSTER_API std::string between(char const *begin, char const *end, std::string const &to_encoding, std::string const &from_encoding, method_type how=default_method)
std::basic_string< CharType > to_utf(char const *begin, char const *end, std::string const &charset, method_type how=default_method)
This is the main namespace that encloses all localization classes.
Definition: locale_fwd.h:14
std::string from_utf(CharType const *begin, CharType const *end, std::string const &charset, method_type how=default_method)
method_type
Definition: encoding_errors.h:54
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23