[FFmpeg-devel] [PATCH] move cutils string functions to libavutil
Michael Niedermayer
michaelni
Fri Jun 22 18:52:24 CEST 2007
Hi
On Fri, Jun 22, 2007 at 03:27:46PM +0200, Benoit Fouet wrote:
> M?ns Rullg?rd wrote:
> > Benoit Fouet wrote:
> >
> >> Hi,
> >>
> >> as M?ns suggested, here is an attempt to move some cutils functions to
> >> libavutil.
> >> once this patch is applied, a second one will come to call those new
> >> functions instead of the old ones.
> >>
> >
> > I don't see anything obviously wrong, but I only had a quick look.
> >
>
> re reading my patch, i found out that the doxy comment i added for
> av_pstrcat was not accurate, i changed it
>
> > I'm a bit skeptical to the filename cutils.c though, it being quite
> > vague. Since it contains string manipulation functions, string.c
> > would seem a more logical choice.
> >
> >
>
> i'm opened to any name :)
> if it's ok for string(s).c, i'll go for it, this is just a matter of
> file name
>
> >> i hesitated about small_strptime, does it bleong to avutil too ?
> >>
> >
> > I guess that depends on what it does.
> >
> >
>
> it seems to "convert a string representation of time to a time tm
> structure" (from man 3 strptime)
>
> new patch attached (still named cutils.c for the moment, but can (and
> will) change)
[...]
> Index: libavformat/cutils.c
> ===================================================================
> --- libavformat/cutils.c (revision 9385)
> +++ libavformat/cutils.c (working copy)
> @@ -19,6 +19,7 @@
> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> */
> #include "avformat.h"
> +#include "avutil.h"
>
> #if !defined(CONFIG_NOCUTILS)
> /**
> @@ -29,21 +30,11 @@
> * @param val prefix to test
> * @param ptr updated after the prefix in str in there is a match
> * @return TRUE if there is a match
> + * @deprecated use av_strstart instead
> */
> int strstart(const char *str, const char *val, const char **ptr)
> {
> - const char *p, *q;
> - p = str;
> - q = val;
> - while (*q != '\0') {
> - if (*p != *q)
> - return 0;
> - p++;
> - q++;
> - }
> - if (ptr)
> - *ptr = p;
> - return 1;
> + return av_strstart(str, val, ptr);
> }
dont even think about moving this trash into libavutil!
this can be implemented in half the code
and iam not sure if it even belongs into libavutil
>
> /**
> @@ -54,21 +45,12 @@
> * @param str input string
> * @param val prefix to test
> * @param ptr updated after the prefix in str in there is a match
> - * @return TRUE if there is a match */
> + * @return TRUE if there is a match
> + * @deprecated use av_stristart instead
> + */
> int stristart(const char *str, const char *val, const char **ptr)
> {
> - const char *p, *q;
> - p = str;
> - q = val;
> - while (*q != '\0') {
> - if (toupper(*(const unsigned char *)p) != toupper(*(const unsigned char *)q))
> - return 0;
> - p++;
> - q++;
> - }
> - if (ptr)
> - *ptr = p;
> - return 1;
> + return av_stristart(str, val, ptr);
> }
toupper? isnt that locale specific?
and the implementation is trash too
>
> /**
> @@ -80,32 +62,20 @@
> * @param buf destination buffer
> * @param buf_size size of destination buffer
> * @param str source string
> + * @deprecated use av_pstrcpy instead
> */
> void pstrcpy(char *buf, int buf_size, const char *str)
> {
> - int c;
> - char *q = buf;
> -
> - if (buf_size <= 0)
> - return;
> -
> - for(;;) {
> - c = *str++;
> - if (c == 0 || q >= buf + buf_size - 1)
> - break;
> - *q++ = c;
> - }
> - *q = '\0';
> + av_pstrcpy(buf, buf_size, str);
> }
the int c declaration should be moved into the loop
the q var is unneeded
>
> /* strcat and truncate. */
> +/**
> + * @deprecated use av_pstrcat instead
> + */
> char *pstrcat(char *buf, int buf_size, const char *s)
> {
> - int len;
> - len = strlen(buf);
combine these
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070622/e986a1bb/attachment.pgp>
More information about the ffmpeg-devel
mailing list