CppCMS

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

utf8_codecvt.h
1 //
2 // Copyright (c) 2015 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_UTF8_CODECVT_HPP
9 #define BOOSTER_LOCALE_UTF8_CODECVT_HPP
10
11 #include <booster/locale/utf.h>
12 #include <booster/locale/generic_codecvt.h>
13 #include <booster/cstdint.h>
14 #include <locale>
15
16 namespace booster {
17 namespace locale {
18
22 template<typename CharType>
23 class utf8_codecvt : public generic_codecvt<CharType,utf8_codecvt<CharType> >
24 {
25 public:
26
27 struct state_type {};
28
29 utf8_codecvt(size_t refs = 0) : generic_codecvt<CharType,utf8_codecvt<CharType> >(refs)
30 {
31 }
32
33 static int max_encoding_length()
34 {
35 return 4;
36 }
37
38 static state_type initial_state(generic_codecvt_base::initial_convertion_state /* unused */)
39 {
40 return state_type();
41 }
42 static utf::code_point to_unicode(state_type &,char const *&begin,char const *end)
43 {
44 char const *p=begin;
45
46 utf::code_point c = utf::utf_traits<char>::decode(p,end);
47 if(c!=utf::illegal && c!=utf::incomplete)
48 begin = p;
49 return c;
50 }
51
52 static utf::code_point from_unicode(state_type &,utf::code_point u,char *begin,char const *end)
53 {
54 if(!utf::is_valid_codepoint(u))
55 return utf::illegal;
56 int width;
57 if((width=utf::utf_traits<char>::width(u)) > end - begin)
58 return utf::incomplete;
59 utf::utf_traits<char>::encode(u,begin);
60 return width;
61 }
62 };
63
64 } // locale
65 } // namespace boost
66
67 #endif
68 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
booster::locale::utf::utf_traits
Definition: utf.h:140
booster::locale::utf::code_point
uint32_t code_point
The integral type that can hold a Unicode code point.
Definition: utf.h:34
booster::locale::generic_codecvt_base::initial_convertion_state
initial_convertion_state
Definition: generic_codecvt.h:32
booster::locale::generic_codecvt
Geneneric generic codecvt facet, various stateless encodings to UTF-16 and UTF-32 using wchar_t...
Definition: generic_codecvt.h:133
booster::locale::utf::incomplete
static const code_point incomplete
Special constant that defines incomplete code point.
Definition: utf.h:44
booster::locale::utf::illegal
static const code_point illegal
Special constant that defines illegal code point.
Definition: utf.h:39
booster::locale::utf::is_valid_codepoint
bool is_valid_codepoint(code_point v)
the function checks if v is a valid code point
Definition: utf.h:49
booster::locale
This is the main namespace that encloses all localization classes.
Definition: locale_fwd.h:14
booster::locale::utf8_codecvt::state_type
Definition: utf8_codecvt.h:27
booster::locale::utf8_codecvt
Geneneric utf8 codecvt facet, it allows to convert UTF-8 strings to UTF-16 and UTF-32 using wchar_t...
Definition: utf8_codecvt.h:23
booster
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23