Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #123056
| From | Alfred Peters <miteinere-mail-adresseindereinleitungszeilewirddieseoftzulang@geekmail.de> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: A nice "strlen()" for UTF-8 ... |
| Date | 2025-11-23 13:22 +0100 |
| Message-ID | <mogclfF8c16U1@mid.individual.net> (permalink) |
| References | <10fkf0b$28ebt$1@raubtier-asyl.eternal-september.org> <10fp024$3fe4a$1@dont-email.me> <10fpc55$3ibol$1@raubtier-asyl.eternal-september.org> |
Es schrieb einmal Bonita Montero:
> This code counts the number of UTF-8 characters.
Unfortunately, no. As someone in the other group already mentioned, it
only counts the number of code points.
I have rewritten main() slightly:
[...]
void testCount(char8_t strU8[])
{
string_view sv( (char *)strU8 );
cout<< sv << endl;
cout << utf8Width<false>( sv ) << endl;
cout << utf8Width<true>( sv ) << endl;
u8string_view svU8( strU8 );
cout << utf8Width<false>( svU8 ) << endl;
cout << utf8Width<true>( svU8 ) << endl;
}
int main()
{
char8_t strU8[] = u8"Hello, 世界!";
testCount( strU8 );
char8_t strU8_1[] = u8"V1: 'äöü'";
testCount(strU8_1);
char8_t strU8_2[] = u8"V2: 'äöü'";
testCount(strU8_2);
char8_t strU8_3[] = u8"'👩🏿❤️💋👨🏻'";
testCount(strU8_3);
}
// End of Code
utf8len.cpp --- Size: 1,5 KB
<https://www.dropbox.com/scl/fi/tiy4syytz5d0tvk3fau9g/utf8len.cpp?rlkey=4njtt4m1nvxdyr95pllvka3td&dl=0>
Result:
Screenshot 2025-11-23 124007.png --- Size: 58,4 KB
<https://www.dropbox.com/scl/fi/4zccn7262qudthb88gnoi/Screenshot-2025-11-23-124007.png?rlkey=3xu71czkiooujj86mfmlnao15&dl=0>
Unfortunately, the console does not display the last character
correctly. But you can see it correctly on the left side within the editor.
Alfred
--
🀋🀐🀃 🀄🀣 25894.6
🀛🀄🀋
🀩🀄🀄🀖🀖🀚🀚
🀛🀣🀃🀐🀩
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A nice "strlen()" for UTF-8 ... Bonita Montero <Bonita.Montero@gmail.com> - 2025-11-19 14:00 +0100
Re: A nice "strlen()" for UTF-8 ... Lynn McGuire <lynnmcguire5@gmail.com> - 2025-11-19 12:59 -0600
Re: A nice "strlen()" for UTF-8 ... Bonita Montero <Bonita.Montero@gmail.com> - 2025-11-20 15:25 +0100
Re: A nice "strlen()" for UTF-8 ... Lynn McGuire <lynnmcguire5@gmail.com> - 2025-11-21 00:15 -0600
Re: A nice "strlen()" for UTF-8 ... Bonita Montero <Bonita.Montero@gmail.com> - 2025-11-21 10:42 +0100
Re: A nice "strlen()" for UTF-8 ... Alfred Peters <miteinere-mail-adresseindereinleitungszeilewirddieseoftzulang@geekmail.de> - 2025-11-23 13:22 +0100
Re: A nice "strlen()" for UTF-8 ... Bonita Montero <Bonita.Montero@gmail.com> - 2025-11-23 17:35 +0100
Re: A nice "strlen()" for UTF-8 ... David Brown <david.brown@hesbynett.no> - 2025-11-23 18:18 +0100
Re: A nice "strlen()" for UTF-8 ... Bonita Montero <Bonita.Montero@gmail.com> - 2025-11-24 13:08 +0100
Re: A nice "strlen()" for UTF-8 ... David Brown <david.brown@hesbynett.no> - 2025-11-24 14:09 +0100
Re: A nice "strlen()" for UTF-8 ... Bonita Montero <Bonita.Montero@gmail.com> - 2025-11-24 14:31 +0100
Re: A nice "strlen()" for UTF-8 ... David Brown <david.brown@hesbynett.no> - 2025-11-24 15:45 +0100
Re: A nice "strlen()" for UTF-8 ... Bonita Montero <Bonita.Montero@gmail.com> - 2025-11-24 16:32 +0100
Re: A nice "strlen()" for UTF-8 ... Michael S <already5chosen@yahoo.com> - 2025-11-24 19:16 +0200
Re: A nice "strlen()" for UTF-8 ... David Brown <david.brown@hesbynett.no> - 2025-11-24 18:32 +0100
Re: A nice "strlen()" for UTF-8 ... Michael S <already5chosen@yahoo.com> - 2025-11-24 19:51 +0200
Re: A nice "strlen()" for UTF-8 ... Michael S <already5chosen@yahoo.com> - 2025-11-24 19:54 +0200
Re: A nice "strlen()" for UTF-8 ... David Brown <david.brown@hesbynett.no> - 2025-11-24 21:14 +0100
Re: A nice "strlen()" for UTF-8 ... Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2025-11-24 12:53 +0000
csiph-web