Skip to content
Snippets Groups Projects
Commit f8cde3fa authored by John Hodge (sonata)'s avatar John Hodge (sonata)
Browse files

Usermode/libunicode - Add C++ wrappers

parent 0bdeb975
Branches
No related merge requests found
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* \breif Read a single codepoint from a UTF-8 stream * \breif Read a single codepoint from a UTF-8 stream
* \return Number of bytes read * \return Number of bytes read
...@@ -27,5 +31,102 @@ extern int WriteUTF8(char *buf, uint32_t Val); ...@@ -27,5 +31,102 @@ extern int WriteUTF8(char *buf, uint32_t Val);
static inline int Unicode_IsPrinting(uint32_t Codepoint) { return 1; } static inline int Unicode_IsPrinting(uint32_t Codepoint) { return 1; }
#ifdef __cplusplus
} // extern "C"
#endif
#ifdef __cplusplus
#include <iterator>
namespace libunicode {
class utf8iterator:
public ::std::iterator< ::std::forward_iterator_tag, uint32_t >
{
const char* m_curpos;
uint32_t m_curval;
public:
utf8iterator():
m_curpos(0)
{
}
utf8iterator(const char *pos):
m_curpos(pos)
{
(*this)++;
}
utf8iterator(const utf8iterator& other) {
m_curpos = other.m_curpos;
m_curval = other.m_curval;
}
utf8iterator& operator=(const utf8iterator& other) {
m_curpos = other.m_curpos;
m_curval = other.m_curval;
return *this;
}
bool operator== (const utf8iterator& other) {
return other.m_curpos == m_curpos;
}
bool operator!= (const utf8iterator& other) {
return other.m_curpos != m_curpos;
}
utf8iterator& operator++() {
m_curpos += ::ReadUTF8(m_curpos, &m_curval);
return *this;
}
utf8iterator operator++(int) {
utf8iterator rv(*this);
m_curpos += ::ReadUTF8(m_curpos, &m_curval);
return rv;
}
uint32_t operator*() const {
return m_curval;
}
uint32_t operator->() const {
return m_curval;
}
};
class utf8string
{
const char* m_data;
size_t m_len;
size_t _strlen(const char*s) {
size_t l = 0;
while(*s) l ++;
return l;
}
public:
utf8string(const char* c_str):
m_data(c_str),
m_len(_strlen(c_str))
{
}
utf8string(const char* c_str, size_t len):
m_data(c_str),
m_len(len)
{
}
utf8string(const ::std::string& str):
m_data(str.c_str()),
m_len(str.size())
{
}
utf8iterator begin() const {
return utf8iterator(m_data);
}
utf8iterator end() const {
return utf8iterator(m_data + m_len);
}
};
};
#endif
#endif #endif
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment