summaryrefslogtreecommitdiff
path: root/boost/spirit/home/support/utf8.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/spirit/home/support/utf8.hpp')
-rw-r--r--boost/spirit/home/support/utf8.hpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/boost/spirit/home/support/utf8.hpp b/boost/spirit/home/support/utf8.hpp
index c4883428b1..8b67f505e5 100644
--- a/boost/spirit/home/support/utf8.hpp
+++ b/boost/spirit/home/support/utf8.hpp
@@ -67,6 +67,44 @@ namespace boost { namespace spirit
}
return result;
}
+
+ // Assume wchar_t content is UTF-16 on Windows and UCS-4 on Unix
+#if defined(_WIN32) || defined(__CYGWIN__)
+ inline utf8_string to_utf8(wchar_t value)
+ {
+ 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);
+
+ u16_to_u32_iterator<wchar_t const*, ucs4_char> ucs4_iter(&value);
+ *utf8_iter++ = *ucs4_iter;
+
+ return result;
+ }
+
+ inline utf8_string to_utf8(wchar_t const* str)
+ {
+ 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);
+
+ u16_to_u32_iterator<wchar_t const*, ucs4_char> ucs4_iter(str);
+ for (ucs4_char c; (c = *ucs4_iter) != ucs4_char(); ++ucs4_iter) {
+ *utf8_iter++ = c;
+ }
+
+ return result;
+ }
+
+ template <typename Traits, typename Allocator>
+ inline utf8_string
+ to_utf8(std::basic_string<wchar_t, Traits, Allocator> const& str)
+ {
+ return to_utf8(str.c_str());
+ }
+#endif
}}
#endif