summaryrefslogtreecommitdiff
path: root/ace/ace_wchar.inl
diff options
context:
space:
mode:
authorbrunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-10-03 21:48:59 +0000
committerbrunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-10-03 21:48:59 +0000
commita54cb2c9f92a2bcf2c7fb7494c9c9332774a9d6f (patch)
treee4c66900f1d29bf7b66b040f2293f80bd6f72d3f /ace/ace_wchar.inl
parent44f1b092021a3f36c96c12712e2278a99496f28c (diff)
downloadATCD-a54cb2c9f92a2bcf2c7fb7494c9c9332774a9d6f.tar.gz
ChangeLogTag:Tue Oct 3 14:25:09 2000 Darrell Brunsch <brunsch@uci.edu>
Diffstat (limited to 'ace/ace_wchar.inl')
-rw-r--r--ace/ace_wchar.inl115
1 files changed, 115 insertions, 0 deletions
diff --git a/ace/ace_wchar.inl b/ace/ace_wchar.inl
new file mode 100644
index 00000000000..fcd65e48a7b
--- /dev/null
+++ b/ace/ace_wchar.inl
@@ -0,0 +1,115 @@
+/* -*- C++ -*- */
+// $Id$
+
+// These are always inlined
+// FUZZ: disable check_for_inline
+
+#if defined (ACE_HAS_WCHAR)
+
+inline
+ACE_Wide_To_Ascii::ACE_Wide_To_Ascii (const wchar_t *s)
+ : s_ (ACE_Wide_To_Ascii::convert (s))
+{
+}
+
+
+inline
+ACE_Wide_To_Ascii::~ACE_Wide_To_Ascii (void)
+{
+ delete [] this->s_;
+}
+
+inline char *
+ACE_Wide_To_Ascii::char_rep (void)
+{
+ return this->s_;
+}
+
+
+inline char *
+ACE_Wide_To_Ascii::convert (const wchar_t *wstr)
+{
+# if defined (ACE_WIN32)
+ size_t len = ::WideCharToMultiByte (CP_OEMCP,
+ 0,
+ wstr,
+ -1,
+ NULL,
+ 0,
+ NULL,
+ NULL);
+# elif defined (VXWORKS)
+ // @@ we should use a different macro than VXWORKS here, ACE_LACKS_WCSLEN?
+ const wchar_t *wtemp = wstr;
+ while (wtemp != 0)
+ ++wtemp;
+
+ size_t len = wtemp - wstr + 1;
+# else /* ACE_WIN32 */
+ size_t len = ::wcslen (wstr) + 1;
+# endif /* ACE_WIN32 */
+
+ char *str = new char[len];
+
+# if defined (ACE_WIN32)
+ ::WideCharToMultiByte (CP_OEMCP, 0, wstr, -1, str, len, NULL, NULL);
+# elif defined (VXWORKS)
+ ::wcstombs (str, wstr, len);
+# else /* ACE_WIN32 */
+ for (size_t i = 0; i < len; i++)
+ {
+ wchar_t *t = ACE_const_cast (wchar_t *, wstr);
+ str[i] = ACE_static_cast (char, *(t + i));
+ }
+# endif /* ACE_WIN32 */
+ return str;
+}
+
+
+inline
+ACE_Ascii_To_Wide::ACE_Ascii_To_Wide (const char *s)
+: s_ (ACE_Ascii_To_Wide::convert (s))
+{
+}
+
+
+inline
+ACE_Ascii_To_Wide::~ACE_Ascii_To_Wide (void)
+{
+ delete [] this->s_;
+}
+
+inline wchar_t *
+ACE_Ascii_To_Wide::wchar_rep (void)
+{
+ return this->s_;
+}
+
+
+inline wchar_t *
+ACE_Ascii_To_Wide::convert (const char *str)
+{
+# if defined (ACE_WIN32)
+ size_t len = ::MultiByteToWideChar (CP_OEMCP, 0, str, -1, NULL, 0);
+# else /* ACE_WIN32 */
+ size_t len = strlen (str) + 1;
+# endif /* ACE_WIN32 */
+
+ wchar_t *wstr = new wchar_t[len];
+
+# if defined (ACE_WIN32)
+ ::MultiByteToWideChar (CP_OEMCP, 0, str, -1, wstr, len);
+# elif defined (VXWORKS)
+ ::mbstowcs (wstr, str, len);
+# else /* ACE_WIN32 */
+ for (size_t i = 0; i < len; i++)
+ {
+ char *t = ACE_const_cast (char *, str);
+ wstr[i] = ACE_static_cast (wchar_t, *(t + i));
+ }
+# endif /* ACE_WIN32 */
+ return wstr;
+}
+
+#endif /* ACE_HAS_WCHAR */
+