stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r378756 - in /incubator/stdcxx/trunk/tests: self/0.printf.cpp src/printf.cpp
Date Sat, 18 Feb 2006 18:37:12 GMT
Author: sebor
Date: Sat Feb 18 10:37:11 2006
New Revision: 378756

URL: http://svn.apache.org/viewcvs?rev=378756&view=rev
Log:
2006-02-18  Martin Sebor  <sebor@roguewave.com>

	* printf.cpp (A_ARRAY): New bit.
	(rw_fmtarray, _rw_fmtwstr): Changed character array formatting
	so as to prepend the 'L' prefix only to generic character arrays
	parametrized on the width of the character type.
	(_rw_fmtarray): Set the A_ARRAY bit.
	(_rw_fmtwchr): Formatted -1 as EOF (no quotes).
	* 0.printf.cpp: Exercised the above changes, specifically that
	the 'L' prefix is only prepended to quoted generic characters
	and arrays of such things parametrized on the width of the
	character type.

Modified:
    incubator/stdcxx/trunk/tests/self/0.printf.cpp
    incubator/stdcxx/trunk/tests/src/printf.cpp

Modified: incubator/stdcxx/trunk/tests/self/0.printf.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/self/0.printf.cpp?rev=378756&r1=378755&r2=378756&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/self/0.printf.cpp (original)
+++ incubator/stdcxx/trunk/tests/self/0.printf.cpp Sat Feb 18 10:37:11 2006
@@ -267,21 +267,23 @@
     TEST ("%{lc}", L'A',    0, 0, "A");
     TEST ("%{lc}", L'Z',    0, 0, "Z");
     TEST ("%{lc}", L'\xff', 0, 0, "\\xff");
+    TEST ("%{lc}", -1,      0, 0, "EOF");
 
     //////////////////////////////////////////////////////////////////
     printf ("%s\n", "extension: \"%{#lc}\": quoted escaped wide character");
 
-    TEST ("%{#lc}", L'\0',   0, 0, "L'\\0'");
-    TEST ("%{#lc}", L'\5',   0, 0, "L'\\x05'");
-    TEST ("%{#lc}", L'\a',   0, 0, "L'\\a'");
-    TEST ("%{#lc}", L'\n',   0, 0, "L'\\n'");
-    TEST ("%{#lc}", L'\r',   0, 0, "L'\\r'");
-    TEST ("%{#lc}", L'\t',   0, 0, "L'\\t'");
-    TEST ("%{#lc}", L'0',    0, 0, "L'0'");
-    TEST ("%{#lc}", L'1',    0, 0, "L'1'");
-    TEST ("%{#lc}", L'A',    0, 0, "L'A'");
-    TEST ("%{#lc}", L'Z',    0, 0, "L'Z'");
-    TEST ("%{#lc}", L'\xff', 0, 0, "L'\\xff'");
+    TEST ("%{#lc}", L'\0',   0, 0, "'\\0'");
+    TEST ("%{#lc}", L'\5',   0, 0, "'\\x05'");
+    TEST ("%{#lc}", L'\a',   0, 0, "'\\a'");
+    TEST ("%{#lc}", L'\n',   0, 0, "'\\n'");
+    TEST ("%{#lc}", L'\r',   0, 0, "'\\r'");
+    TEST ("%{#lc}", L'\t',   0, 0, "'\\t'");
+    TEST ("%{#lc}", L'0',    0, 0, "'0'");
+    TEST ("%{#lc}", L'1',    0, 0, "'1'");
+    TEST ("%{#lc}", L'A',    0, 0, "'A'");
+    TEST ("%{#lc}", L'Z',    0, 0, "'Z'");
+    TEST ("%{#lc}", L'\xff', 0, 0, "'\\xff'");
+    TEST ("%{#lc}", -1,      0, 0, "EOF");
 }
 
 /***********************************************************************/
@@ -367,20 +369,19 @@
     //////////////////////////////////////////////////////////////////
     printf ("%s\n", "extension: \"%{#ls}\": quoted wide character string");
 
