2 * Acess2 "libunicode" UTF Parser
3 * - By John Hodge (thePowersGang)
8 #ifndef _LIBUNICODE__UNICODE_H_
9 #define _LIBUNICODE__UNICODE_H_
18 * \breif Read a single codepoint from a UTF-8 stream
19 * \return Number of bytes read
21 extern int ReadUTF8(const char *Input, uint32_t *Val);
23 * \brief Read backwards in the stream
25 extern int ReadUTF8Rev(const char *Base, int Offset, uint32_t *Val);
27 * \breif Write a single codepoint to a UTF-8 stream
29 extern int WriteUTF8(char *buf, uint32_t Val);
32 static inline int Unicode_IsPrinting(uint32_t Codepoint) { return 1; }
41 namespace libunicode {
44 public ::std::iterator< ::std::forward_iterator_tag, uint32_t >
53 utf8iterator(const char *pos):
58 utf8iterator(const utf8iterator& other) {
59 m_curpos = other.m_curpos;
60 m_curval = other.m_curval;
62 utf8iterator& operator=(const utf8iterator& other) {
63 m_curpos = other.m_curpos;
64 m_curval = other.m_curval;
68 bool operator== (const utf8iterator& other) {
69 return other.m_curpos == m_curpos;
71 bool operator!= (const utf8iterator& other) {
72 return other.m_curpos != m_curpos;
74 utf8iterator& operator++() {
75 m_curpos += ::ReadUTF8(m_curpos, &m_curval);
78 utf8iterator operator++(int) {
79 utf8iterator rv(*this);
80 m_curpos += ::ReadUTF8(m_curpos, &m_curval);
83 uint32_t operator*() const {
86 uint32_t operator->() const {
96 size_t _strlen(const char*s) {
102 utf8string(const char* c_str):
104 m_len(_strlen(c_str))
107 utf8string(const char* c_str, size_t len):
112 utf8string(const ::std::string& str):
118 utf8iterator begin() const {
119 return utf8iterator(m_data);
121 utf8iterator end() const {
122 return utf8iterator(m_data + m_len);