stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r384082 - in /incubator/stdcxx/trunk/tests: include/rw_char.h src/char.cpp
Date Wed, 08 Mar 2006 01:13:13 GMT
Author: sebor
Date: Tue Mar  7 17:13:12 2006
New Revision: 384082

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

	* rw_char.h (compare, length, find, copy, move, assign): Outlined
	UserTraits<UserChar> members.
	(rw_widen): New functions for the wideining of narrow characters
	to the three character types used in the test suite (char, wchar_t,
	and UserChar).
	* char.cpp (compare, length, find, copy, move, assign, rw_widen):
	Defined.

Added:
    incubator/stdcxx/trunk/tests/src/char.cpp   (with props)
Modified:
    incubator/stdcxx/trunk/tests/include/rw_char.h

Modified: incubator/stdcxx/trunk/tests/include/rw_char.h
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/include/rw_char.h?rev=384082&r1=384081&r2=384082&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/include/rw_char.h (original)
+++ incubator/stdcxx/trunk/tests/include/rw_char.h Tue Mar  7 17:13:12 2006
@@ -190,6 +190,7 @@
 UserTraits<charT>::eof_ = std::char_traits<charT>::eof ();
 
 
+_TEST_EXPORT
 _RWSTD_SPECIALIZED_CLASS
 struct UserTraits<UserChar>   // user-defined character traits
 {
@@ -218,52 +219,25 @@
     }
 
     static int
-    compare (const char_type *s1, const char_type *s2, _RWSTD_SIZE_T n) {
-        for (_RWSTD_SIZE_T i = 0; i != n; ++i) {
-            if (!eq (s1[i], s2[i])) {
-                return lt (s1[i], s2[i]) ? -1 : 1;
-            }
-        }
-        return 0;
-    }
+    compare (const char_type*, const char_type*, _RWSTD_SIZE_T);
         
-    static _RWSTD_SIZE_T length (const char_type *s) {
-        _RWSTD_SIZE_T len = 0;
-        for (; !eq (*s++, char_type::eos ()); ++len);
-        return len;
-    }
+    static _RWSTD_SIZE_T
+    length (const char_type*);
  
     static const char_type*
-    find (const char_type *s, _RWSTD_SIZE_T n, const char_type &c) {
-        for (; n-- && !eq (*s, c); ++s);
-        return eq (*s, c) ? s : 0;
-    }
+    find (const char_type*, _RWSTD_SIZE_T, const char_type&);
 
     static char_type*
-    copy (char_type *dst, const char_type *src, _RWSTD_SIZE_T n) {
-        for (; n--; *dst++ = *src++);
-        return dst;
-    }
+    copy (char_type*, const char_type*, _RWSTD_SIZE_T);
 
     static char_type*
-    move (char_type *s1, const char_type *s2, _RWSTD_SIZE_T n) {
-        if (s1 < s2)
-            copy (s1, s2, n);
-        else if (s2 < s1) {
-            s1 += n;
-            s2 += n;
-            for (_RWSTD_SIZE_T i = 0; i != n; ++i) 
-                assign (*--s1, *--s2);
-        }
-        return s1;
-    }
+    move (char_type*, const char_type*, _RWSTD_SIZE_T);
 
-    static char_type* assign (char_type *s, _RWSTD_SIZE_T n, char_type c) {
-        for (char_type *tmp = s; n--; assign (*tmp++, c));
-        return s;
-    }
+    static char_type*
+    assign (char_type*, _RWSTD_SIZE_T, char_type);
 