-    TEST ("%{#ls}", L"",     0, 0, "L\"\"");
-    TEST ("%{#ls}", L"\1",   0, 0, "L\"\\x01\"");
-    TEST ("%{#ls}", L"\a",   0, 0, "L\"\\a\"");
-    TEST ("%{#ls}", L"\n",   0, 0, "L\"\\n\"");
-    TEST ("%{#ls}", L"\r",   0, 0, "L\"\\r\"");
-    TEST ("%{#ls}", L"\t",   0, 0, "L\"\\t\"");
-    TEST ("%{#ls}", L"\v",   0, 0, "L\"\\v\"");
-    TEST ("%{#ls}", L"a",    0, 0, "L\"a\"");
-    TEST ("%{#ls}", L"ab",   0, 0, "L\"ab\"");
-    TEST ("%{#ls}", L"abc",  0, 0, "L\"abc\"");
-    TEST ("%{#ls}", L"a\ac", 0, 0, "L\"a\\ac\"");
-    TEST ("%{#ls}", L"a\"c", 0, 0, "L\"a\\\"c\"");
-
-    TEST ("%{#ls}", L"\x100", 0, 0, "L\"\\x100\"");
+    TEST ("%{#ls}", L"",      0, 0, "\"\"");
+    TEST ("%{#ls}", L"\1",    0, 0, "\"\\x01\"");
+    TEST ("%{#ls}", L"\a",    0, 0, "\"\\a\"");
+    TEST ("%{#ls}", L"\n",    0, 0, "\"\\n\"");
+    TEST ("%{#ls}", L"\r",    0, 0, "\"\\r\"");
+    TEST ("%{#ls}", L"\t",    0, 0, "\"\\t\"");
+    TEST ("%{#ls}", L"\v",    0, 0, "\"\\v\"");
+    TEST ("%{#ls}", L"a",     0, 0, "\"a\"");
+    TEST ("%{#ls}", L"ab",    0, 0, "\"ab\"");
+    TEST ("%{#ls}", L"abc",   0, 0, "\"abc\"");
+    TEST ("%{#ls}", L"a\ac",  0, 0, "\"a\\ac\"");
+    TEST ("%{#ls}", L"a\"c",  0, 0, "\"a\\\"c\"");
+    TEST ("%{#ls}", L"\x100", 0, 0, "\"\\x100\"");
 }
 
 /***********************************************************************/
@@ -541,13 +542,13 @@
     TEST ("%{lS}",  WS ("ab"),         0, 0, "ab");
     TEST ("%{lS}",  WS ("abc"),        0, 0, "abc");
 
-    TEST ("%{#lS}", WS ("\a\n\r\t\v"), 0, 0, "L\"\\a\\n\\r\\t\\v\"");
+    TEST ("%{#lS}", WS ("\a\n\r\t\v"), 0, 0, "\"\\a\\n\\r\\t\\v\"");
 
-    TEST ("%{#lS}", WS ("\0bc"),       0, 0, "L\"\\0bc\"");
-    TEST ("%{#lS}", WS ("a\0c"),       0, 0, "L\"a\\0c\"");
-    TEST ("%{#lS}", WS ("ab\0"),       0, 0, "L\"ab\\0\"");
-    TEST ("%{#lS}", WS ("a\0\0"),      0, 0, "L\"a\\0\\0\"");
-    TEST ("%{#lS}", WS ("\0\0\0"),     0, 0, "L\"\\0\\0\\0\"");
+    TEST ("%{#lS}", WS ("\0bc"),       0, 0, "\"\\0bc\"");
+    TEST ("%{#lS}", WS ("a\0c"),       0, 0, "\"a\\0c\"");
+    TEST ("%{#lS}", WS ("ab\0"),       0, 0, "\"ab\\0\"");
+    TEST ("%{#lS}", WS ("a\0\0"),      0, 0, "\"a\\0\\0\"");
+    TEST ("%{#lS}", WS ("\0\0\0"),     0, 0, "\"\\0\\0\\0\"");
 
 #else   // if defined (_RWSTD_NO_WCHAR_T)
 

Modified: incubator/stdcxx/trunk/tests/src/printf.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/printf.cpp?rev=378756&r1=378755&r2=378756&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/printf.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/printf.cpp Sat Feb 18 10:37:11 2006
@@ -2668,7 +2668,8 @@
 enum {
     A_ESC   = 1,        // use escape sequences
     A_CHAR  = 1 << 1,   // format each element as a char
-    A_WCHAR = 1 << 2    // format each element as a wchar_t
+    A_WCHAR = 1 << 2,   // format each element as a wchar_t
+    A_ARRAY = 1 << 3    // generic array formatting
 };
 
 template <class elemT>
