stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r426343 - in /incubator/stdcxx/trunk/tests: self/0.printf.cpp src/printf.cpp
Date Fri, 28 Jul 2006 00:50:15 GMT
Author: sebor
Date: Thu Jul 27 17:50:15 2006
New Revision: 426343

URL: http://svn.apache.org/viewvc?rev=426343&view=rev
Log:
2006-07-27  Martin Sebor  <sebor@roguewave.com>

	* src/printf.cpp (_rw_fmtstrarray): New function to format argv-style
	(i.e., null-terminated) arrays of NUL-terminated character strings.
	(_rw_vasnprintf_ex): Called _rw_fmtstrarray to process the "%{As}"
	formatting directive.
	* test/0.printf.cpp (test_stringarray): Exercised the above.

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/viewvc/incubator/stdcxx/trunk/tests/self/0.printf.cpp?rev=426343&r1=426342&r2=426343&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/self/0.printf.cpp (original)
+++ incubator/stdcxx/trunk/tests/self/0.printf.cpp Thu Jul 27 17:50:15 2006
@@ -6,22 +6,23 @@
  *
  ************************************************************************
  *
- * Copyright 2006 The Apache Software Foundation or its licensors,
- * as applicable.
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
  *
- * Copyright 2005-2006 Rogue Wave Software.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 2005-2006 Rogue Wave Software.
  * 
  **************************************************************************/
 
@@ -626,6 +627,58 @@
 
 /***********************************************************************/
 
+static const char**
+mkargv (const char *arg0 = 0,
+        const char *arg1 = 0,
+        const char *arg2 = 0,
+        const char *arg3 = 0,
+        const char *arg4 = 0,
+        const char *arg5 = 0,
+        const char *arg6 = 0,
+        const char *arg7 = 0,
+        const char *arg8 = 0,
+        const char *arg9 = 0)
+{
+    static const char* argv [10];
+
+    argv [0] = arg0;
+    argv [1] = arg1;
+    argv [2] = arg2;
+    argv [3] = arg3;
+    argv [4] = arg4;
+    argv [5] = arg5;
+    argv [6] = arg6;
+    argv [7] = arg7;
+    argv [8] = arg8;
+    argv [9] = arg9;
+
+    return argv;
+}
+
+
+static void
+test_stringarray ()
+{
+    //////////////////////////////////////////////////////////////////
+    printf ("%s\n", "extension: \"%{As}\": array of character strings");
+
+#undef ARG
+#define ARG   mkargv
+
+    TEST ("%{As}", 0,                              0, 0, "(null)");
+    TEST ("%{As}", ARG ("a"),                      0, 0, "a");
+    TEST ("%{As}", ARG ("a", "bc"),                0, 0, "a,bc");
+    TEST ("%{As}", ARG ("a", "bc", "def"),         0, 0, "a,bc,def");
+    TEST ("%{As}", ARG ("a", "bc", "def", "ghij"), 0, 0, "a,bc,def,ghij");
+
+    TEST ("%{#As}", 0,                         0, 0, "(null)");
+    TEST ("%{#As}", ARG ("abcd"),              0, 0, "\"abcd\"");
+    TEST ("%{#As}", ARG ("abcd", "efg"),       0, 0, "\"abcd\",\"efg\"");
+    TEST ("%{#As}", ARG ("abcd", "efg", "hi"), 0, 0, "\"abcd\",\"efg\",\"hi\"");
+}
+
+/***********************************************************************/
+
 static void
 test_basic_string ()
 {
@@ -2756,6 +2809,7 @@
     test_character ();
     test_string ();
     test_chararray ();
+    test_stringarray ();
 
     test_integer ();
     test_intarray ();

Modified: incubator/stdcxx/trunk/tests/src/printf.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/printf.cpp?rev=426343&r1=426342&r2=426343&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/printf.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/printf.cpp Thu Jul 27 17:50:15 2006
@@ -6,22 +6,23 @@
  *
  ************************************************************************
  *
- * Copyright 2006 The Apache Software Foundation or its licensors,
- * as applicable.
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
  *
- * Copyright 2005-2006 Rogue Wave Software.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 2005-2006 Rogue Wave Software.
  * 
  **************************************************************************/
 
@@ -128,6 +129,10 @@
 static int
 _rw_fmtwstr (const FmtSpec&, Buffer&, const wchar_t*, size_t);
 
+// format an argv-style (null-terminated) array of character strings
+static int
+_rw_fmtstrarray (FmtSpec*, size_t, Buffer&, const char* const*);
+
 // format struct tm
 static int
 _rw_fmttm (const FmtSpec&, Buffer&, const tm*);
@@ -2219,6 +2224,50 @@
 
 /********************************************************************/
 
+// formats an argv-style array of character strings
+static int
+_rw_fmtstrarray (FmtSpec *pspec, size_t paramno, Buffer &buf,
+                 const char* const* argv)
+{
+    FmtSpec &spec = pspec [paramno];
+
+    int len = 0;
+
+    if (0 == argv || 0 > _RW::__rw_memattr (argv, sizeof *argv, 0))
+        return _rw_fmtbadaddr (spec, buf, argv);
+
+    size_t argc = spec.prec;
+
+    for (size_t i = 0; i != argc; ++i) {
+        if (_RWSTD_SIZE_MAX == argc && 0 == argv [i])
+            break;
+
+        int n = _rw_fmtstr (spec, buf, argv [i], _RWSTD_SIZE_MAX);
+
+        if (n < 0)
+            return n;
+
+        len += n;
+
+        if (i + 1 == argc || _RWSTD_SIZE_MAX == argc && 0 == argv [i + 1])
+            break;
+
+        const unsigned pound = spec.fl_pound;
+        spec.fl_pound = 0;
+        n = _rw_fmtstr (spec, buf, ",", 1);
+        spec.fl_pound = pound;
+
+        if (n < 0)
+            return n;
+
+        len += n;
+    }
+
+    return len;
+}
+
+/********************************************************************/
+
 // implements %c and %{c} (narrow character formatting, both without
 // and with escape sequences, respectively)
 static int
@@ -2756,8 +2805,13 @@
         break;
     }
 
-    case 's':   // %{s}, %{Is}, %{ls}
-        if (spec.mod == spec.mod_ext_I) {   // ios::iostate
+    case 's':   // %{s}, %{As}, %{Is}, %{ls}
+        if (spec.mod == spec.mod_ext_A) {   // array of strings
+            spec.param.ptr_ = PARAM (ptr_);
+            const char* const* const argv = (char**)spec.param.ptr_;
+            len = _rw_fmtstrarray (pspec, paramno, buf, argv);
+        }
+        else if (spec.mod == spec.mod_ext_I) {   // ios::iostate
             spec.param.int_ = PARAM (int_);
             len = _rw_fmtiostate (spec, buf, spec.param.int_);
         }



Mime
View raw message