public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][BZ #15527] strftime_l.c: Support lowercase output
@ 2016-06-15  8:54 Jakub Martisko
  2016-06-15  9:09 ` Andreas Schwab
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Jakub Martisko @ 2016-06-15  8:54 UTC (permalink / raw)
  To: libc-alpha

[-- Attachment #1: Type: text/plain, Size: 344 bytes --]

strftime_l.c doe not provide easy way to produce lowercase output. While 
the function to create lowercase is implemented, there is no flag which 
would cause it to be called. Provided patch checks, whether combination 
of to_uppcase and change_case flags is used and sets to_lowcase if both 
of them are set which leads to lower case output.


[-- Attachment #2: 0001-PATCH-.-time-strftime_l.c-add-lowercase-support.patch --]
[-- Type: text/x-patch, Size: 2468 bytes --]

2016-05-12  Jakub Martisko  <jamartis@redhat.com>

	* [BZ #15527]
	* time/strftime_l.c (__strftime_internal): Implement conversion to
	all lowercase.
	* manual/time.texi: Document # flag.
	* time/tst-strftime.c (do_test): Test case conversion.



---
 manual/time.texi    |  6 +++++-
 time/strftime_l.c   |  7 ++++++-
 time/tst-strftime.c | 31 ++++++++++++++++++++++++++++++-
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/manual/time.texi b/manual/time.texi
index f94cbe4..a65959f 100644
--- a/manual/time.texi
+++ b/manual/time.texi
@@ -1350,7 +1350,11 @@ The number is padded with zeros even if the format specifies padding
 with spaces.
 
 @item ^
-The output uses uppercase characters, but only if this is possible
+The output uses uppercase characters, but only if this is possible.
+
+@item #
+The output uses opposite case characters, but only if this is possible.
+Can be combined with @samp{^} to produce lowercase characters.
 (@pxref{Case Conversion}).
 @end table
 
diff --git a/time/strftime_l.c b/time/strftime_l.c
index 1205035..c577f28 100644
--- a/time/strftime_l.c
+++ b/time/strftime_l.c
@@ -677,7 +677,12 @@ __strftime_internal (CHAR_T *s, size_t maxsize, const CHAR_T *format,
 	    }
 	  break;
 	}
-
+	if (to_uppcase == 1 && change_case == 1)
+	{
+	  to_uppcase = 0;
+	  change_case = 0;
+	  to_lowcase = 1;
+	}
       /* As a GNU extension we allow to specify the field width.  */
       if (ISDIGIT (*f))
 	{
diff --git a/time/tst-strftime.c b/time/tst-strftime.c
index af3ff72..e369595 100644
--- a/time/tst-strftime.c
+++ b/time/tst-strftime.c
@@ -153,7 +153,36 @@ do_test (void)
 	  result = 1;
 	}
     }
-
+  /*case tests*/
+	const struct
+	  {
+	    const char *fmt;
+	    const char *exp;
+	    size_t n;
+	  } ctests[] =
+	    {
+	      { "%^A", "SUNDAY", 6 },
+	      { "%^#A", "sunday", 6 },
+	      { "%A", "Sunday", 6 },
+	    };
+#define nctests (sizeof (ctests) / sizeof (ctests[0]))
+	  for (cnt = 0; cnt < nctests; ++cnt)
+    {
+      char buf[100];
+      size_t r = strftime (buf, sizeof (buf), ctests[cnt].fmt, &ttm);
+      if (r != ctests[cnt].n)
+	{
+	  printf ("strftime(\"%s\") returned %zu not %zu\n",
+		  ctests[cnt].fmt, r, ctests[cnt].n);
+	  result = 1;
+	}
+      if (strcmp (buf, ctests[cnt].exp) != 0)
+	{
+	  printf ("strftime(\"%s\") produced \"%s\" not \"%s\"\n",
+		  ctests[cnt].fmt, buf, ctests[cnt].exp);
+	  result = 1;
+	}
+    }
   return result + do_bz18985 ();
 }
 
-- 
2.5.0



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-06-15  8:54 [PATCH][BZ #15527] strftime_l.c: Support lowercase output Jakub Martisko
@ 2016-06-15  9:09 ` Andreas Schwab
  2016-06-29  7:55   ` Jakub Martisko
  2016-11-29 12:21 ` Jakub Martisko
  2016-12-06 23:21 ` Mike Frysinger
  2 siblings, 1 reply; 19+ messages in thread
From: Andreas Schwab @ 2016-06-15  9:09 UTC (permalink / raw)
  To: Jakub Martisko; +Cc: libc-alpha

Jakub Martisko <jamartis@redhat.com> writes:

>  @item ^
> -The output uses uppercase characters, but only if this is possible
> +The output uses uppercase characters, but only if this is possible.
> +
> +@item #
> +The output uses opposite case characters, but only if this is possible.
> +Can be combined with @samp{^} to produce lowercase characters.
>  (@pxref{Case Conversion}).
>  @end table

Bash is using ${x^} and ${x,} for case replacing expansions.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-06-15  9:09 ` Andreas Schwab
@ 2016-06-29  7:55   ` Jakub Martisko
  2016-12-06 23:20     ` Mike Frysinger
  0 siblings, 1 reply; 19+ messages in thread
From: Jakub Martisko @ 2016-06-29  7:55 UTC (permalink / raw)
  To: libc-alpha

Hi Andreas,

thanks for your comment. The reason why I sent the patch is that there 
is a bug/feature request for similar functionality in coreutils' "date" 
program and the maintainers of coreutils/gnulib do not want to diverge 
from the glibc interface. Even though the replacing you mentioned does 
indeed work, built-in version would be imo better (for example when 
using other shell than bash), especially when all of the needed 
functionality was already implemented.

Jakub

On 15.6.2016 11:08, Andreas Schwab wrote:
> Jakub Martisko <jamartis@redhat.com> writes:
>
>>   @item ^
>> -The output uses uppercase characters, but only if this is possible
>> +The output uses uppercase characters, but only if this is possible.
>> +
>> +@item #
>> +The output uses opposite case characters, but only if this is possible.
>> +Can be combined with @samp{^} to produce lowercase characters.
>>   (@pxref{Case Conversion}).
>>   @end table
>
> Bash is using ${x^} and ${x,} for case replacing expansions.
>
> Andreas.
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-06-15  8:54 [PATCH][BZ #15527] strftime_l.c: Support lowercase output Jakub Martisko
  2016-06-15  9:09 ` Andreas Schwab
@ 2016-11-29 12:21 ` Jakub Martisko
  2016-11-29 12:42   ` Jakub Martisko
  2016-12-06 23:21 ` Mike Frysinger
  2 siblings, 1 reply; 19+ messages in thread
From: Jakub Martisko @ 2016-11-29 12:21 UTC (permalink / raw)
  To: libc-alpha

Hi, are there any updates regarding this functionality?

On 15.6.2016 10:54, Jakub Martisko wrote:
> strftime_l.c doe not provide easy way to produce lowercase
> output. While the function to create lowercase is
> implemented, there is no flag which would cause it to be
> called. Provided patch checks, whether combination of
> to_uppcase and change_case flags is used and sets to_lowcase
> if both of them are set which leads to lower case output.
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-11-29 12:21 ` Jakub Martisko
@ 2016-11-29 12:42   ` Jakub Martisko
  2016-12-01 23:29     ` Rafal Luzynski
  0 siblings, 1 reply; 19+ messages in thread
From: Jakub Martisko @ 2016-11-29 12:42 UTC (permalink / raw)
  To: libc-alpha

Sorry, this was supposed to be a reply to:
https://sourceware.org/ml/libc-alpha/2016-06/msg00575.html

On 29.11.2016 13:21, Jakub Martisko wrote:
> Hi, are there any updates regarding this functionality?
> 
> On 15.6.2016 10:54, Jakub Martisko wrote:
>> strftime_l.c doe not provide easy way to produce lowercase
>> output. While the function to create lowercase is
>> implemented, there is no flag which would cause it to be
>> called. Provided patch checks, whether combination of
>> to_uppcase and change_case flags is used and sets to_lowcase
>> if both of them are set which leads to lower case output.
>>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-11-29 12:42   ` Jakub Martisko
@ 2016-12-01 23:29     ` Rafal Luzynski
  2016-12-05 14:55       ` Jakub Martisko
  0 siblings, 1 reply; 19+ messages in thread
From: Rafal Luzynski @ 2016-12-01 23:29 UTC (permalink / raw)
  To: libc-alpha, Jakub Martisko

Hi,

(Top-posting to conform to the style you already started. ;)

Your patch has drawn my attention. I must admit that I have not
analyzed it very thoroughly but OTOH I'm not the right person to
say the patch should be committed.

Only one question: what would be the order of applying
the flags? Should "%^#A" mean "convert to uppercase and then
swap" or "swap the case and then convert to uppercase" or
should it be an idiom to "convert to lowercase" no matter
what is the actual order? Should "%^#A" do the same as "%#^A"?

At first sight it may seem that usefulness of this feature
is limited: who would need a "convert to lowercase" switch
if all letters are already lowercase and those which are
uppercase (first letters of months names and weekdays names)
should always be uppercase?

But that's true only for English, German and maybe few other
languages. Not true for lots of others, including my and also
I guess your language. In many languages there is no rule
saying that month names and weekday names should always begin
with uppercase but other rules may apply: it should begin with
uppercase if it's a beginning of a sentence or a beginning of
a title. I really don't like months names (standalone) or weekday
names (a full date starting with a weekday name) starting with
lowercase just because in English they are always uppercase
and developers don't have to worry about it so they eventually
leave all other languages in all lowercase. I really wish there
was a strftime() flag converting words to titlecase. We have
"convert to uppercase" and "swap the case" but no "convert to
lowercase" nor "convert the first letter to uppercase". OTOH,
the implementation of this feature should not be left to the app
developers because not all languages need it, and converting
to the uppercase/titlecase is not a trivial task (in case of
UTF-8, how many bytes are occupied by the first letter? how
many bytes will its uppercase version occupy? does the letter
feature only lowercase and uppercase or is it a ligature
and has it a separate titlecase, like lj → Lj → LJ?) so better
should be implemented by a core library.

Unfortunately, I don't have a good candidate for a "convert
to lowercase" or a "convert to titlecase" switch. But your
patch solves the problem if we also provide all months names
and all weekday names in all locale data for all languages
in titlecase, even if a language does not require it by default.
Then we would have:

"%^A" - convert to uppercase => "SUNDAY";
"%#A" - swap the case => "sUNDAY" (yes, not useful);
"%^#A" - convert to lowercase => "sunday" (in the middle of
         a sentence, as required in many languages but not
         in English);
"%A" - leave unchanged, titlecase => "Sunday" (default, always
       in English and some other languages, required in the
       beginning of a sentence in many other languages).

We would have a way to convert all words to any (reasonable)
case and the decision would be always left for the translators
without any change in any application code. What do you guys think?

Regards,

Rafal


29.11.2016 13:41 Jakub Martisko <jamartis@redhat.com> wrote:
>
>
> Sorry, this was supposed to be a reply to:
> https://sourceware.org/ml/libc-alpha/2016-06/msg00575.html
>
> On 29.11.2016 13:21, Jakub Martisko wrote:
> > Hi, are there any updates regarding this functionality?
> >
> > On 15.6.2016 10:54, Jakub Martisko wrote:
> >> strftime_l.c doe not provide easy way to produce lowercase
> >> output. While the function to create lowercase is
> >> implemented, there is no flag which would cause it to be
> >> called. Provided patch checks, whether combination of
> >> to_uppcase and change_case flags is used and sets to_lowcase
> >> if both of them are set which leads to lower case output.
> >>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-12-01 23:29     ` Rafal Luzynski
@ 2016-12-05 14:55       ` Jakub Martisko
  2016-12-06 22:47         ` Rafal Luzynski
  0 siblings, 1 reply; 19+ messages in thread
From: Jakub Martisko @ 2016-12-05 14:55 UTC (permalink / raw)
  To: Rafal Luzynski, libc-alpha

Hello Rafal,

as for the order of ^# flags - right now the change case
flag works as an upper case flag for options which are in
title case by default (Sun -> SUN) and as lowercase for
those, which are in uppercase by default (AM -> am). In my
opinion, treating "%^#A" and "%#^A" as an idiom for lower
case makes the most sense. If you consider "%#^A", the
output would switch case (whatever that means) and then be
switched to uppercase. The "#" flag would thus be ignored.

As for the title case part of your message, I am probably
not the right person to answer it:-(.

Regards,
Jakub

On 2.12.2016 00:29, Rafal Luzynski wrote:
> Hi,
> 
> (Top-posting to conform to the style you already started. ;)
> 
> Your patch has drawn my attention. I must admit that I have not
> analyzed it very thoroughly but OTOH I'm not the right person to
> say the patch should be committed.
> 
> Only one question: what would be the order of applying
> the flags? Should "%^#A" mean "convert to uppercase and then
> swap" or "swap the case and then convert to uppercase" or
> should it be an idiom to "convert to lowercase" no matter
> what is the actual order? Should "%^#A" do the same as "%#^A"?
> 
> At first sight it may seem that usefulness of this feature
> is limited: who would need a "convert to lowercase" switch
> if all letters are already lowercase and those which are
> uppercase (first letters of months names and weekdays names)
> should always be uppercase?
> 
> But that's true only for English, German and maybe few other
> languages. Not true for lots of others, including my and also
> I guess your language. In many languages there is no rule
> saying that month names and weekday names should always begin
> with uppercase but other rules may apply: it should begin with
> uppercase if it's a beginning of a sentence or a beginning of
> a title. I really don't like months names (standalone) or weekday
> names (a full date starting with a weekday name) starting with
> lowercase just because in English they are always uppercase
> and developers don't have to worry about it so they eventually
> leave all other languages in all lowercase. I really wish there
> was a strftime() flag converting words to titlecase. We have
> "convert to uppercase" and "swap the case" but no "convert to
> lowercase" nor "convert the first letter to uppercase". OTOH,
> the implementation of this feature should not be left to the app
> developers because not all languages need it, and converting
> to the uppercase/titlecase is not a trivial task (in case of
> UTF-8, how many bytes are occupied by the first letter? how
> many bytes will its uppercase version occupy? does the letter
> feature only lowercase and uppercase or is it a ligature
> and has it a separate titlecase, like lj → Lj → LJ?) so better
> should be implemented by a core library.
> 
> Unfortunately, I don't have a good candidate for a "convert
> to lowercase" or a "convert to titlecase" switch. But your
> patch solves the problem if we also provide all months names
> and all weekday names in all locale data for all languages
> in titlecase, even if a language does not require it by default.
> Then we would have:
> 
> "%^A" - convert to uppercase => "SUNDAY";
> "%#A" - swap the case => "sUNDAY" (yes, not useful);
> "%^#A" - convert to lowercase => "sunday" (in the middle of
>          a sentence, as required in many languages but not
>          in English);
> "%A" - leave unchanged, titlecase => "Sunday" (default, always
>        in English and some other languages, required in the
>        beginning of a sentence in many other languages).
> 
> We would have a way to convert all words to any (reasonable)
> case and the decision would be always left for the translators
> without any change in any application code. What do you guys think?
> 
> Regards,
> 
> Rafal
> 
> 
> 29.11.2016 13:41 Jakub Martisko <jamartis@redhat.com> wrote:
>>
>>
>> Sorry, this was supposed to be a reply to:
>> https://sourceware.org/ml/libc-alpha/2016-06/msg00575.html
>>
>> On 29.11.2016 13:21, Jakub Martisko wrote:
>>> Hi, are there any updates regarding this functionality?
>>>
>>> On 15.6.2016 10:54, Jakub Martisko wrote:
>>>> strftime_l.c doe not provide easy way to produce lowercase
>>>> output. While the function to create lowercase is
>>>> implemented, there is no flag which would cause it to be
>>>> called. Provided patch checks, whether combination of
>>>> to_uppcase and change_case flags is used and sets to_lowcase
>>>> if both of them are set which leads to lower case output.
>>>>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-12-05 14:55       ` Jakub Martisko
@ 2016-12-06 22:47         ` Rafal Luzynski
  0 siblings, 0 replies; 19+ messages in thread
From: Rafal Luzynski @ 2016-12-06 22:47 UTC (permalink / raw)
  To: libc-alpha, Jakub Martisko

5.12.2016 15:55 Jakub Martisko <jamartis@redhat.com> wrote:
>
>
> Hello Rafal,
>
> as for the order of ^# flags - right now the change case
> flag works as an upper case flag for options which are in
> title case by default (Sun -> SUN) and as lowercase for
> those, which are in uppercase by default (AM -> am). In my
> opinion, treating "%^#A" and "%#^A" as an idiom for lower
> case makes the most sense. If you consider "%#^A", the
> output would switch case (whatever that means) and then be
> switched to uppercase. The "#" flag would thus be ignored.

Yes, that's true. Switching the case and then converting to
uppercase wouldn't make sense. And this is how your patch
works, as far as I remember: it switches to lowercase no matter
what is the order of "#" and "^".

I think that this either should be documented or (maybe better)
should be treated as an undefined behavior: not documented,
maybe producing bad results, maybe even producing correct
results, maybe will be changed in future. It may be also
explicitly documented as undefined behavior.

> As for the title case part of your message, I am probably
> not the right person to answer it:-(.

I don't think so. :-) I thought you were a non-English native
speaker; sorry if I'm wrong but if I'm not then you can
provide some valuable input here. How does it look in your
native language? Are all months and weekdays names always
written in lowercase? Wouldn't you like them to start with
an uppercase letter sometimes? For example, if you display
a calendar would you prefer "December" or "december"
in the header? Or if you display a date with a weekday
would you prefer "Wednesday, 7th of december" or
"wednesday, 7th of decebmer"? What is your solution to
achieve a proper result?

Regards,

Rafal

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-06-29  7:55   ` Jakub Martisko
@ 2016-12-06 23:20     ` Mike Frysinger
  2016-12-07 10:18       ` Jakub Martisko
  0 siblings, 1 reply; 19+ messages in thread
From: Mike Frysinger @ 2016-12-06 23:20 UTC (permalink / raw)
  To: Jakub Martisko; +Cc: libc-alpha

[-- Attachment #1: Type: text/plain, Size: 796 bytes --]

On 29 Jun 2016 09:55, Jakub Martisko wrote:
> thanks for your comment. The reason why I sent the patch is that there 
> is a bug/feature request for similar functionality in coreutils' "date" 
> program and the maintainers of coreutils/gnulib do not want to diverge 
> from the glibc interface. Even though the replacing you mentioned does 
> indeed work, built-in version would be imo better (for example when 
> using other shell than bash), especially when all of the needed 
> functionality was already implemented.

i think his point is that bash has already defined a syntax, but you
are doing it differently and there's (afaict) no need for it.  he isn't
saying you should use bash if you want lower/upper case.

so instead of adding new syntax like "%#^x", add "%,x"
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-06-15  8:54 [PATCH][BZ #15527] strftime_l.c: Support lowercase output Jakub Martisko
  2016-06-15  9:09 ` Andreas Schwab
  2016-11-29 12:21 ` Jakub Martisko
@ 2016-12-06 23:21 ` Mike Frysinger
  2 siblings, 0 replies; 19+ messages in thread
From: Mike Frysinger @ 2016-12-06 23:21 UTC (permalink / raw)
  To: Jakub Martisko; +Cc: libc-alpha

[-- Attachment #1: Type: text/plain, Size: 209 bytes --]

On 15 Jun 2016 10:54, Jakub Martisko wrote:
> +  /*case tests*/

seems like you should drop this comment

> +    }
>    return result + do_bz18985 ();

should be a blank line above this return statement
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-12-06 23:20     ` Mike Frysinger
@ 2016-12-07 10:18       ` Jakub Martisko
  2016-12-07 15:39         ` Mike Frysinger
  0 siblings, 1 reply; 19+ messages in thread
From: Jakub Martisko @ 2016-12-07 10:18 UTC (permalink / raw)
  To: libc-alpha, Mike Frysinger

[-- Attachment #1: Type: text/plain, Size: 907 bytes --]

Oh, my bad. That seems reasonable, sending new patch.
JM

On 7.12.2016 00:20, Mike Frysinger wrote:
> On 29 Jun 2016 09:55, Jakub Martisko wrote:
>> thanks for your comment. The reason why I sent the patch is that there 
>> is a bug/feature request for similar functionality in coreutils' "date" 
>> program and the maintainers of coreutils/gnulib do not want to diverge 
>> from the glibc interface. Even though the replacing you mentioned does 
>> indeed work, built-in version would be imo better (for example when 
>> using other shell than bash), especially when all of the needed 
>> functionality was already implemented.
> 
> i think his point is that bash has already defined a syntax, but you
> are doing it differently and there's (afaict) no need for it.  he isn't
> saying you should use bash if you want lower/upper case.
> 
> so instead of adding new syntax like "%#^x", add "%,x"
> -mike
> 

[-- Attachment #2: 0001-time-stfrtime_l.c-add-lowercase-support.patch --]
[-- Type: text/x-patch, Size: 2514 bytes --]

From 1289b48ee174bda5dc6266df1ed216f172fc5dd4 Mon Sep 17 00:00:00 2001
From: Jakub Martisko <jamartis@redhat.com>
Date: Wed, 7 Dec 2016 10:52:08 +0100
Subject: [PATCH] time/stfrtime_l.c: add lowercase support

* [BZ #15527]
* time/strftime_l.c (__strftime_internal): Implement conversion to
all lowercase.
* manual/time.texi: Document # and , flags.
* time/tst-strftime.c (do_test): Test case conversion.
---
 manual/time.texi    |  8 ++++++++
 time/strftime_l.c   |  4 +++-
 time/tst-strftime.c | 30 ++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/manual/time.texi b/manual/time.texi
index f94cbe4..39ed062 100644
--- a/manual/time.texi
+++ b/manual/time.texi
@@ -1352,6 +1352,14 @@ with spaces.
 @item ^
 The output uses uppercase characters, but only if this is possible
 (@pxref{Case Conversion}).
+
+@item #
+The output uses opposite case, but only if this is possible
+(@pxref{Case Conversion}).
+
+@item ,
+The output uses lowercase characters, but only if this is possible
+(@pxref{Case Conversion}).
 @end table
 
 The default action is to pad the number with zeros to keep it a constant
diff --git a/time/strftime_l.c b/time/strftime_l.c
index 1205035..6ed5f63 100644
--- a/time/strftime_l.c
+++ b/time/strftime_l.c
@@ -671,7 +671,9 @@ __strftime_internal (CHAR_T *s, size_t maxsize, const CHAR_T *format,
 	    case L_('#'):
 	      change_case = 1;
 	      continue;
-
+      case L_(','):
+  	      to_lowcase = 1;
+  	      continue;
 	    default:
 	      break;
 	    }
diff --git a/time/tst-strftime.c b/time/tst-strftime.c
index af3ff72..258d40a 100644
--- a/time/tst-strftime.c
+++ b/time/tst-strftime.c
@@ -154,6 +154,36 @@ do_test (void)
 	}
     }
 
+	const struct
+	  {
+	    const char *fmt;
+	    const char *exp;
+	    size_t n;
+	  } ctests[] =
+	    {
+	      { "%^A", "SUNDAY", 6 },
+	      { "%,A", "sunday", 6 },
+	      { "%A", "Sunday", 6 },
+	    };
+#define nctests (sizeof (ctests) / sizeof (ctests[0]))
+	  for (cnt = 0; cnt < nctests; ++cnt)
+    {
+      char buf[100];
+      size_t r = strftime (buf, sizeof (buf), ctests[cnt].fmt, &ttm);
+      if (r != ctests[cnt].n)
+	{
+	  printf ("strftime(\"%s\") returned %zu not %zu\n",
+		  ctests[cnt].fmt, r, ctests[cnt].n);
+	  result = 1;
+	}
+      if (strcmp (buf, ctests[cnt].exp) != 0)
+	{
+	  printf ("strftime(\"%s\") produced \"%s\" not \"%s\"\n",
+		  ctests[cnt].fmt, buf, ctests[cnt].exp);
+	  result = 1;
+	}
+    }
+
   return result + do_bz18985 ();
 }
 
-- 
2.5.5


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-12-07 10:18       ` Jakub Martisko
@ 2016-12-07 15:39         ` Mike Frysinger
  2016-12-09  1:14           ` Rafal Luzynski
  0 siblings, 1 reply; 19+ messages in thread
From: Mike Frysinger @ 2016-12-07 15:39 UTC (permalink / raw)
  To: Jakub Martisko; +Cc: libc-alpha

[-- Attachment #1: Type: text/plain, Size: 99 bytes --]

this makes sense to me.  might be good to get wider opinion about new
strftime flags though.
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-12-07 15:39         ` Mike Frysinger
@ 2016-12-09  1:14           ` Rafal Luzynski
  2016-12-09  4:08             ` Mike Frysinger
  0 siblings, 1 reply; 19+ messages in thread
From: Rafal Luzynski @ 2016-12-09  1:14 UTC (permalink / raw)
  To: Mike Frysinger, Jakub Martisko; +Cc: libc-alpha

7.12.2016 16:39 Mike Frysinger <vapier@gentoo.org> wrote:
> [...] might be good to get wider opinion about new
> strftime flags though.
> -mike

Now I lean a little against this change. As I wrote before,
I'd love to see a flag to change the first letter to uppercase
(or to titlecase, if that's more appropriate). A flag to change
whole string to lowercase would be a workaround for this problem
if we also converted all months and weekdays names to the
titlecase in all languages, like in English now. So we would have:

- titlecase by default,
- lowercase if a flag is added explicitly,
- uppercase if a flag is added explicitly.

All reasonable cases covered. Except that converting all locale
data would cause some problems to existing software and that
it wouldn't help the applications which retrieve the months names
or weekdays names with nl_langinfo() rather than strftime().
So indeed I think that a flag to convert to titlecase would
be more useful.

But in that case, do you guys think that converting to lowercase
is useful if all letters are either lowercase already or should
be always as they are now? Can you explain why would any application
ever need the lowercase which should be provided by a format flag
rather than converting programmatically? It seems to be useful
only if some locales want to convert some data to lowercase and
they don't have it lowercase out of the box.

Regards,

Rafal

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-12-09  1:14           ` Rafal Luzynski
@ 2016-12-09  4:08             ` Mike Frysinger
  2016-12-09 11:00               ` Rafal Luzynski
  0 siblings, 1 reply; 19+ messages in thread
From: Mike Frysinger @ 2016-12-09  4:08 UTC (permalink / raw)
  To: Rafal Luzynski; +Cc: Jakub Martisko, libc-alpha

[-- Attachment #1: Type: text/plain, Size: 1705 bytes --]

On 09 Dec 2016 02:14, Rafal Luzynski wrote:
> 7.12.2016 16:39 Mike Frysinger wrote:
> > [...] might be good to get wider opinion about new
> > strftime flags though.
> 
> Now I lean a little against this change. As I wrote before,
> I'd love to see a flag to change the first letter to uppercase
> (or to titlecase, if that's more appropriate). A flag to change
> whole string to lowercase would be a workaround for this problem
> if we also converted all months and weekdays names to the
> titlecase in all languages, like in English now.

i don't think changing the locale data or forcing titlecase everywhere
makes sense.  the data is already in the standard format that users
expect for their locale.  having a flag to support that seems like a
good way to get developers to naively enforce their own expectations
onto users.  "my language writes things like 'Dec', therefore every
language out there must use titlecase".

forcing to all uppercase or lowercase seems a bit more reasonable in
certain outputs (everything is upper/lower case beyond the date).

> But in that case, do you guys think that converting to lowercase
> is useful if all letters are either lowercase already or should
> be always as they are now? Can you explain why would any application
> ever need the lowercase which should be provided by a format flag
> rather than converting programmatically? It seems to be useful
> only if some locales want to convert some data to lowercase and
> they don't have it lowercase out of the box.

we already have a flag to force it to uppercase.  makes sense to have
a flag to do the opposite.  your arguments here apply to the uppercase
flag too.
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-12-09  4:08             ` Mike Frysinger
@ 2016-12-09 11:00               ` Rafal Luzynski
  2016-12-09 16:20                 ` Mike Frysinger
  0 siblings, 1 reply; 19+ messages in thread
From: Rafal Luzynski @ 2016-12-09 11:00 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: libc-alpha, Jakub Martisko

9.12.2016 05:07 Mike Frysinger <vapier@gentoo.org> wrote:
>
>
> On 09 Dec 2016 02:14, Rafal Luzynski wrote:
> > 7.12.2016 16:39 Mike Frysinger wrote:
> > > [...] might be good to get wider opinion about new
> > > strftime flags though.
> >
> > Now I lean a little against this change. As I wrote before,
> > I'd love to see a flag to change the first letter to uppercase
> > (or to titlecase, if that's more appropriate). A flag to change
> > whole string to lowercase would be a workaround for this problem
> > if we also converted all months and weekdays names to the
> > titlecase in all languages, like in English now.
>
> i don't think changing the locale data or forcing titlecase everywhere
> makes sense. the data is already in the standard format that users
> expect for their locale. having a flag to support that seems like a
> good way to get developers to naively enforce their own expectations
> onto users. "my language writes things like 'Dec', therefore every
> language out there must use titlecase".

That's really not what I meant. I meant that switching all locale
data to titlecase would be possible only if there was a flag to
switch back to lowercase.

Yes, in my language (and I think that in most languages) we have
all months names and weekdays names in lowercase and this is correct
by default. But we have no flag to switch to titlecase and
I think it would be useful sometimes.

>
> forcing to all uppercase or lowercase seems a bit more reasonable in
> certain outputs (everything is upper/lower case beyond the date).
>
> > But in that case, do you guys think that converting to lowercase
> > is useful if all letters are either lowercase already or should
> > be always as they are now? Can you explain why would any application
> > ever need the lowercase which should be provided by a format flag
> > rather than converting programmatically? It seems to be useful
> > only if some locales want to convert some data to lowercase and
> > they don't have it lowercase out of the box.
>
> we already have a flag to force it to uppercase. makes sense to have
> a flag to do the opposite. your arguments here apply to the uppercase
> flag too.
> -mike

No, does not. I didn't say anything about uppercase, if I had
to say I'd say it's correct so let's leave it as it is now.
What I wanted to say is that we don't have a flag to switch
to titlecase.

My question was: what is the real problem solved by implementing
a flag to switch to lowercase?

And my suggestion is that it would be useful only if a locale
allows all-lowercase months or weekdays but locale data deliver
non-lowercase. For example titlecase. This would solve two problems:
- provide titlecase,
- provide an easy way to generate lowercase.

Regards,

Rafal

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-12-09 11:00               ` Rafal Luzynski
@ 2016-12-09 16:20                 ` Mike Frysinger
  2016-12-09 22:37                   ` Rafal Luzynski
  0 siblings, 1 reply; 19+ messages in thread
From: Mike Frysinger @ 2016-12-09 16:20 UTC (permalink / raw)
  To: Rafal Luzynski; +Cc: libc-alpha, Jakub Martisko

[-- Attachment #1: Type: text/plain, Size: 3935 bytes --]

On 09 Dec 2016 12:00, Rafal Luzynski wrote:
> 9.12.2016 05:07 Mike Frysinger wrote:
> > On 09 Dec 2016 02:14, Rafal Luzynski wrote:
> > > 7.12.2016 16:39 Mike Frysinger wrote:
> > > > [...] might be good to get wider opinion about new
> > > > strftime flags though.
> > >
> > > Now I lean a little against this change. As I wrote before,
> > > I'd love to see a flag to change the first letter to uppercase
> > > (or to titlecase, if that's more appropriate). A flag to change
> > > whole string to lowercase would be a workaround for this problem
> > > if we also converted all months and weekdays names to the
> > > titlecase in all languages, like in English now.
> >
> > i don't think changing the locale data or forcing titlecase everywhere
> > makes sense. the data is already in the standard format that users
> > expect for their locale. having a flag to support that seems like a
> > good way to get developers to naively enforce their own expectations
> > onto users. "my language writes things like 'Dec', therefore every
> > language out there must use titlecase".
> 
> That's really not what I meant. I meant that switching all locale
> data to titlecase would be possible only if there was a flag to
> switch back to lowercase.

i'm saying the flags are irrelevant.  the data should be in the form
that is appropriate for that locale.  that might mean uppercase, or
lowercase, or titlecase.  flags would not help at all, and in fact,
they would make things worse.  en_US authors would see that, think
that it's weird looking, and then use the titlecase flag.  then it'd
be broken for many other locales.

> Yes, in my language (and I think that in most languages) we have
> all months names and weekdays names in lowercase and this is correct
> by default. But we have no flag to switch to titlecase and
> I think it would be useful sometimes.

i have a hard time seeing a valid usecase where the code forcing
titlecase all the time would be desirable.  forcing all lower or
upper case isn't that hard to imagine (e.g. output forms where
*all* content, not just dates, are in the respective cases).

> > forcing to all uppercase or lowercase seems a bit more reasonable in
> > certain outputs (everything is upper/lower case beyond the date).
> >
> > > But in that case, do you guys think that converting to lowercase
> > > is useful if all letters are either lowercase already or should
> > > be always as they are now? Can you explain why would any application
> > > ever need the lowercase which should be provided by a format flag
> > > rather than converting programmatically? It seems to be useful
> > > only if some locales want to convert some data to lowercase and
> > > they don't have it lowercase out of the box.
> >
> > we already have a flag to force it to uppercase. makes sense to have
> > a flag to do the opposite. your arguments here apply to the uppercase
> > flag too.
> 
> No, does not. I didn't say anything about uppercase, if I had
> to say I'd say it's correct so let's leave it as it is now.
> What I wanted to say is that we don't have a flag to switch
> to titlecase.
> 
> My question was: what is the real problem solved by implementing
> a flag to switch to lowercase?

i didn't say you talked about uppercase.  my point is that your argument
isn't specific to lowercase.  you could s/lower/upper/ and have the same
points.  so why do you think having uppercase makes sense but adding
lowercase is wrong ?

> And my suggestion is that it would be useful only if a locale
> allows all-lowercase months or weekdays but locale data deliver
> non-lowercase. For example titlecase. This would solve two problems:
> - provide titlecase,
> - provide an easy way to generate lowercase.

locale data cannot be changed.  adding flags to transform their case
would not help the situation at all, just make it worse.
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-12-09 16:20                 ` Mike Frysinger
@ 2016-12-09 22:37                   ` Rafal Luzynski
  2017-04-07 23:29                     ` Rafal Luzynski
  0 siblings, 1 reply; 19+ messages in thread
From: Rafal Luzynski @ 2016-12-09 22:37 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: libc-alpha, Jakub Martisko

9.12.2016 17:20 Mike Frysinger <vapier@gentoo.org> wrote:
>
>
> On 09 Dec 2016 12:00, Rafal Luzynski wrote:
> > [...]
> > That's really not what I meant. I meant that switching all locale
> > data to titlecase would be possible only if there was a flag to
> > switch back to lowercase.
>
> i'm saying the flags are irrelevant. the data should be in the form
> that is appropriate for that locale. that might mean uppercase, or
> lowercase, or titlecase. flags would not help at all, and in fact,
> they would make things worse. en_US authors would see that, think
> that it's weird looking, and then use the titlecase flag. then it'd
> be broken for many other locales.

Format strings should be translatable and it should be left to
translators what format string and what flags they want. An application
should present all messages, format strings, and date/time data
either in en_US or all should be localized, otherwise we
get some unfinished mix of localized/not-yet-localized.
So although it's correct to use titlecase in English it should not
be relevant for other languages.

> > Yes, in my language (and I think that in most languages) we have
> > all months names and weekdays names in lowercase and this is correct
> > by default. But we have no flag to switch to titlecase and
> > I think it would be useful sometimes.
>
> i have a hard time seeing a valid usecase where the code forcing
> titlecase all the time would be desirable.

No, I didn't mean a code forcing titlecase all the time.  My aim
is to provide a choice: lowercase/titlecase/uppercase, for each
format specifier individually.  For now in English (and German)
we have titlecase/uppercase, in other languages we have lowercase/uppercase.
What is a solution to provide the missing case?

> forcing all lower or
> upper case isn't that hard to imagine (e.g. output forms where
> *all* content, not just dates, are in the respective cases).

I agree with the uppercase, but is it really useful to have
all lowercase in English?

> > > [...]
> > > we already have a flag to force it to uppercase. makes sense to have
> > > a flag to do the opposite. your arguments here apply to the uppercase
> > > flag too.
> >
> > No, does not. I didn't say anything about uppercase, if I had
> > to say I'd say it's correct so let's leave it as it is now.
> > What I wanted to say is that we don't have a flag to switch
> > to titlecase.
> >
> > My question was: what is the real problem solved by implementing
> > a flag to switch to lowercase?
>
> i didn't say you talked about uppercase. my point is that your argument
> isn't specific to lowercase. you could s/lower/upper/ and have the same
> points. so why do you think having uppercase makes sense but adding
> lowercase is wrong ?

Because we already have all data in lowercase.  No need to convert
from lowercase to lowercase.  More precisely: in some languages
the data are in titlecase but should remain so, converting them
to lowercase is incorrect.

My point is not that lowercase flag is wrong or destructive,
I just think it does not provide any additional value.

A separate problem is that there is no flag to convert to
titlecase.  My suggestion is that if we had locale data in
titlecase (like in English) and a flag to convert them to
lowercase explicitly then it would be a workaround.  Of course
a titlecase flag would be better.  But, again, that's a separate
case, only similar to the lowercase flag.

Regards,

Rafal

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH][BZ #15527] strftime_l.c: Support lowercase output
  2016-12-09 22:37                   ` Rafal Luzynski
@ 2017-04-07 23:29                     ` Rafal Luzynski
  0 siblings, 0 replies; 19+ messages in thread
From: Rafal Luzynski @ 2017-04-07 23:29 UTC (permalink / raw)
  To: libc-alpha; +Cc: Jakub Martisko

Hi,

This thread has been started almost one year ago [1] but has been
inactive for last 4 months. [2] What is its current progress? Do you
guys think about continuing this work and eventually committing it
to the main repo?

I think that my previous comments could be misunderstood. I didn't
mean that the patch is bad, I just wonder what is its application
and whether Jakub, the author, can see any and whether it is the
same application as I see.

Regards,

Rafal


[1] https://sourceware.org/ml/libc-alpha/2016-05/msg00259.html
[2] https://sourceware.org/ml/libc-alpha/2016-12/msg00034.html

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH][BZ 15527] strftime_l.c: Support lowercase output
@ 2016-05-12 15:26 Jakub Martisko
  0 siblings, 0 replies; 19+ messages in thread
From: Jakub Martisko @ 2016-05-12 15:26 UTC (permalink / raw)
  To: libc-alpha

[-- Attachment #1: Type: text/plain, Size: 344 bytes --]

strftime_l.c doe not provide easy way to produce lowercase output. While 
the function to create lowercase is implemented, there is no flag which 
would cause it to be called. Provided patch checks, whether combination 
of to_uppcase and change_case flags is used and sets to_lowcase if both 
of them are set which leads to lower case output.


[-- Attachment #2: 0001-PATCH-.-time-strftime_l.c-add-lowercase-support.patch --]
[-- Type: text/x-patch, Size: 2468 bytes --]

2016-05-12  Jakub Martisko  <jamartis@redhat.com>

	* [BZ #15527]
	* time/strftime_l.c (__strftime_internal): Implement conversion to
	all lowercase.
	* manual/time.texi: Document # flag.
	* time/tst-strftime.c (do_test): Test case conversion.



---
 manual/time.texi    |  6 +++++-
 time/strftime_l.c   |  7 ++++++-
 time/tst-strftime.c | 31 ++++++++++++++++++++++++++++++-
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/manual/time.texi b/manual/time.texi
index f94cbe4..a65959f 100644
--- a/manual/time.texi
+++ b/manual/time.texi
@@ -1350,7 +1350,11 @@ The number is padded with zeros even if the format specifies padding
 with spaces.
 
 @item ^
-The output uses uppercase characters, but only if this is possible
+The output uses uppercase characters, but only if this is possible.
+
+@item #
+The output uses opposite case characters, but only if this is possible.
+Can be combined with @samp{^} to produce lowercase characters.
 (@pxref{Case Conversion}).
 @end table
 
diff --git a/time/strftime_l.c b/time/strftime_l.c
index 1205035..c577f28 100644
--- a/time/strftime_l.c
+++ b/time/strftime_l.c
@@ -677,7 +677,12 @@ __strftime_internal (CHAR_T *s, size_t maxsize, const CHAR_T *format,
 	    }
 	  break;
 	}
-
+	if (to_uppcase == 1 && change_case == 1)
+	{
+	  to_uppcase = 0;
+	  change_case = 0;
+	  to_lowcase = 1;
+	}
       /* As a GNU extension we allow to specify the field width.  */
       if (ISDIGIT (*f))
 	{
diff --git a/time/tst-strftime.c b/time/tst-strftime.c
index af3ff72..e369595 100644
--- a/time/tst-strftime.c
+++ b/time/tst-strftime.c
@@ -153,7 +153,36 @@ do_test (void)
 	  result = 1;
 	}
     }
-
+  /*case tests*/
+	const struct
+	  {
+	    const char *fmt;
+	    const char *exp;
+	    size_t n;
+	  } ctests[] =
+	    {
+	      { "%^A", "SUNDAY", 6 },
+	      { "%^#A", "sunday", 6 },
+	      { "%A", "Sunday", 6 },
+	    };
+#define nctests (sizeof (ctests) / sizeof (ctests[0]))
+	  for (cnt = 0; cnt < nctests; ++cnt)
+    {
+      char buf[100];
+      size_t r = strftime (buf, sizeof (buf), ctests[cnt].fmt, &ttm);
+      if (r != ctests[cnt].n)
+	{
+	  printf ("strftime(\"%s\") returned %zu not %zu\n",
+		  ctests[cnt].fmt, r, ctests[cnt].n);
+	  result = 1;
+	}
+      if (strcmp (buf, ctests[cnt].exp) != 0)
+	{
+	  printf ("strftime(\"%s\") produced \"%s\" not \"%s\"\n",
+		  ctests[cnt].fmt, buf, ctests[cnt].exp);
+	  result = 1;
+	}
+    }
   return result + do_bz18985 ();
 }
 
-- 
2.5.0



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2017-04-07 23:29 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-15  8:54 [PATCH][BZ #15527] strftime_l.c: Support lowercase output Jakub Martisko
2016-06-15  9:09 ` Andreas Schwab
2016-06-29  7:55   ` Jakub Martisko
2016-12-06 23:20     ` Mike Frysinger
2016-12-07 10:18       ` Jakub Martisko
2016-12-07 15:39         ` Mike Frysinger
2016-12-09  1:14           ` Rafal Luzynski
2016-12-09  4:08             ` Mike Frysinger
2016-12-09 11:00               ` Rafal Luzynski
2016-12-09 16:20                 ` Mike Frysinger
2016-12-09 22:37                   ` Rafal Luzynski
2017-04-07 23:29                     ` Rafal Luzynski
2016-11-29 12:21 ` Jakub Martisko
2016-11-29 12:42   ` Jakub Martisko
2016-12-01 23:29     ` Rafal Luzynski
2016-12-05 14:55       ` Jakub Martisko
2016-12-06 22:47         ` Rafal Luzynski
2016-12-06 23:21 ` Mike Frysinger
  -- strict thread matches above, loose matches on Subject: below --
2016-05-12 15:26 [PATCH][BZ 15527] " Jakub Martisko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).