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
* [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).