On Fri, 30 Oct 2020, Riccardo (Jack) Lucchetti wrote:
On Fri, 30 Oct 2020, Sven Schreiber wrote:
> Am 12.10.2020 um 19:24 schrieb Sven Schreiber:
>> Am 06.10.2020 um 15:28 schrieb Allin Cottrell:
>>>
>>> And talking about undocumented extensions, maybe we should mention
>>> that nelem() can be applied to strings, in which case it returns the
>>> number of bytes as opposed to the number of UTF-8 characters. Or we
>>> could get rid of that.
>>>
>> I think it would be good (and easy) to just add a note to the strlen
>> information, where it currently is silent about how to actually count
>> the bytes. No reason to scrap it AFAICS.
>>
> Are you guys OK with an additional sentence in the 'strlen' reference
> like this: "If you actually wish to count the number of bytes that the
> string takes, you can use the 'nelem' function."
>
> I could add that.
I would rephrase this as follows:
(current version)
Note that this does not equal the number of bytes if some characters are
outside of the printable-ASCII range.
(proposal)
Note that this does not equal the number of bytes if some characters are
outside of the printable-ASCII range; if this is what you want, you can use
the nelem() function.
I'd say that "if this is what you want" is a bit ambiguous in
context: what about: "if you want the number of bytes", with the
rest of Jack's text as is.
and maybe add an example:
<hansl>
string s = "¡Olé!"
printf "strlen(s) = %d, nelem(s) = %d\n", strlen(s), nelem(s)
</hansl>
Yes, good idea.
Allin