stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r557652 - in /incubator/stdcxx/trunk/tests: include/rw_locale.h src/locale.cpp
Date Thu, 19 Jul 2007 15:06:46 GMT
Author: sebor
Date: Thu Jul 19 08:06:45 2007
New Revision: 557652

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

	* rw_locale.h (rw_get_wchars): Declared a new function to find
	a set of (valid or invalid) wide characters in the current locale.
	* locale.cpp (rw_get_wchars): Defined.

Modified:
    incubator/stdcxx/trunk/tests/include/rw_locale.h
    incubator/stdcxx/trunk/tests/src/locale.cpp

Modified: incubator/stdcxx/trunk/tests/include/rw_locale.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/include/rw_locale.h?view=diff&rev=557652&r1=557651&r2=557652
==============================================================================
--- incubator/stdcxx/trunk/tests/include/rw_locale.h (original)
+++ incubator/stdcxx/trunk/tests/include/rw_locale.h Thu Jul 19 08:06:45 2007
@@ -69,6 +69,17 @@
 rw_localedef (const char*, const char*, const char*, const char*);
 
 
+// stores up to 'size' wide characters valid in the current locale
+// in consecutive elements of the 'wbuf' buffer; if 'nbytes' is
+// non-zero only wide characters with multibyte sequences of the
+// specified length will be stored (as determined by mblen())
+// returns the number of elements stored
+_TEST_EXPORT _RWSTD_SIZE_T
+rw_get_wchars (wchar_t*      /* wbuf */,
+               _RWSTD_SIZE_T /* size */,
+               int           /* nbytes */ = 0);
+
+
 // an array of multibyte characters 1 to MB_LEN_MAX bytes in length
 typedef char
 rw_mbchar_array_t [_RWSTD_MB_LEN_MAX][_RWSTD_MB_LEN_MAX];

Modified: incubator/stdcxx/trunk/tests/src/locale.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/locale.cpp?view=diff&rev=557652&r1=557651&r2=557652
==============================================================================
--- incubator/stdcxx/trunk/tests/src/locale.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/locale.cpp Thu Jul 19 08:06:45 2007
@@ -595,6 +595,67 @@
 }
 
 
+_TEST_EXPORT size_t
+rw_get_wchars (wchar_t *wbuf, size_t bufsize, int nbytes /* = 0 */)
+{
+    if (0 == bufsize)
+        return 0;
+
+    char tmp [_RWSTD_MB_LEN_MAX];
+
+    size_t nchars = 0;
+
+    for (int i = 0; i != 65536; ++i) {
+
+        // determine whether the wide character is valid
+        // and if so, the length of the multibyte character
+        // that corresponds to it
+        const int len = wctomb (tmp, wchar_t (i));
+
+        if (nbytes == 0 && 0 < len || nbytes != 0 && nbytes == len) {
+            // if the requested length is 0 (i.e., the caller doesn't
+            // care) and the character is valid, store it
+            // if the requested length is non-zero (including -1),
+            // and the value returned from mblen() is the same, store
+            // it (this makes it possible to find invalid characters
+            // as well as valid ones)
+            wbuf [nchars++];
+            if (nchars == bufsize)
+                return nchars;
+        }
+    }
+
+#if 2 < _RWSTD_WCHAR_SIZE
+
+    // try to find the remaining wide characters by a random
+    // search, iterating only so many times to prevent an
+    // infinite loop
+    for (int i = 0; i != 0x100000; ++i) {
+
+        // make a wide character with a random bit pattern
+        wchar_t wc = wchar_t (rand ());
+
+        if (RAND_MAX < 0x10000) {
+            wc <<= 16;
+            wc |= wchar_t (rand ());
+        }
+
+        const int len = wctomb (tmp, wchar_t (i));
+
+        if (nbytes == 0 && 0 < len || nbytes != 0 && nbytes == len) {
+            wbuf [nchars++];
+            if (nchars == bufsize)
+                return nchars;
+        }
+    }
+
+#endif   // 2 < _RWSTD_WCHAR_SIZE
+
+    return nchars;
+
+}
+
+
 _TEST_EXPORT const char*
 rw_find_mb_locale (size_t            *mb_cur_max,
                    rw_mbchar_array_t  mb_chars)



Mime
View raw message