From patchwork Mon Feb 20 20:30:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Micah Galizia X-Patchwork-Id: 2617 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.65.149 with SMTP id x21csp86928vsf; Mon, 20 Feb 2017 12:31:02 -0800 (PST) X-Received: by 10.28.144.66 with SMTP id s63mr21728248wmd.134.1487622662789; Mon, 20 Feb 2017 12:31:02 -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 b31si25183314wrd.314.2017.02.20.12.31.01; Mon, 20 Feb 2017 12:31:02 -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 6576A689BE9; Mon, 20 Feb 2017 22:30:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f67.google.com (mail-it0-f67.google.com [209.85.214.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 66CC5689A33 for ; Mon, 20 Feb 2017 22:30:44 +0200 (EET) Received: by mail-it0-f67.google.com with SMTP id 203so12343551ith.2 for ; Mon, 20 Feb 2017 12:30:52 -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=D89H3Pb/DkLP7hlU0ifveQRPDchjJWR60F3s3VPhYNs=; b=k0Xd0g3vljulGu/cZkczTCMb739pI3nrhjNcenoUydr0no7MyiX129jrNw1GdOmPr6 jqLS6EdJZjhz/F9bCXBhxiUx60Fqdr9/D3Ei163biE229CBSnDak+Zg/ImlCc0DoNjjt 7DO2JI71v0VmDboHxXBthZ7i3eLeQUpP6ydf5hDM1Hd/0haqXCKgjBozfmeme9OqYu0A fl1hbX4VgjBl/BadM6dB7zNAHTI2eIAzJWTkk3J2T6HhS9jC+kwIhqGv3sPzaWNBVBcs RKCD+dqefFwOUIVuph+ICVTIiSkzR99pHVeFW4+/9JSPBfkuXlrm63BllW7/l8lfTnzE Se3Q== 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=D89H3Pb/DkLP7hlU0ifveQRPDchjJWR60F3s3VPhYNs=; b=JIgVTaIu5lnLmu2w8j0noygx3XL8k9ZkH/WdP2+VOxEYqulbsYI+ajrv6NB56Eaz+H +eCceMLhmh1kWAbiM+AHmaz/fDTFtTUbUMFPB+KikbjI5BMr15wJCCUIxUIKLj9LgfT2 Fy+UtNkWfvndKQVGS3qHP3ithuigAKQJSObslLtJlzZjy7FLyC2BU3+tQnquz/AUegek TAhso8XnsNiBHWWVD5ITlM2METuDCurlJRBHR95lbgFlb/jksv00kBFAKMO9z6IGLVtl mmG3veAOCuc++HCtvptYiO/KjvDGVJVl/wB4pjtf/zZlj2Yyf0BHLV0ORl/2nx/3Uyhl MtAA== X-Gm-Message-State: AMke39nmOkUOqOLFTCYgLTFXX2cHTWv2mP9SBX7AS9AkWhLKf4uxqqHK/yQ3bMSkUR8qoQ== X-Received: by 10.36.68.17 with SMTP id o17mr22547936ita.62.1487622650697; Mon, 20 Feb 2017 12:30:50 -0800 (PST) Received: from localhost.localdomain (30.40.44.96.scpe.hay.net. [96.44.40.30]) by smtp.gmail.com with ESMTPSA id i203sm9421329ioi.45.2017.02.20.12.30.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Feb 2017 12:30:50 -0800 (PST) From: Micah Galizia To: ffmpeg-devel@ffmpeg.org, micahgalizia@gmail.com Date: Mon, 20 Feb 2017 15:30:43 -0500 Message-Id: <20170220203043.742-1-micahgalizia@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170220104750.GA2923380@phare.normalesup.org> References: <20170220104750.GA2923380@phare.normalesup.org> 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 +++++++ 2 files changed, 35 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);