我想知道如何编写在 C++ 中执行 UTF-8 到拉丁语(ISO-8859-1)转换的代码。
以下网站进行所需的转换: http ://www.unicodetools.com/unicode/utf8-to-latin-converter.php
插入值:úsername
提供结果:用户名
我有一段代码与上一篇文章类似,但似乎没有转换字符串
int utf8_to_unicode(std::deque<int> &coded)
{
int charcode = 0;
int t = coded.front();
coded.pop_front();
if (t < 128)
{
return t;
}
int high_bit_mask = (1 << 6) -1;
int high_bit_shift = 0;
int total_bits = 0;
const int other_bits = 6;
while((t & 0xC0) == 0xC0)
{
t <<= 1;
t &= 0xff;
total_bits += 6;
high_bit_mask >>= 1;
high_bit_shift++;
charcode <<= other_bits;
charcode |= coded.front() & ((1 << other_bits)-1);
coded.pop_front();
}
charcode |= ((t >> high_bit_shift) & high_bit_mask) << total_bits;
return charcode;
}
请帮忙!