summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-04-29 07:16:09 +0200
committerwm4 <wm4@mplayer2.org>2012-04-29 10:01:28 +0200
commit97ac824124fc5cdfbd9ac74156b79c098bce09c6 (patch)
tree2c924403e2fb619ec57ee0933cd12d32ef1bb62a /sub
parent87f4cafe9c0881743d1117c2e8cd7e3376e33302 (diff)
parentf64a4e9931428de0f308f6ed0a0144edb8ce9619 (diff)
downloadmpv-97ac824124fc5cdfbd9ac74156b79c098bce09c6.tar.bz2
mpv-97ac824124fc5cdfbd9ac74156b79c098bce09c6.tar.xz
Merge remote-tracking branch 'origin/master'
Conflicts: bstr.c bstr.h libvo/cocoa_common.m libvo/gl_common.c libvo/video_out.c mplayer.c screenshot.c sub/subassconvert.c Merge of cocoa_common.m done by pigoz. Picking my version of screenshot.c. The fix in commit aadf1002f8a will be redone in a follow-up commit, as the original commit causes too many conflicts with the work done locally in this branch, and other work in progress.
Diffstat (limited to 'sub')
-rw-r--r--sub/subassconvert.c67
1 files changed, 34 insertions, 33 deletions
diff --git a/sub/subassconvert.c b/sub/subassconvert.c
index bbd789f91f..e1db9bb033 100644
--- a/sub/subassconvert.c
+++ b/sub/subassconvert.c
@@ -106,25 +106,30 @@ static const struct {
#define SUBRIP_MAX_STACKED_FONT_TAGS 16
-/* read the attribute value starting at *s, and skip *s past the value
- * return the value in out_value, with possible '"' stripped
- * return whether the attribute is well formed */
-static bool read_value(char **s, struct bstr *out_value)
+/* Read the HTML-style attribute starting at *s, and skip *s past the value.
+ * Set attr and val to the parsed attribute name and value.
+ * Return 0 on success, or -1 if no valid attribute was found.
+ */
+static int read_attr(char **s, struct bstr *attr, struct bstr *val)
{
- char term = '\0';
- if (**s == '"') {
- term = '"';
- (*s)++;
- }
- out_value->start = *s;
- out_value->len = 0;
- unsigned char *start = *s;
- unsigned char *end = term ? strchr(start, term) : strpbrk(start, " >");
+ char *eq = strchr(*s, '=');
+ if (!eq)
+ return -1;
+ attr->start = *s;
+ attr->len = eq - *s;
+ for (int i = 0; i < attr->len; i++)
+ if (!isalnum(attr->start[i]))
+ return -1;
+ val->start = eq + 1;
+ bool quoted = val->start[0] == '"';
+ if (quoted)
+ val->start++;
+ unsigned char *end = strpbrk(val->start, quoted ? "\"" : " >");
if (!end)
- return false;
- out_value->len = end - out_value->start;
- *s = end + (term ? 1 : 0);
- return true;
+ return -1;
+ val->len = end - val->start;
+ *s = end + quoted;
+ return 0;
}
void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size)
@@ -195,22 +200,21 @@ void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size)
line += 6;
while (*line && *line != '>') {
- if (strncmp(line, "size=", 5) == 0) {
- line += 5;
- struct bstr val;
- if (!read_value(&line, &val))
- break;
+ if (*line == ' ') {
+ line++;
+ continue;
+ }
+ struct bstr attr, val;
+ if (read_attr(&line, &attr, &val) < 0)
+ break;
+ if (!bstrcmp0(attr, "size")) {
tag->size = bstrtoll(val, &val, 10);
if (val.len)
break;
append_text(&new_line, "{\\fs%d}", tag->size);
tag->has_size = true;
has_valid_attr = true;
- } else if (strncmp(line, "color=", 6) == 0) {
- line += 6;
- struct bstr val;
- if (!read_value(&line, &val))
- break;
+ } else if (!bstrcmp0(attr, "color")) {
if (bstr_eatstart(&val, bstr("#"))) {
// #RRGGBB format
tag->color = bstrtoll(val, &val, 16) & 0x00ffffff;
@@ -240,18 +244,15 @@ void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size)
append_text(&new_line, "{\\c&H%06X&}", tag->color);
tag->has_color = true;
has_valid_attr = true;
- } else if (strncmp(line, "face=", 5) == 0) {
+ } else if (!bstrcmp0(attr, "face")) {
/* Font face attribute */
- line += 5;
- struct bstr val;
- if (!read_value(&line, &val))
- break;
tag->face = val;
append_text(&new_line, "{\\fn%.*s}", BSTR_P(tag->face));
tag->has_face = true;
has_valid_attr = true;
} else
- line++;
+ mp_tmsg(MSGT_SUBREADER, MSGL_WARN,"SubRip: unrecognized "
+ "attribute \"%.*s\" in font tag\n", BSTR_P(attr));
}
if (!has_valid_attr || *line != '>') { /* Not valid font tag */