August 02, 2017 Re: all OS functions should be "nothrow @trusted @nogc" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Wednesday, 2 August 2017 at 16:32:44 UTC, Andrei Alexandrescu wrote:
>>> import std.algorithm;
>>> // I probably wouldn't even define this but use the body as is
>>> auto strnlen_safe(in char[] str)
>>> {
>>> return countUntil(cast(ubyte[]) str, '\0');
>>> }
>>
>> Oh that cast.... it irks me so.
>>
>> -Steve
>
> return str.representation.countUntil('\0');
>
Thanks, wasn't aware of this; it makes auto decoding slightly more bearable.
|
Copyright © 1999-2021 by the D Language Foundation