我正在尝试将带有特殊引号符号的utf-8字符串转换为Latin1。代码在Windows上运行完美,但省略了g ++上的符号(Ubuntu 5.4.0-6ubuntu1~16.04.4)5.4.0
字符串:Latin1:APOST(')QUOTE(“)(«»)
Windows:Latin1:APOST(')QUOTE(“)(<>)
Ubuntu:Latin1:APOST()QUOTE()()
转换字符串的十六进制表示形式:
HW: 41 50 4F 53 54 20 28 20 27 20 29 20 51 55 4F 54 45 20 28 20 22 20 29 20 28 20 3C 20 3E 20 29
HU: 41 50 4F 53 54 20 28 20 20 29 20 51 55 4F 54 45 20 28 20 20 29 20 28 20 20 20 29
const unsigned char utf8[] = { 0x41, 0x50, 0x4f, 0x53, 0x54, 0x20, 0x28, 0x20, 0xe2, 0x80, 0x98, 0x20, 0x29, 0x20, 0x51, 0x55, 0x4f, 0x54, 0x45, 0x20, 0x28, 0x20, 0xe2, 0x80, 0x9c, 0x20, 0x29, 0x20, 0x28, 0x20, 0xc2, 0xab, 0x20, 0xc2, 0xbb, 0x20, 0x29, 0x00 };
boost::locale::generator loc_g;
std::string ansi0 = boost::locale::conv::from_utf<char>((const char*)utf8, loc_g.generate("Latin1"));
printf("Latin1: %s", ansi0.c_str());
如何获得类似于Windows的Ubuntu结果?
使用iconv
在Ubuntu上的结果ASCII: APOST ( ' ) QUOTE ( " ) ( << >> )
Latin1: APOST ( ` ) QUOTE ( " ) ( . . )
ISO-8859-1: APOST ( ` ) QUOTE ( " ) ( . . )