Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #82799
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Can anyone improve this ? |
| Date | 2022-01-17 10:13 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <86iluis01j.fsf@linuxsc.com> (permalink) |
| References | (1 earlier) <srkqk6$mtr$1@dont-email.me> <srmkil$pjh$2@dont-email.me> <87ee5d6ny8.fsf@bsb.me.uk> <86pmortp6q.fsf@linuxsc.com> <4a8780c9-19a5-43af-935d-9ccf756014f4n@googlegroups.com> |
Tiib <ootiib@hot.ee> writes:
> On Sunday, 16 January 2022 at 22:13:01 UTC+2, Tim Rentsch wrote:
>
>> Ben Bacarisse <ben.u...@bsb.me.uk> writes:
>>
>>> Bonita Montero <Bonita....@gmail.com> writes:
>>>
>>>> sizes instead of size; corrected:
>>>>
>>>> size_t utf8Strlen( char const *str )
>>>> {
>>>> static size_t const sizes[8] = { 1, 0, 2, 3, 4, 0, 0, 0 };
>>>> size_t len = 0;
>>>> for( unsigned char c; (c = *str); )
>>>> {
>>>> size_t size = sizes[countl_zero<unsigned char>( ~c )];
>>>> if( !size ) [[unlikely]]
>>>> return -1;
>>>> ++len;
>>>> for( char const *cpEnd = str + size; ++str != cpEnd; )
>>>> if( ((unsigned char)*str & 0x0C0) != 0x080 ) [[unlikely]]
>>>> return -1;
>>>> }
>>>> return len;
>>>> }
>>>
>>> You reject simpler solutions because they don't detect the one error
>>> you have decided to look for. There are other encoding errors that
>>> this code won't catch. Seems a bit arbitrary to me. [...]
>>
>> (Sorry, accidental send)
>> I wouldn't say arbitrary. The function verifies that its input is
>> syntactically well-formed while ignoring the question of whether it
>> is semantically well-formed. That choice may not be ideal but I
>> don't think it's totally unreasonable.
>
> With complicated syntax and semantics it makes sense
> as the issues are easier to reason about in separation and the
> expectations of users to diagnostics are also quite high.
>
> UTF-8 is usually produced by software. It takes not too lot of
> code to detect all issues in it. Usually the symbol ? is shown
> as "diagnostic" for any issue in Unicode. [...]
>
> So if some problem involving UTF-8 needs only half of error
> checking then it is fair to expect it been said in problem
> description.
Yes, I know you have no shortage of strong opinions.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can anyone improve this ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-01-11 09:08 +0100
Re: Can anyone improve this ? Juha Nieminen <nospam@thanks.invalid> - 2022-01-11 09:50 +0000
Re: Can anyone improve this ? Juha Nieminen <nospam@thanks.invalid> - 2022-01-11 11:07 +0000
Re: Can anyone improve this ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-01-11 11:08 +0000
Re: Can anyone improve this ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-01-11 18:28 +0100
Re: Can anyone improve this ? Christian Gollwitzer <auriocus@gmx.de> - 2022-01-11 18:41 +0100
Re: Can anyone improve this ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-01-11 19:36 +0100
Re: Can anyone improve this ? Öö Tiib <ootiib@hot.ee> - 2022-01-11 21:54 -0800
Re: Can anyone improve this ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-01-11 21:51 +0100
Re: Can anyone improve this ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-01-12 14:19 +0100
Re: Can anyone improve this ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-01-12 14:20 +0100
Re: Can anyone improve this ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-01-12 14:14 +0000
Re: Can anyone improve this ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-01-12 17:20 +0100
Re: Can anyone improve this ? "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2022-01-12 08:38 -0800
Re: Can anyone improve this ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-01-12 16:55 +0000
Re: Can anyone improve this ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-01-16 12:09 -0800
Re: Can anyone improve this ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-01-16 12:12 -0800
Re: Can anyone improve this ? Öö Tiib <ootiib@hot.ee> - 2022-01-16 13:00 -0800
Re: Can anyone improve this ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-01-17 10:13 -0800
Re: Can anyone improve this ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-01-17 10:28 -0800
Re: Can anyone improve this ? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-01-17 21:51 +0100
Re: Can anyone improve this ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-01-17 16:16 -0800
Re: Can anyone improve this ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-01-17 22:43 -0800
Re: Can anyone improve this ? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-01-18 12:09 +0100
Re: Can anyone improve this ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-01-18 09:18 +0100
csiph-web