@@ -2718,7 +2719,12 @@
 
         }
         else {
-            if (_RWSTD_WCHAR_T_SIZE == sizeof (elemT))
+            // append 'L' for a generic array (i.e., one whose type
+            // is not known to be wchar_t) that is the same size as
+            // wchar_t (bot not for an array of wchar_t's being
+            // formatted using the {%ls} directive -- the caller
+            // can easily stick the 'L' there themselves)
+            if (flags & A_ARRAY && _RWSTD_WCHAR_T_SIZE == sizeof (elemT))
                 *next++ = 'L';
 
             *next++ = '"';
@@ -2803,11 +2809,11 @@
 
             if (last_repeat < 0) {
                 if (flags & (A_CHAR | A_WCHAR)) {
-                    // insert an opening quote (preceded by the 'L'
-                    // prefix for wchar_t arrays)
-                    if (_RWSTD_WCHAR_T_SIZE == sizeof (elemT)) {
+                    if (   (flags & A_ARRAY)
+                        && _RWSTD_WCHAR_T_SIZE == sizeof (elemT))
                         *s++ = 'L';
-                    }
+
+                    // insert an opening quote
                     *s++ = '\"';
                 }
             }
@@ -2908,8 +2914,9 @@
     const int width = spec.width;
     spec.width = -1;
 
-    const int flags = 'c' == spec.cvtspec ?
-        A_CHAR | A_ESC : spec.fl_pound ? A_ESC : 0;
+    const int flags = A_ARRAY
+        | ('c' == spec.cvtspec || 'S' == spec.cvtspec ?
+          A_CHAR | A_ESC : spec.fl_pound ? A_ESC : 0);
 
     // to format an array of integers using the 0 or 0x/0X prefix
     // both the pound and the zero flags must be set; clear the pound
@@ -2979,6 +2986,7 @@
     const UChar uc = UChar (val);
 
     char buffer [8];
+
     int len = rw_quotechar (buffer + spec.fl_pound, uc, noesc);
     if (spec.fl_pound) {
         buffer [0] = buffer [len + 1] = '\'';
@@ -2999,15 +3007,27 @@
 _rw_fmtwchr (const FmtSpec &spec, char **pbuf, size_t *pbufsize,
              wint_t val, int noesc)
 {
-    const wchar_t wc = wchar_t (val);
-
     char buffer [16];
-    int len = rw_quotechar (buffer + 2 * spec.fl_pound, wc, noesc);
-    if (spec.fl_pound) {
-        buffer [0] = 'L';
-        buffer [1] = buffer [len + 2] = '\'';
-        buffer [len + 3] = '\0';
-        len += 3;
+    int  len;
+
+    if (0 == noesc && -1 == val) {
+
+        // format EOF
+        buffer [0] = 'E';
+        buffer [1] = 'O';
+        buffer [2] = 'F';
+        buffer [3] = '\0';
+        len = 3;
+    }
+    else {
+        const wchar_t wc = wchar_t (val);
+
+        len = rw_quotechar (buffer + spec.fl_pound, wc, noesc);
+        if (spec.fl_pound) {
+            buffer [0] = buffer [len + 1] = '\'';
+            buffer [len + 2] = '\0';
+            len += 2;
+        }
     }
 
     FmtSpec newspec (spec);
@@ -3080,8 +3100,18 @@
 _rw_fmtwstr (const FmtSpec &spec,
             char **pbuf, size_t *pbufsize, const wchar_t *wstr, size_t len)
 {
-    if (spec.fl_pound)
-        return rw_fmtarray (spec, pbuf, pbufsize, wstr, len, A_WCHAR | A_ESC);
+    if (spec.fl_pound) {
+
+        // set up flags so that %{#*S} for generic basic_string quoted
+        // formatting (i.e., parametrized on the size of the character
+        // type) prepends a 'L' to the quoted string when the character
+        // type is (likely to be) wchar_t
+        const int flags =
+              ('S' == spec.cvtspec && -1 != spec.width ? A_ARRAY : 0)
+            | A_WCHAR | A_ESC;
+
+        return rw_fmtarray (spec, pbuf, pbufsize, wstr, len, flags);
+    }
 
     if (0 == wstr || 0 > _RW::__rw_memattr (wstr, _RWSTD_SIZE_MAX, 0))
         return _rw_fmtbadaddr (spec, pbuf, pbufsize, wstr);



Mime
View raw message