How do you convert an std::string encoded in extended ascii to utf8 using microsoft visual studio 2005?
I'm using google protocol buffer and it's complaining about non utf8 characters in my string if I give it without conversion, which is true...
How do you convert an std::string encoded in extended ascii to utf8 using microsoft visual studio 2005?
I'm using google protocol buffer and it's complaining about non utf8 characters in my string if I give it without conversion, which is true...
Use MultiByteToWideChar to convert your string to UTF-16, then use WideCharToMultiByte to convert it to UTF-8.
Let's assume that mysterious Exntended ASCII is just Latin1. Then use mask from wikipedia:
110y yyxx 10xx xxxx
Since you have only 00..FF then you have: 1100 00xx 10xx xxxx
.
Conversion algorithm will be following, if char code is < 127 then just dump it as is, if it is > 127 then you do 0xC0 | ((x & 0xC0) >> 24)
goes to first byte, second is ((x & 0x3F) | 0x80)