gpt4 book ai didi

c++ - libcurl 中的波兰变音符号 (c++)

转载 作者:太空宇宙 更新时间:2023-11-04 11:29:12 25 4
gpt4 key购买 nike

我只是遇到一个问题,其中包含 libcurl 从服务器获取的波兰语变音符号(例如 ą、ć、ę、ł、ń、ó、ś、ź、ż)。我正在尝试在 Windows C++ 控制台应用程序中正确显示此文本。

我通过将类似的内容放到控制台屏幕上解决了类似的问题:

cout << "ąćęźół";

通过将我的源文件的代码页切换为:DOS 代码页 852(中欧)。不幸的是,它不适用于从 libcurl 传递的文本。我认为它只适用于直接写入代码的文本。那你能告诉我一些有用的信息吗?我不知道如何解决这个问题。

最佳答案

好吧,我已经为我的问题编写了临时解决方案。它工作正常,但我不满足于这种方式:

char* cpl(const char* input)
{
size_t length = strlen(input);
char* output = new char[length+1];

/* Order of the diacretics
Ą ą Ć ć Ę ę
Ł ł Ń ń Ó ó
Ś ś Ź ź Ż ż
*/
const size_t pld_in[] = {
0xA1,0xB1,0xC6,0xE6,0xCA,0xEA,
0xA3,0xB3,0xD1,0xF1,0xD3,0xF3,
0xA6,0xB6,0xAC,0xBC,0xAF,0xBF,
};
const size_t pld_out[] = {
0xA4,0xA5,0x8F,0x86,0xA8,0xA9,
0x9D,0x88,0xE3,0xE4,0xE0,0xA2,
0x97,0x98,0x8D,0xAB,0xBD,0xBE
};

for(size_t i = 0; i < length; i++)
{
bool modified = false;
for(size_t j = 0; j < 18; j++)
{
if(*(input + i) == (*(pld_in + j)) + 0xFFFFFF00)
{
*(output + i) = *(pld_out + j);
modified = true;
break;
}
}
if(!modified)
*(output + i) = *(input + i);
}
*(output + length) = 0x00;

return output;
}

你能提出更好的解决这个问题的方法吗?

关于c++ - libcurl 中的波兰变音符号 (c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25477361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com