assuming that I have
uint32_t a(3084);
I would like to create a string that stores the unicode character U+3084
which means that I should take the value of a
and use it as the coordinate for the right character in the UTF8 table/charset.
Now, clearly std::to_string()
doesn't work for me, there are a lot of functions in the standard to convert between numeric values and char, I can't find anything that grants me UTF8 support and outputs an std::string
.
I would like to ask if I have to create this function from scratch or there is something in the C++11 standard that can help me with that; please note that my compiler ( gcc/g++ 4.8.1 ) doesn't offer a complete support for codecvt
.
prints
for me (using g++ 4.8.1).
s
has typeconst char*
, as you'd expect, but I don't know if this is implementation defined. Unfortunately C++ doesn't have any support for manipulation of UTF8 strings are far as I know; for that you need to use a library likeGlib::ustring
.Here's some C++ code that wouldn't be hard to convert to C. Adapted from an older answer.
std::string_convert::to_bytes has a single-char overload just for you.
I get (with libc++)
The C++ standard contains the
std::codecvt<char32_t, char, mbstate_t>
facet which converts between UTF-32 and UTF-8 according to 22.4.1.4 [locale.codecvt] paragraph 3. Sadly, thestd::codecvt<...>
facets aren't easy to use. At some point there was discussion about filtering stream buffers which would take case of the code conversion (the standard C++ library needs to implement them anyway forstd::basic_filebuf<...>
) but I can't see any trace of these.