httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roy T. Fielding" <field...@liege.ICS.UCI.EDU>
Subject Re: Closing strcasestr discussion...
Date Fri, 12 Jul 1996 10:16:29 GMT
> So, if I had to vote it would be +1 for this routine:
> 
> char *strcasestr( char *s1, char *s2 )
> {
>     int len = strlen(s2);
>     while (*s1) {
>         if (!strncasecmp(s1, s2, len))
>             return s1;
>         s1++;
>     }
>     return NULL;
> }
> 
> CASE CLOSED... :)  (finally!)

Hmmm, then I suppose this one would be out of line ....

  char *strcasestr( char *s1, char *s2 )
  {
      int len1 = strlen(s1);
      int len2 = strlen(s2);
      while (*s1 && (len1 >= len2)) {
          if (!strncasecmp(s1, s2, len2))
              return s1;
          s1++;
          len1--;
      }
      return NULL;
  }

........Roy     ;-p

p.s. relative performance in this case will depend on the test sample.  :)

Mime
View raw message