[FFmpeg-devel] [PATCH 2/4] Make strmatch() return 1 only if the string compared against the prefix does not contain other characters which may belong to an identifier.

Stefano Sabatini stefano.sabatini-lala
Sun Oct 31 23:37:36 CET 2010


On date Sunday 2010-10-31 21:48:37 +0100, Michael Niedermayer encoded:
> On Sun, Oct 31, 2010 at 04:40:19PM +0100, Stefano Sabatini wrote:
> > On date Sunday 2010-10-31 16:25:36 +0100, Michael Niedermayer encoded:
> > > On Sun, Oct 31, 2010 at 03:31:08PM +0100, Stefano Sabatini wrote:
> > > > On date Sunday 2010-10-31 11:28:02 +0100, Michael Niedermayer encoded:
> > > > > On Sun, Oct 31, 2010 at 01:30:56AM +0200, Stefano Sabatini wrote:
> > > > > > This allows to distinguish for example to have different constants
> > > > > > with the same prefix (e.g. "foo" and "foobar").
> > > > > > ---
> > > > > >  libavutil/eval.c |    4 +++-
> > > > > >  1 files changed, 3 insertions(+), 1 deletions(-)
> > > > > > 
> > > > > > diff --git a/libavutil/eval.c b/libavutil/eval.c
> > > > > > index 6e03498..27c1b6d 100644
> > > > > > --- a/libavutil/eval.c
> > > > > > +++ b/libavutil/eval.c
> > > > > > @@ -103,13 +103,15 @@ double av_strtod(const char *numstr, char **tail)
> > > > > >      return d;
> > > > > >  }
> > > > > >  
> > > > > > +#define IDENTIFIER_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789"
> > > > > > +
> > > > > >  static int strmatch(const char *s, const char *prefix)
> > > > > >  {
> > > > > >      int i;
> > > > > >      for (i=0; prefix[i]; i++) {
> > > > > >          if (prefix[i] != s[i]) return 0;
> > > > > >      }
> > > > > > -    return 1;
> > > > > > +    return !strspn(s+i, IDENTIFIER_CHARS);
> > > > > 
> > > > > check the char ranges directly please, this is just slow
> > > > 
> > > > Updated.
> > > > -- 
> > > > FFmpeg = Faithful and Foolish Marvellous Picky Erudite Gospel
> > > 
> > > >  eval.c |    3 ++-
> > > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > > 065f69f749d3e06fcd98ff769110fbecdf0870ab  0004-Make-strmatch-return-1-only-if-the-string-compared-a.patch
> > > > From 062050ae543dd03b70b2203bd49f1caa7dc5a806 Mon Sep 17 00:00:00 2001
> > > > From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> > > > Date: Sun, 31 Oct 2010 01:27:25 +0200
> > > > Subject: [PATCH 4/8] Make strmatch() return 1 only if the string compared against the
> > > >  prefix does not contain other characters which may belong to an
> > > >  identifier.
> > > > 
> > > > This allows to distinguish for example to have different constants
> > > > with the same prefix (e.g. "foo" and "foobar").
> > > > ---
> > > >  libavutil/eval.c |    3 ++-
> > > >  1 files changed, 2 insertions(+), 1 deletions(-)
> > > > 
> > > > diff --git a/libavutil/eval.c b/libavutil/eval.c
> > > > index 98917fa..8e0b871 100644
> > > > --- a/libavutil/eval.c
> > > > +++ b/libavutil/eval.c
> > > > @@ -109,7 +109,8 @@ static int strmatch(const char *s, const char *prefix)
> > > >      for (i=0; prefix[i]; i++) {
> > > >          if (prefix[i] != s[i]) return 0;
> > > >      }
> > > > -    return 1;
> > > > +    /* return 1 only if the s identifier is terminated */
> > > > +    return !isalnum(s[i]) && s[i] != '_';
> > > 
> > > this is locale sensitiv which is unlikely what you want.
> > 
> > Updated.
> > -- 
> > FFmpeg = Faithful Friendly Mind-dumbing Prodigious Extreme Guide
> 
> >  eval.c |    8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > c67b14d5fd8ca52c283126e0103527d0de446504  0004-Make-strmatch-return-1-only-if-the-string-compared-a.patch
> > From 99d69b819b76445fd33eb56e501c3bf875f5414a Mon Sep 17 00:00:00 2001
> > From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> > Date: Sun, 31 Oct 2010 01:27:25 +0200
> > Subject: [PATCH 4/8] Make strmatch() return 1 only if the string compared against the
> >  prefix does not contain other characters which may belong to an
> >  identifier.
> >
> > This allows to distinguish for example to have different constants
> > with the same prefix (e.g. "foo" and "foobar").
> > ---
> >  libavutil/eval.c |    8 +++++++-
> >  1 files changed, 7 insertions(+), 1 deletions(-)
> > 
> > diff --git a/libavutil/eval.c b/libavutil/eval.c
> > index 98917fa..765492f 100644
> > --- a/libavutil/eval.c
> > +++ b/libavutil/eval.c
> > @@ -103,13 +103,19 @@ double av_strtod(const char *numstr, char **tail)
> >      return d;
> >  }
> >  
> > +#define IS_IDENTIFIER_CHAR(c) (((c) >= '0' && (c) <= '9') || \
> > +                               ((c) >= 'a' && (c) <= 'z') || \
> > +                               ((c) >= 'A' && (c) <= 'Z') || \
> > +                               ((c) == '_'))
> 
> things like
> (c) - '0' <= 9U
> can be used to optimize this
> except such things apply it

Updated, but I'm not very happy about the legibility of the result.
-- 
FFmpeg = Frightening and Foolish Magic Power Elitarian Ghost



More information about the ffmpeg-devel mailing list