[FFmpeg-devel] [PATCH] lavu/avstring: support "'" escaping in sequence of chars enclosed by "'"

Stefano Sabatini stefasab at gmail.com
Tue Sep 4 01:55:55 CEST 2012


Make av_get_token() support escaping of ' inside a sequence enclosed by
quotes. This allows to specify strings of the kind:
'\'this sentence is quoted\''

which may be useful when quoting nested literal strings.

TODO: bump micro
---
 libavutil/avstring.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 8b258a4..4b3c505 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -141,8 +141,13 @@ char *av_get_token(const char **buf, const char *term)
             *out++ = *p++;
             end= out;
         }else if(c == '\''){
-            while(*p && *p != '\'')
-                *out++ = *p++;
+            while (*p && *p != '\'') {
+                if (*p == '\\' && *(p+1) == '\'') {
+                    *out++ = *(p+1);
+                    p += 2;
+                } else
+                    *out++ = *p++;
+            }
             if(*p){
                 p++;
                 end= out;
@@ -248,7 +253,8 @@ int main(void)
             "\\f\\o\\o",
             "'foo : \\ \\  '   : blahblah",
             "'\\fo\\o:': blahblah",
-            "\\'fo\\o\\:':  foo  '  :blahblah"
+            "\\'fo\\o\\:':  foo  '  :blahblah",
+            "'foo \\'and\\' bar'",
         };
 
         for (i=0; i < FF_ARRAY_ELEMS(strings); i++) {
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list