inline utf8_string to_utf8(Char value) { // always store as UTF8 utf8_string result; typedef std::back_insert_iterator<utf8_string> insert_iter; insert_iter out_iter(result); utf8_output_iterator<insert_iter> utf8_iter(out_iter); typedef typename make_unsigned<Char>::type UChar; *utf8_iter = (UChar)value; return result; }
char *match(char *expr_, char *text_, char **end) { struct utf8_iter expr; struct utf8_iter text; utf8_iter(&expr, expr_); utf8_iter(&text, text_); utf8_next(&text); if (utf8_next(&expr) == '^') { utf8_next(&expr); return match_here(expr, text, end) ? text.head : NULL; } do if (match_here(expr, text, end)) return text.head; while (text.chr != 0 && utf8_next(&text)); return NULL; }
inline utf8_string to_utf8(Char const* str) { // always store as UTF8 utf8_string result; typedef std::back_insert_iterator<utf8_string> insert_iter; insert_iter out_iter(result); utf8_output_iterator<insert_iter> utf8_iter(out_iter); typedef typename make_unsigned<Char>::type UChar; while (*str) *utf8_iter++ = (UChar)*str++; return result; }
inline utf8_string to_utf8(std::basic_string<Char, Traits, Allocator> const& str) { // always store as UTF8 utf8_string result; typedef std::back_insert_iterator<utf8_string> insert_iter; insert_iter out_iter(result); utf8_output_iterator<insert_iter> utf8_iter(out_iter); typedef typename make_unsigned<Char>::type UChar; BOOST_FOREACH(Char ch, str) { *utf8_iter++ = (UChar)ch; }