History

avfilter/f_metadata: add ends_with() function for comparing ends of strings

Paul B Mahol committed 7 years ago

Commit 9c9d5bf1 parent 6ca3d342 files · +17 −0Browse files

Unified · Split

2 files
  1. doc/filters.texi +4 −0
  2. libavfilter/f_metadata.c +13 −0
doc/filters.texi+4−0
@@ -21856,6 +21856,10 @@ Values are interpreted as floats, returns true if metadata value is greater than · 21855 unmodified lines
21856@item expr21856@item expr
21857Values are interpreted as floats, returns true if expression from option @code{expr}21857Values are interpreted as floats, returns true if expression from option @code{expr}
21858evaluates to true.21858evaluates to true.
21859
21860@item ends_with
21861Values are interpreted as strings, returns true if metadata value ends with
21862the @code{value} option string.
21859@end table21863@end table
21860 21864
21861@item expr21865@item expr
libavfilter/f_metadata.c+13−0
@@ -54,6 +54,7 @@ enum MetadataFunction { · 53 unmodified lines
54 METADATAF_EQUAL,54 METADATAF_EQUAL,
55 METADATAF_GREATER,55 METADATAF_GREATER,
56 METADATAF_EXPR,56 METADATAF_EXPR,
57 METADATAF_ENDS_WITH,
57 METADATAF_NB58 METADATAF_NB
58};59};
59 60
@@ -107,6 +108,7 @@ static const AVOption filt_name##_options[] = { \ · 47 unmodified lines
107 { "equal", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_EQUAL }, 0, 3, FLAGS, "function" }, \108 { "equal", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_EQUAL }, 0, 3, FLAGS, "function" }, \
108 { "greater", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_GREATER }, 0, 3, FLAGS, "function" }, \109 { "greater", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_GREATER }, 0, 3, FLAGS, "function" }, \
109 { "expr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_EXPR }, 0, 3, FLAGS, "function" }, \110 { "expr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_EXPR }, 0, 3, FLAGS, "function" }, \
111 { "ends_with", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_ENDS_WITH }, 0, 0, FLAGS, "function" }, \
110 { "expr", "set expression for expr function", OFFSET(expr_str), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, FLAGS }, \112 { "expr", "set expression for expr function", OFFSET(expr_str), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, FLAGS }, \
111 { "file", "set file where to print metadata information", OFFSET(file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, \113 { "file", "set file where to print metadata information", OFFSET(file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, \
112 { NULL } \114 { NULL } \
@@ -122,6 +124,14 @@ static int starts_with(MetadataContext *s, const char *value1, const char *value · 9 unmodified lines
122 return !strncmp(value1, value2, strlen(value2));124 return !strncmp(value1, value2, strlen(value2));
123}125}
124 126
127static int ends_with(MetadataContext *s, const char *value1, const char *value2)
128{
129 const int len1 = strlen(value1);
130 const int len2 = strlen(value2);
131
132 return !strncmp(value1 + FFMAX(len1 - len2, 0), value2, len2);
133}
134
125static int equal(MetadataContext *s, const char *value1, const char *value2)135static int equal(MetadataContext *s, const char *value1, const char *value2)
126{136{
127 float f1, f2;137 float f1, f2;
@@ -212,6 +222,9 @@ static av_cold int init(AVFilterContext *ctx) · 84 unmodified lines
212 case METADATAF_STARTS_WITH:222 case METADATAF_STARTS_WITH:
213 s->compare = starts_with;223 s->compare = starts_with;
214 break;224 break;
225 case METADATAF_ENDS_WITH:
226 s->compare = ends_with;
227 break;
215 case METADATAF_LESS:228 case METADATAF_LESS:
216 s->compare = less;229 s->compare = less;
217 break;230 break;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t