On Tuesday, 28 June 2016 at 03:58:23 UTC, Jay Norwood wrote:
On Tuesday, 28 June 2016 at 03:11:26 UTC, Jay Norwood wrote:
On Tuesday, 28 June 2016 at 01:53:22 UTC, deadalnix wrote:
If we were in interview, I'd ask you "what does this returns if you pass it an empty string ?"


oops.  I see ... need to test for empty string.

nothrow pure size_t strlen2(const(char)* c) {
  if (c is null || *c==0)
     return 0;
  const(char)* c_save = c;
  while (*c){ c+=4; }
  while (*c==0){ c--; }
  c++;
  return c - c_save;
}

Why not just do

nothrow pure size_t strlen2(const(char)* c) {
  if (!c)
    return 0;

  ...
}

Reply via email to