On 23/07/10 13:03, Paolo Bonzini wrote:
> On 07/23/2010 09:21 AM, Bruno Haible wrote:
>> Otherwise fine, please commit. I can add comments that prove the
>> validity of
>> the code later, after you committed it.
> 
> v2 already had large comments that detail the algorithm used and do
> include all the info in the comments you suggested.  Feel free to add
> more to it.
> 
> I pushed it now, thanks for the review!

I would suggest a new function due to the
way I see this function called most often.
I.E. repeatedly with the same character.

/* definitely not sure of this name */
uint8_t *
u8_str_u8_chr (const uint8_t *s, const uint8_t *c, size_t size)
{
  switch (size):
    {
    case 1:
      return (uint8_t *) strchr ((const char *) s, *c);
    case 2:
      //use logic from current u8_strchr()
    case 3:
      ...
    case 4:
      ...
    }
}

Then that can be called by u8_strchr():

uint8_t *
u8_strchr (const uint8_t *s, ucs4_t uc)
{
  if (uc < 0x80)
    return (uint8_t *) strchr ((const char *) s, uc);
  else
    {
      uint8_t c[6];
      size_t size = u8_uctomb_aux (c, uc, sizeof c);
      return u8_str_u8_chr (s, c, size);
    }
}

Note these performance and interface suggestions
apply to u8_strrchr() also.

cheers,
Pádraig.

Reply via email to