-    static int_type not_eof (const int_type &i) {
+    static int_type
+    not_eof (const int_type &i) {
         if (eq_int_type (i, int_type::eof ())) {
             const char_type c = { 0, 0 };
             return int_type::from_char (c);
@@ -288,5 +262,18 @@
     }
 };
 
+
+_TEST_EXPORT
+char* rw_widen (char*, const char*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
+
+#ifndef _RWSTD_WCHAR_T
+
+_TEST_EXPORT
+wchar_t* rw_widen (wchar_t*, const char*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
+
+#endif   // _RWSTD_WCHAR_T
+
+_TEST_EXPORT
+UserChar* rw_widen (UserChar*, const char*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
 
 #endif   // RW_CHAR_INCLUDED

Added: incubator/stdcxx/trunk/tests/src/char.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/char.cpp?rev=384082&view=auto
==============================================================================
--- incubator/stdcxx/trunk/tests/src/char.cpp (added)
+++ incubator/stdcxx/trunk/tests/src/char.cpp Tue Mar  7 17:13:12 2006
@@ -0,0 +1,188 @@
+/**************************************************************************
+ *
+ * char.cpp - helpers for user-defined character type and its traits
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Copyright 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
+ *
+ * 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.
+ * 
+ **************************************************************************/
+
+// expand _TEST_EXPORT macros
+#define _RWSTD_TEST_SRC
+#include <rw_char.h>
+
+#include <string.h>   // for memcpy()
+
+
+int UserTraits<UserChar>::
+compare (const char_type *s1, const char_type *s2, size_t n)
+{
+    RW_ASSERT (0 == n || s1 && s2);
+
+    for (size_t i = 0; i != n; ++i) {
+        if (!eq (s1[i], s2[i])) {
+            return lt (s1[i], s2[i]) ? -1 : 1;
+        }
+    }
+
+    return 0;
+}
+        
+
+size_t UserTraits<UserChar>::
+length (const char_type *s)
+{
+    RW_ASSERT (0 != s);
+
+    size_t len = 0;
+    for (; !eq (*s++, char_type::eos ()); ++len);
+    return len;
+}
+ 
+
+const UserTraits<UserChar>::char_type*
+UserTraits<UserChar>::
+find (const char_type *s, size_t n, const char_type &c)
+{
+    RW_ASSERT (0 == n || s);
+
+    for (; n-- && !eq (*s, c); ++s);
+
+    return eq (*s, c) ? s : 0;
+}
+
+
+UserTraits<UserChar>::char_type*
+UserTraits<UserChar>::
+copy (char_type *dst, const char_type *src, size_t n)
+{
+    for (; n--; *dst++ = *src++);
+
+    return dst;
+}
+
+
+UserTraits<UserChar>::char_type*
+UserTraits<UserChar>::
+move (char_type *s1, const char_type *s2, size_t n)
+{
+    RW_ASSERT (0 == n || s1 && s2);
+
+    if (s1 < s2)
+        copy (s1, s2, n);
+    else if (s2 < s1) {
+        s1 += n;
+        s2 += n;
+        for (size_t i = 0; i != n; ++i) 
+            assign (*--s1, *--s2);
+    }
+    return s1;
+}
+
+
+_TEST_EXPORT
+char*
+rw_widen (char *dst, const char *src, size_t len)
+{
+    // dst must point to an array of at least 1 element
+    RW_ASSERT (0 != dst);
+
+    // allow src to be null
+    if (0 == src)
+        src = "";
+
+    // compute the length of src if not specified
+    if (_RWSTD_SIZE_MAX == len)
+        len = src ? strlen (src) : 0;
+
+    // copy src into dst
+    if (len)
+        memcpy (dst, src, len);
+    else
+        *dst = '\0';
+
+    return dst;
+}
+
+
+#ifndef _RWSTD_WCHAR_T
+
+_TEST_EXPORT
+wchar_t*
+rw_widen (wchar_t *dst, const char *src, size_t len)
+{
+    // dst must point to an array of at least 1 element
+    RW_ASSERT (0 != dst);
+
+    // allow src to be null
+    if (0 == src)
+        src = "";
+
+    // compute the length of src if not specified
+    if (_RWSTD_SIZE_MAX == len)
+        len = src ? strlen (src) : 0;
+
+    // widen src into dst one element at a time
+    for (size_t i = 0; ; ++i) {
+        typedef unsigned char UChar;
+
+        // always NUL-terminate dst
+        dst [i] = wchar_t (UChar (src [i]));
+
+        if (i == len)
+            break;
+    }
+
+    return dst;
+}
+
+#endif   // _RWSTD_WCHAR_T
+
+
+_TEST_EXPORT
+UserChar*
+rw_widen (UserChar *dst, const char *src, size_t len)
+{
+    // dst must point to an array of at least 1 element
+    RW_ASSERT (0 != dst);
+
+    // allow src to be null
+    if (0 == src)
+        src = "";
+
+    // compute the length of src if not specified
+    if (_RWSTD_SIZE_MAX == len)
+        len = src ? strlen (src) : 0;
+
+    // widen src into dst one element at a time
+    for (size_t i = 0; ; ++i) {
+        typedef unsigned char UChar;
+
+        // always NUL-terminate dst
+        dst [i].f = 0;
+        dst [i].c = UChar (src [i]);
+
+        if (i == len)
+            break;
+    }
+
+    return dst;
+}

Propchange: incubator/stdcxx/trunk/tests/src/char.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stdcxx/trunk/tests/src/char.cpp
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message