OGLplus (0.52.0) a C++ wrapper for OpenGL

utf8.hpp
1 
12 #ifndef OGLPLUS_STRING_UTF8_1102101236_HPP
13 #define OGLPLUS_STRING_UTF8_1102101236_HPP
14 
15 #include <oglplus/config/compiler.hpp>
16 #include <cstddef>
17 #include <cassert>
18 #include <vector>
19 
20 namespace oglplus {
21 namespace aux {
22 
23 typedef char32_t UnicodeCP;
24 
25 std::size_t UTF8BytesRequired(const UnicodeCP* cp_str, std::size_t len);
26 
27 void ConvertCodePointToUTF8(UnicodeCP cp, char* str, std::size_t& len);
28 
29 void ConvertCodePointsToUTF8(
30  const UnicodeCP* cps,
31  std::size_t len,
32  std::vector<char>& result
33 );
34 
35 std::size_t CodePointsRequired(const char* str, std::size_t len);
36 
37 UnicodeCP ConvertUTF8ToCodePoint(
38  const char* str,
39  std::size_t len,
40  std::size_t& cp_len
41 );
42 
43 void ConvertUTF8ToCodePoints(
44  const char* str,
45  std::size_t len,
46  std::vector<UnicodeCP>& result
47 );
48 
49 class UTF8Validator
50 {
51 protected:
52  static bool _is_valid_ptr(const char* _s);
53  static unsigned char byte(const char* _i);
54 
55  template <int N>
56  static void _check_seq_tail(const char* _s)
57  {
58  for(int i=1; i!=N; ++i)
59  {
60  assert(byte(_s) != 0x00);
61  assert(byte(_s) != 0x80);
62  ++_s;
63  }
64  }
65 
66  // Validates the utf8 string, returns _end or nullptr
67  static const char* _validate(const char* _s, const char* _end);
68 public:
69  bool operator()(const char* begin, const char* end) const
70  {
71  return _validate(begin, end) == end;
72  }
73 };
74 
75 inline bool ValidUTF8(const char* begin, const char* end)
76 {
77 #if !OGLPLUS_NO_UTF8_CHECKS
78  UTF8Validator valid_utf8;
79  return valid_utf8(begin, end);
80 #else
81  OGLPLUS_FAKE_USE(begin);
82  OGLPLUS_FAKE_USE(end);
83  return true;
84 #endif
85 }
86 
87 } // namespace aux
88 } // namespace oglplus
89 
90 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
91 #include <oglplus/string/utf8.ipp>
92 #endif // OGLPLUS_LINK_LIB
93 
94 #endif

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).