On Wed, Jan 23, 2013 at 04:59:23PM +0100, Vladimir Pantelic wrote:
>>From d09072fcdfdbf7d5aa860e60a7e8697a999de820 Mon Sep 17 00:00:00 2001
> From: Vladimir Pantelic <[email protected]>
> Date: Wed, 23 Jan 2013 16:56:16 +0100
> Subject: [PATCH] lavu: Add av_strnstr()
> 
> This is a length limited version of strstr()

.

> --- a/Changelog
> +++ b/Changelog
> @@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest 
> within each release,
>  releases are sorted from youngest to oldest.
>  
>  version 9:
> +- av_strnstr
>  - av_basename and av_dirname
>  - adobe and limelight publisher authentication in RTMP
>  - VDPAU hardware acceleration through normal hwaccel

Quoting from directly above where you added this entry:


  Entries are sorted chronologically from oldest to youngest within
  each release, releases are sorted from youngest to oldest.

:-)

> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -13,6 +13,9 @@ libavutil:     2012-10-22
>  
>  API changes, most recent first:
>  
> +2013-01-xx - xxxxxxx - lavu 52.6.0 - avstring.h
> +  Add av_strnstr()

.

> --- a/libavutil/avstring.c
> +++ b/libavutil/avstring.c
> @@ -64,6 +64,22 @@ char *av_stristr(const char *s1, const char *s2)
>  
> +char *av_strnstr(const char *s1, const char *s2, size_t len)
> +{
> +        size_t l2;
> +
> +        l2 = strlen(s2);
> +        if (!l2)
> +                return s1;
> +        while (len >= l2) {
> +                len--;
> +                if (!memcmp(s1, s2, l2))
> +                        return s1;
> +                s1++;
> +        }
> +        return NULL;
> +}

Indentation level is twice what it should be.  Doesn't this generate
warnings when you return those const pointers?  Also, all hail for
non-descriptive variable names :)

Here's my version, slightly more compact ;)

  char *av_strnstr(const char *haystack, const char *needle, size_t 
haystack_size);
  {
      size_t needle_len = strlen(needle);
      if (!needle_len)
          return haystack;
      for (; len >= needle_len; len--, haystack++)
          if (!memcmp(haystack, needle, needle_len))
              return haystack;
      return NULL;
  }

> --- a/libavutil/avstring.h
> +++ b/libavutil/avstring.h
> @@ -67,6 +67,21 @@ int av_stristart(const char *str, const char *pfx, const 
> char **ptr);
>  char *av_stristr(const char *haystack, const char *needle);
>  
>  /**
> + * Locate the first occurrence in the string haystack of the string needle
> + * where not more than length characters are searched. 

  Locate the first occurrence of the string needle in the first length
  characters of the string haystack.

There is some doxygen syntax to markup parameters that might help here.

> + * where not more than length characters are searched. A zero-length string

> + * This function is a length limited version of the standard strstr().

length-limited

> + * @param haystack string to search in
> + * @param needle   string to search for
> + * @param length   length of string to search in
> + * @return         pointer to the located match within haystack

pointer to the first match within the haystack

> + *                 or a null pointer if no match

NULL

> + */
> +char *av_strnstr(const char *haystack, const char *needle, size_t 
> haystack_size);

nit: break the line

The parameter names of the declaration don't match the definition, nor the
doxygen ...

Diego
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to