Mar 23, 2022 at 9:31pm UTC
jonnin -- I don't think he needs to be using wide strings. That's just for Windows API compatibility stuff.
bydrachen -- The character counts are wrong because you're still using strlen instead of the implementation discussed in the Stack Overflow page I previously linked.
Mar 23, 2022 at 9:33pm UTC
L is a 'prefix' -- there are several of these -- it converts a string literal to widechar. But as said I dunno if you need to be doing these things.
Mar 23, 2022 at 9:35pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include <iostream>
// // https://stackoverflow.com/a/3586973
int utf8_strlen(const char * str)
{
int count = 0;
while (*str != 0)
{
if ((*str & 0xc0) != 0x80)
++count;
++str;
}
return count;
}
int main()
{
char my_string [][60]
{
{"ù322dA@@kyUMGyy3t5u7UMEy~{yyEC€}{y6(y6(y6(y4ty67" },
{"6(y6(y6(y6(y6(y6(y6(3y6(3y6(3yEk€}|y1#+y15dff67fgg3ddd)=?" },
{"#+y1#+y1#+y1#+y1#+y1#+y1#+y1#+y1#+y1#+y1#&&%(JK33Y)(" },
{"+yrmjyJIHkGFFk|zxy.y-y-njfy5'y0\"y,y+37y+33cuy[}s43" },
{"7y+37y+37yy+37y+y+ykgc#+y1#+y6(6(3yE37y-65/gt46&" }
};
for (int i = 0; i < 5; i++)
{
std::cout << "utf8_strlen = " << utf8_strlen(my_string[i]) << '\n' ;
}
}
Last edited on Mar 23, 2022 at 9:40pm UTC
Mar 24, 2022 at 6:57pm UTC
Thanks for your help. I learned a lot.