summaryrefslogtreecommitdiff
path: root/ace/ace_wchar.inl
blob: ebe47ccbd3f42b20abfb58ca218ebdec43eeccd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* -*- C++ -*- */
// $Id$

// These are always inlined
// FUZZ: disable check_for_inline

#if defined (ACE_HAS_WCHAR)

#if !defined (ACE_WIN32)
#  include /**/ <string.h>             // Need to see strlen()
#endif /* ACE_WIN32 */

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)
{
  // Short circuit null pointer case
  if (wstr == 0)
    return 0;

# if defined (ACE_WIN32)
  int len = ::WideCharToMultiByte (CP_OEMCP,
                                   0,
                                   wstr,
                                   -1,
                                   NULL,
                                   0,
                                   NULL,
                                   NULL);
# elif defined (ACE_LACKS_WCSLEN)
  const wchar_t *wtemp = wstr;
  while (wtemp != 0)
    ++wtemp;

  int len = wtemp - wstr + 1;
# else  /* ACE_WIN32 */
  int 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 (int 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_Wide_To_Ascii::ACE_Wide_To_Ascii (const wchar_t *s)
  : s_ (ACE_Wide_To_Ascii::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)
{
  // Short circuit null pointer case
  if (str == 0)
    return 0;

# if defined (ACE_WIN32)
  int len = ::MultiByteToWideChar (CP_OEMCP, 0, str, -1, NULL, 0);
# else /* ACE_WIN32 */
  int 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 (int 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;
}

inline
ACE_Ascii_To_Wide::ACE_Ascii_To_Wide (const char *s)
: s_ (ACE_Ascii_To_Wide::convert (s))
{
}

#endif /* ACE_HAS_WCHAR */