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

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/f_metadata.c+13−0
@@ -54,6 +54,7 @@ enum MetadataFunction { · 53 unmodified lines
5454 METADATAF_EQUAL,
5555 METADATAF_GREATER,
5656 METADATAF_EXPR,
57+ METADATAF_ENDS_WITH,
5758 METADATAF_NB
5859 };
5960
@@ -107,6 +108,7 @@ static const AVOption filt_name##_options[] = { \ · 47 unmodified lines
107108 { "equal", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_EQUAL }, 0, 3, FLAGS, "function" }, \
108109 { "greater", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_GREATER }, 0, 3, FLAGS, "function" }, \
109110 { "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" }, \
110112 { "expr", "set expression for expr function", OFFSET(expr_str), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, FLAGS }, \
111113 { "file", "set file where to print metadata information", OFFSET(file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, \
112114 { NULL } \
@@ -122,6 +124,14 @@ static int starts_with(MetadataContext *s, const char *value1, const char *value · 9 unmodified lines
122124 return !strncmp(value1, value2, strlen(value2));
123125 }
124126
127+static 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+
125135 static int equal(MetadataContext *s, const char *value1, const char *value2)
126136 {
127137 float f1, f2;
@@ -212,6 +222,9 @@ static av_cold int init(AVFilterContext *ctx) · 84 unmodified lines
212222 case METADATAF_STARTS_WITH:
213223 s->compare = starts_with;
214224 break;
225+ case METADATAF_ENDS_WITH:
226+ s->compare = ends_with;
227+ break;
215228 case METADATAF_LESS:
216229 s->compare = less;
217230 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