+// takes a pointer into a utf8 string and returns a unicode character for the
+// first character at the pointer
+unichar utf8_get_char (const char *p)
+{
+ unichar result = static_cast<unsigned char>(*p);
+
+ // if its not a 7-bit ascii character
+ if((result & 0x80) != 0) {
+ // len is the number of bytes this character takes up in the string
+ unsigned char len = utf8_skip[result];
+ result &= 0x7F >> len;
+
+ while(--len != 0) {
+ result <<= 6;
+ result |= static_cast<unsigned char>(*++p) & 0x3F;
+ }
+ }
+
+ return result;
+}
+
+// takes a pointer into a string and finds its offset
+static ustring::size_type utf8_ptr_to_offset(const char *str, const char *pos)