From patchwork Mon Mar 20 20:38:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafal Luzynski X-Patchwork-Id: 741170 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vn77y1Jclz9rvt for ; Tue, 21 Mar 2017 07:38:38 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="p8ZwUlxP"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:reply-to:to:message-id:subject :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=XlOTD3RiSn8OIv6PMLfCCZcNgsMweuLif47lPF6wqgdp7nHbsSPLP 3tFbizWP5Rox+leYP2hiu+rHc1xYVSo15GIq+TQ13xzt10NLfaBk/7Xxel36Av63 //FtYfzYS6BB+s79O+U4x5sXKOghvGPXK3LbBG7dR0+u31zZZBsqlw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:reply-to:to:message-id:subject :mime-version:content-type:content-transfer-encoding; s=default; bh=fAY7JZXvro//1NL+WwJ/RgBY234=; b=p8ZwUlxPx6QSIx8gpPs1hUk1PphE rwt6uKJQ2MuvMCdF0OPVzuX+QUnEcWSzCUOGtChaQYKfchbMlJI9BZ0iVarH2d48 qjwwgV2bBYjOcaxkI9/3oUh3H6wrkSjYHHXlNJtmKpHfac26M3bQagCZFIycfiVV z+Ffuuw6foi34IQ= Received: (qmail 51616 invoked by alias); 20 Mar 2017 20:38:29 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 51578 invoked by uid 89); 20 Mar 2017 20:38:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=month, H*x:Mailer, H*UA:Mailer X-HELO: aev204.rev.netart.pl X-Spam-Score: 0 Date: Mon, 20 Mar 2017 21:38:24 +0100 (CET) From: Rafal Luzynski Reply-To: Rafal Luzynski To: libc-alpha@sourceware.org Message-ID: <1655006752.88154.1490042304039@poczta.nazwa.pl> Subject: [RFC][PATCH v6 05/16] Implement the %OB specifier - alternative month names (bug 10871) MIME-Version: 1.0 X-Originating-Client: com.openexchange.ox.gui.dhtml Some languages (Slavic, Baltic, etc.) require a genitive case of the month name when formatting a full date (with the day number) while they require a nominative case when referring to the month standalone. strftime() now implements a %OB format specifier which generates an alternative month name. For those languages %B will return the basic month name. For those languages which do not use different (nominative and genitive) cases of the month name or do not yet have their locales updated %OB will retrieve the same string as %B so moving to %OB will be harmless as long as the version of glibc which supports this feature is used. Note that it is not yet decided whether %OB will return the standalone case (usually nominative) and %B will return the full date context case (usually genitive) or vice versa. It depends on the locale database and localized format strings which may vary with the locales and depend on what a language community decides. strptime() now accepts both nominative and genitive month names. [BZ #10871] * time/strftime_l.c: %OB format for alternative month names added. * time/strptime_l.c: alternative month names also recognized. --- time/strftime_l.c | 11 +++++++++-- time/strptime_l.c | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) # define HERE_AM_STR (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (AM_STR)].string) @@ -403,6 +405,20 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tmp, if (s.decided !=raw) { trp = rp; +#ifdef _LIBC + /* First check the alt month. */ + if (match_string (_NL_CURRENT (LC_TIME, ALTMON_1 + cnt), trp) + && trp > rp_longest) + { + rp_longest = trp; + cnt_longest = cnt; + if (s.decided == not + && strcmp (_NL_CURRENT (LC_TIME, ALTMON_1 + cnt), + alt_month_name[cnt])) + decided_longest = loc; + } + trp = rp; +#endif if (match_string (_NL_CURRENT (LC_TIME, MON_1 + cnt), trp) && trp > rp_longest) { @@ -429,6 +445,10 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tmp, if (s.decided != loc && (((trp = rp, match_string (month_name[cnt], trp)) && trp > rp_longest) +#ifdef _LIBC + || ((trp = rp, match_string (alt_month_name[cnt], trp)) + && trp > rp_longest) +#endif || ((trp = rp, match_string (ab_month_name[cnt], trp)) && trp > rp_longest))) { @@ -1016,6 +1036,10 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tmp, case 'O': switch (*fmt++) { + case 'B': + /* Undo the increment and continue. */ + fmt--; + break; case 'd': case 'e': /* Match day of month using alternate numeric symbols. */ diff --git a/time/strftime_l.c b/time/strftime_l.c index eb3efb8..544c97d 100644 --- a/time/strftime_l.c +++ b/time/strftime_l.c @@ -492,6 +492,9 @@ __strftime_internal (CHAR_T *s, size_t maxsize, const CHAR_T *format, # define f_month \ ((const CHAR_T *) (tp->tm_mon < 0 || tp->tm_mon > 11 \ ? "?" : _NL_CURRENT (LC_TIME, NLW(MON_1) + tp->tm_mon))) +# define f_altmonth \ + ((const CHAR_T *) (tp->tm_mon < 0 || tp->tm_mon > 11 \ + ? "?" : _NL_CURRENT (LC_TIME, NLW(ALTMON_1) + tp->tm_mon))) # define ampm \ ((const CHAR_T *) _NL_CURRENT (LC_TIME, tp->tm_hour > 11 \ ? NLW(PM_STR) : NLW(AM_STR))) @@ -507,6 +510,7 @@ __strftime_internal (CHAR_T *s, size_t maxsize, const CHAR_T *format, ? "?" : month_name[tp->tm_mon]) # define a_wkday f_wkday # define a_month f_month +# define f_altmonth f_month # define ampm (L_("AMPM") + 2 * (tp->tm_hour > 11)) size_t aw_len = 3; @@ -775,7 +779,7 @@ __strftime_internal (CHAR_T *s, size_t maxsize, const CHAR_T *format, #endif case L_('B'): - if (modifier != 0) + if (modifier == L_('E')) goto bad_format; if (change_case) { @@ -783,7 +787,10 @@ __strftime_internal (CHAR_T *s, size_t maxsize, const CHAR_T *format, to_lowcase = 0; } #if defined _NL_CURRENT || !HAVE_STRFTIME - cpy (STRLEN (f_month), f_month); + if (modifier == L_('O')) + cpy (STRLEN (f_altmonth), f_altmonth); + else + cpy (STRLEN (f_month), f_month); break; #else goto underlying_strftime; diff --git a/time/strptime_l.c b/time/strptime_l.c index dbf4606..dd61495 100644 --- a/time/strptime_l.c +++ b/time/strptime_l.c @@ -124,6 +124,8 @@ extern const struct __locale_data _nl_C_LC_TIME attribute_hidden; (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABDAY_1)].string) # define month_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (MON_1)].string) # define ab_month_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABMON_1)].string) +# define alt_month_name \ + (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ALTMON_1)].string) # define HERE_D_T_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_T_FMT)].string) # define HERE_D_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_FMT)].string)