Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #123058

Re: A nice "strlen()" for UTF-8 ...

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c++
Subject Re: A nice "strlen()" for UTF-8 ...
Date 2025-11-23 18:18 +0100
Organization A noiseless patient Spider
Message-ID <10fvfli$1k0h9$1@dont-email.me> (permalink)
References <10fkf0b$28ebt$1@raubtier-asyl.eternal-september.org> <10fp024$3fe4a$1@dont-email.me> <10fpc55$3ibol$1@raubtier-asyl.eternal-september.org> <mogclfF8c16U1@mid.individual.net> <10fvd3m$1j7vg$2@raubtier-asyl.eternal-september.org>

Show all headers | View raw


On 23/11/2025 17:35, Bonita Montero wrote:
> Am 23.11.2025 um 13:22 schrieb Alfred Peters:
>> 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.
> That's your definition.

No, it is the Unicode definition.  See 
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G2212>

> Each UTF-8 character is also a code point and is built with a varying 
> number of characters.
Some code points do not represent characters - they can be 
noncharacters, reserved, surrogates, etc. Some Unicode characters 
require more than one code point, such as those that need combining 
diacritical marks.  Some Unicode characters can be found at more than 
one code point.  Some Unicode characters can be represented as either a 
single code point or a combination (again, accented letters or other 
diacriticals are common cases here).

Trying to pin down what a Unicode "character" is turns out to be very 
difficult, and does not match what people usually think of as 
characters.  But one thing that we can be sure about, is that Unicode 
characters and Unicode code points are not synonymous.

Counting Unicode characters is a very difficult task.  Counting code 
points is much simpler and more clearly specified.  Neither task is 
normally particularly useful - they don't tell you much about space 
usage that can be helpful for things like memory allocation, and they 
don't tell you much about the size taken on screens or when printed out.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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