[FFmpeg-devel] [PATCH 2/5] lavu/bprint: add XML escape convenience function

Nicolas George george at nsup.org
Fri Jul 17 12:47:30 CEST 2015


L'octidi 28 messidor, an CCXXIII, Rodger Combs a écrit :
> ---
>  libavutil/bprint.c | 7 +++++++
>  libavutil/bprint.h | 9 +++++++++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/libavutil/bprint.c b/libavutil/bprint.c
> index 64d2ab1..746868b 100644
> --- a/libavutil/bprint.c
> +++ b/libavutil/bprint.c
> @@ -334,6 +334,13 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_cha
>      }
>  }
>  
> +const char *av_xml_escape_str(AVBPrint *dst, const char *src)
> +{
> +    av_bprint_clear(dst);
> +    av_bprint_escape(dst, src, NULL, AV_ESCAPE_MODE_XML, 0);
> +    return dst->str;
> +}
> +
>  #ifdef TEST
>  
>  #undef printf
> diff --git a/libavutil/bprint.h b/libavutil/bprint.h
> index c09b1ac..006fa8c 100644
> --- a/libavutil/bprint.h
> +++ b/libavutil/bprint.h
> @@ -216,4 +216,13 @@ int av_bprint_finalize(AVBPrint *buf, char **ret_str);
>  void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_chars,
>                        enum AVEscapeMode mode, int flags);
>  
> +/**
> + * Clear the contents of dst, use it to XML-escape a string, and return the result.
> + * This is a convenience function that escapes only the default XML special characters.
> + *
> + * @param dst           already inited destination bprint buffer
> + * @param src           string containing the text to escape
> + */
> +const char *av_xml_escape_str(AVBPrint *dst, const char *src);
> +
>  #endif /* AVUTIL_BPRINT_H */

I am rather against this. First, of course, it does not correctly check for
OOM. Second, it does not fit the rest of the BPrint API. And last, it is
redundant with av_escape(), which performs the same task, only with
additional parameters for flags.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150717/fe6dfdf8/attachment.sig>


More information about the ffmpeg-devel mailing list