cmp and icmp.
Damian
damianday at hotmail.co.uk
Thu Jul 4 15:36:02 PDT 2013
On Thursday, 4 July 2013 at 22:02:06 UTC, bearophile wrote:
> Damian:
>
>> Why don't these functions take a length parameter, like strcmp
>> and memcmp?
>> Is it worth making an enhancement request for such?
>
> Probably slicing of their inputs, or using std.range.take() of
> their inputs, is enough. Do you agree?
>
> Bye,
> bearophile
Ah but with slicing the inputs, you must check the length first
so that you don't get an out of bounds error. I would prefer it
if cmp
did this for me, since it is going to check lengths anyway.
Example below.
private void ParsePacket(in char[] data)
{
static string Good = "GOOD";
static string Bad = "BAD";
if (data.length >= Good.length) // Prefer not to do this check
{
if (std.algorithm.cmp(data[0 .. Good.length], Good) == 0)
}
else if
{
// Check Bad, and so on
}
}
More information about the Digitalmars-d
mailing list