From patchwork Tue Feb 21 00:48:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Micah Galizia X-Patchwork-Id: 2621 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.65.149 with SMTP id x21csp163340vsf; Mon, 20 Feb 2017 16:48:32 -0800 (PST) X-Received: by 10.223.167.66 with SMTP id e2mr17124426wrd.48.1487638111973; Mon, 20 Feb 2017 16:48:31 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y6si14240242wmg.57.2017.02.20.16.48.31; Mon, 20 Feb 2017 16:48:31 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 561446899C4; Tue, 21 Feb 2017 02:48:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f66.google.com (mail-it0-f66.google.com [209.85.214.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 45696680AA1 for ; Tue, 21 Feb 2017 02:48:09 +0200 (EET) Received: by mail-it0-f66.google.com with SMTP id r141so13354037ita.1 for ; Mon, 20 Feb 2017 16:48:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:in-reply-to :references; bh=jCRb+JTumjsjDPAgfT0okEcHJPJXbGfHsTfCabWlUhg=; b=IFtGOC5foQquzHJNA5sl5ro+g1aDhWrcgQqKvLMGHg374ZMOjqwWETUa+tutkOU1uQ xtbfoI/8kL1yxYya9ZaOfjYwkFlBAGbOWvaxEyADVVahocxrJYetKAod5+fmUkHnxqFG h0W3s+7sTa84W9y0rGePRM3DUcTM+Wb5d6axPiXAgQGTCP/x5rHz47AscUhX6/UVB/7L BGY8ksQzO8f7u3/GxqEDrBABRVAGlaTdDgML5F/z3VlNp3RQTuxk7PLMz/KUggF3motF 3F2PVCfeX/vgCE4l1yVGUzJhqb//p1yV44pFs2LLARoAP8dRHW4yaVerTXyPqjLKQ1Ml hhkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=jCRb+JTumjsjDPAgfT0okEcHJPJXbGfHsTfCabWlUhg=; b=Jjt6k0HSO6qEys26/s7TxG2ixrqeDagvhjXoVT6MGoouKVUOzjGo0S6FeBwIKmjI0Z 0Y8fkjyb5OCEtxd/DZihc4/3oyDcF8mQhjcyxlL48EQCp4x1Gtf1ZFE+chae9VTQyN3w qrScfLvcJe/sYhrk/tnOg/Jf4uANrGHTwzF6+uX9oCCD9t5DP0E+WqEUuiJQk9OmvDBm w4xvbP3kJTnIFhQw9z/7JOAAl642aC80ZXTvs827vEvkkI8q2BwmRqYu5qM3KjoBPLGp XZxoNDU0+IiT7o8KbTUDgEfUAhxx1UGkCPIlXct5a0kfwFyT81h4mLlB22OvvGlmTwFq 9cSg== X-Gm-Message-State: AMke39k4KpfYhvwVF8gSOMM1JqzFH9bG5q9S0L7+c62DIb8APF4X0HEkltriuCBC0/zEAA== X-Received: by 10.107.133.223 with SMTP id p92mr22024192ioi.175.1487638095887; Mon, 20 Feb 2017 16:48:15 -0800 (PST) Received: from localhost.localdomain (ip-24-54-73-138.user.start.ca. [24.54.73.138]) by smtp.gmail.com with ESMTPSA id u65sm9645167ioe.47.2017.02.20.16.48.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Feb 2017 16:48:15 -0800 (PST) From: Micah Galizia To: ffmpeg-devel@ffmpeg.org, micahgalizia@gmail.com Date: Mon, 20 Feb 2017 19:48:02 -0500 Message-Id: <20170221004802.20303-2-micahgalizia@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170221004802.20303-1-micahgalizia@gmail.com> References: <20170221000502.GY5776@nb4> <20170221004802.20303-1-micahgalizia@gmail.com> In-Reply-To: <20170220104750.GA2923380@phare.normalesup.org> References: <20170220104750.GA2923380@phare.normalesup.org> Subject: [FFmpeg-devel] [PATCH] add locale month names to av_small_strptime 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" Signed-off-by: Micah Galizia --- libavutil/parseutils.c | 28 ++++++++++++++++++++++++++++ libavutil/tests/parseutils.c | 7 +++++++ tests/ref/fate/parseutils | 7 +++++++ 3 files changed, 42 insertions(+) diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c index 86d3dac..7ca07b3 100644 --- a/libavutil/parseutils.c +++ b/libavutil/parseutils.c @@ -140,6 +140,11 @@ static const VideoRateAbbr video_rate_abbrs[]= { { "ntsc-film", { 24000, 1001 } }, }; +static const char *months[12] = { + "january", "february", "march", "april", "may", "june", "july", "august", + "september", "october", "november", "december" +}; + int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str) { int i; @@ -466,6 +471,21 @@ static int date_get_num(const char **pp, return val; } +static int date_get_month(const char **pp) { + int i = 0; + for (; i < 12; i++) { + if (!av_strncasecmp(*pp, months[i], 3)) { + const char *mo_full = months[i] + 3; + int len = strlen(mo_full); + *pp += 3; + if (len > 0 && !av_strncasecmp(*pp, mo_full, len)) + *pp += len; + return i; + } + } + return -1; +} + char *av_small_strptime(const char *p, const char *fmt, struct tm *dt) { int c, val; @@ -525,6 +545,14 @@ char *av_small_strptime(const char *p, const char *fmt, struct tm *dt) if (!p) return NULL; break; + case 'b': + case 'B': + case 'h': + val = date_get_month(&p); + if (val == -1) + return NULL; + dt->tm_mon = val; + break; case '%': if (*p++ != '%') return NULL; diff --git a/libavutil/tests/parseutils.c b/libavutil/tests/parseutils.c index 682b390..180f624 100644 --- a/libavutil/tests/parseutils.c +++ b/libavutil/tests/parseutils.c @@ -138,6 +138,13 @@ static void test_av_small_strptime(void) { "%Y - %m - %d", "2012-12-21" }, { "%Y-%m-%d %H:%M:%S", "2012-12-21 20:12:21" }, { " %Y - %m - %d %H : %M : %S", " 2012 - 12 - 21 20 : 12 : 21" }, + { " %Y - %b - %d %H : %M : %S", " 2012 - nOV - 21 20 : 12 : 21" }, + { " %Y - %B - %d %H : %M : %S", " 2012 - nOVemBeR - 21 20 : 12 : 21" }, + { " %Y - %B%d %H : %M : %S", " 2012 - may21 20 : 12 : 21" }, + { " %Y - %B%d %H : %M : %S", " 2012 - mby21 20 : 12 : 21" }, + { " %Y - %B - %d %H : %M : %S", " 2012 - JunE - 21 20 : 12 : 21" }, + { " %Y - %B - %d %H : %M : %S", " 2012 - Jane - 21 20 : 12 : 21" }, + { " %Y - %B - %d %H : %M : %S", " 2012 - January - 21 20 : 12 : 21" }, }; av_log_set_level(AV_LOG_DEBUG); diff --git a/tests/ref/fate/parseutils b/tests/ref/fate/parseutils index 1aad5ec..568b6d2 100644 --- a/tests/ref/fate/parseutils +++ b/tests/ref/fate/parseutils @@ -68,6 +68,13 @@ fmt:'%Y-%m-%d' spec:'2012-12-21' -> 2012-12-21 00:00:00 fmt:'%Y - %m - %d' spec:'2012-12-21' -> 2012-12-21 00:00:00 fmt:'%Y-%m-%d %H:%M:%S' spec:'2012-12-21 20:12:21' -> 2012-12-21 20:12:21 fmt:' %Y - %m - %d %H : %M : %S' spec:' 2012 - 12 - 21 20 : 12 : 21' -> 2012-12-21 20:12:21 +fmt:' %Y - %b - %d %H : %M : %S' spec:' 2012 - nOV - 21 20 : 12 : 21' -> 2012-11-21 20:12:21 +fmt:' %Y - %B - %d %H : %M : %S' spec:' 2012 - nOVemBeR - 21 20 : 12 : 21' -> 2012-11-21 20:12:21 +fmt:' %Y - %B%d %H : %M : %S' spec:' 2012 - may21 20 : 12 : 21' -> 2012-05-21 20:12:21 +fmt:' %Y - %B%d %H : %M : %S' spec:' 2012 - mby21 20 : 12 : 21' -> error +fmt:' %Y - %B - %d %H : %M : %S' spec:' 2012 - JunE - 21 20 : 12 : 21' -> 2012-06-21 20:12:21 +fmt:' %Y - %B - %d %H : %M : %S' spec:' 2012 - Jane - 21 20 : 12 : 21' -> error +fmt:' %Y - %B - %d %H : %M : %S' spec:' 2012 - January - 21 20 : 12 : 21' -> 2012-01-21 20:12:21 Testing av_parse_time() (now is 2012-03-17 09:14:13.2 +0100, local time is UTC+1)