[FFmpeg-devel] [PATCH] drawtext: unescape fontconfig patterns

bn aval57 at yahoo.com
Mon Jun 3 17:07:57 CEST 2013


--- On Mon, 6/3/13, Nicolas George <nicolas.george at normalesup.org> wrote:


> This is wrong, the options parsing system already takes care
> of unescaping.

You're right, Nicolas, I jumped the gun it seems.  The drawtext sequence was long and involved one and one of my fontfile sequences may not have been quote-wrapped (at least as best I can determine from my console history).

> > +{
> > +    char *p = text;
> > +    int shift = 0;
> > +
> > +    while (*p) {
> > +        if (*p == '\\' && p[1])) {
> > +            shift++;
> > +            p++;
> > +        }
> > +        if (shift) {
> > +            *(p - shift) = *p;
> > +        }
> > +        p++;
> > +    }
> > +    *(p - shift) = '\0';
> 
> It looks rather complex, using two pointers would be
> simpler:
> 
> p = q = text;
> while (*p) {
>     if (*p == '\\' && p[1])
>     p++;
>     *(q++) = *(p++);
> }

Thanks for the coding lesson, but I was simply following the implicit style of expand_text() from the same file:

    while (*text) {
        if (*text == '\\' && text[1]) {
            av_bprint_chars(bp, text[1], 1);
            text += 2;
        } else if (*text == '%') {
            text++;
            if ((ret = expand_function(ctx, bp, &text)) < 0)
                return ret;
        } else {
            av_bprint_chars(bp, *text, 1);
            text++;
        }

where as you see the writer resists the temptation to post-increment variables inline.  Personally I, like yourself, prefer the conciser way.  Leaving this aside, using two pointers is not conceptually simpler than using a pointer and an offset, the number of arithmetic ops is identical.

peace,
Bahman




More information about the ffmpeg-devel mailing list