From patchwork Mon Jun 12 22:01:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 3931 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.22.4 with SMTP id 4csp65088vsw; Mon, 12 Jun 2017 15:01:18 -0700 (PDT) X-Received: by 10.223.150.123 with SMTP id c56mr574192wra.15.1497304878648; Mon, 12 Jun 2017 15:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497304878; cv=none; d=google.com; s=arc-20160816; b=IAD7V71TfR+o4/1moTDSq+2Kj9BvXDSN512gfjWmElpamFEtHE9yKqdK3gkHawt+Ep qWpeCrrY1N0ESzZ31BLaqPxmhLpZbaJLtZyaiNuVSgdKk9NwtwIHGCXFKxERb1HuXfDH XSvfWR1NYnopZFHdpo6puUv/QNsqNhnv1bc/i8YEeRVRRb4gBqvtZkUbeUZpXXpWjzdp RvhbsSn3JhxNXB1iGF7ts2GMO/RC7MAokGST7BVRC6NcR0QEAiAx76MBoOuXpkcB6qML Qwkou5wAPs8V9YcyoGOdYP5AGXZJJsdCqUa9guNfjcmugMmPFKolU25YcC0DjUiV3JGk 3bbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=VBLzNbe2u9bgMNFKp66mW7+cy2H1AfWN0h/BFJ5yaX8=; b=wi/4cx6YZN9BHAetIToJnILGX9zHZUxiTfbU429E4KHCaI3J1hyVoDRCsfsGR3bWTL bNd7asSTKJOidSTf5VLrZFa7gOwvHNSUe0MEchKbRFqEYZK0qOhsPYvnnwsHhy/ApNh0 W/k4F0JgD04psVC0M3VCVTRfyEq/88pd/ntkEeTgbisif9wzbaXiSxALs7jiomA/BArk Mm3gnLF7ovE9Yc+LOLqPH75ypvF2BrnJ3fF5ial36slpFgEfQByalmOuvSyGcSB1CvLu HC79WqmjavhnV1T2eSPzLO9wrC3J72u3kHjItbGyMNBOjoqgjhT2UUN5h9156zijpog4 PcAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z79si9073987wmz.9.2017.06.12.15.01.17; Mon, 12 Jun 2017 15:01:18 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2093A689D07; Tue, 13 Jun 2017 01:01:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-1.mx.upcmail.net (vie01a-dmta-pe07-3.mx.upcmail.net [84.116.36.19]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E36B8688300 for ; Tue, 13 Jun 2017 01:01:05 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe07.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dKXOV-0005y4-8I for ffmpeg-devel@ffmpeg.org; Tue, 13 Jun 2017 00:01:07 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id Xy151v0040S5wYM01y16G7; Tue, 13 Jun 2017 00:01:06 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 13 Jun 2017 00:01:04 +0200 Message-Id: <20170612220104.1571-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.13.0 Subject: [FFmpeg-devel] [PATCH] avcodec/htmlsubtitles: Factor open brace handling into its own function X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Suggested-by: wm4 Signed-off-by: Michael Niedermayer --- libavcodec/htmlsubtitles.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/libavcodec/htmlsubtitles.c b/libavcodec/htmlsubtitles.c index 70311c66d5..be5c9316ca 100644 --- a/libavcodec/htmlsubtitles.c +++ b/libavcodec/htmlsubtitles.c @@ -51,6 +51,30 @@ static void rstrip_spaces_buf(AVBPrint *buf) buf->str[--buf->len] = 0; } +/* skip all {\xxx} substrings except for {\an%d} + and all microdvd like styles such as {Y:xxx} */ +static void handle_open_brace(AVBPrint *dst, const char **inp, int *an, int *closing_brace_missing) +{ + int len = 0; + const char *in = *inp; + + *an += sscanf(in, "{\\an%*1u}%n", &len) >= 0 && len > 0; + + if (!*closing_brace_missing) { + if ( (*an != 1 && in[1] == '\\') + || (in[1] && strchr("CcFfoPSsYy", in[1]) && in[2] == ':')) { + char *bracep = strchr(in+2, '}'); + if (bracep) { + *inp = bracep; + return; + } else + *closing_brace_missing = 1; + } + } + + av_bprint_chars(dst, *in, 1); +} + int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in) { char *param, buffer[128], tmp[128]; @@ -80,24 +104,8 @@ int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in) if (!line_start) av_bprint_chars(dst, *in, 1); break; - case '{': /* skip all {\xxx} substrings except for {\an%d} - and all microdvd like styles such as {Y:xxx} */ - len = 0; - an += sscanf(in, "{\\an%*1u}%n", &len) >= 0 && len > 0; - - if (!closing_brace_missing) { - if ( (an != 1 && in[1] == '\\') - || (in[1] && strchr("CcFfoPSsYy", in[1]) && in[2] == ':')) { - char *bracep = strchr(in+2, '}'); - if (bracep) { - in = bracep; - break; - } else - closing_brace_missing = 1; - } - } - - av_bprint_chars(dst, *in, 1); + case '{': + handle_open_brace(dst, &in, &an, &closing_brace_missing); break; case '<': tag_close = in[1] == '/';