summaryrefslogtreecommitdiff
path: root/ace/SString.i
blob: 103af5674815f3a4a48da01033668d838c411c93 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* -*- C++ -*- */
// $Id$

// SString.i

// Return the <index'th> character in the string.

ACE_INLINE char 
ACE_CString::operator[] (size_t index) const
{
  ACE_TRACE ("ACE_CString::operator[]");
  return this->rep_[index];
}

// Get a copy of the underlying representation.

ACE_INLINE char *
ACE_CString::rep (void) const
{
  ACE_TRACE ("ACE_CString::rep");
  
  char *new_string;
  ACE_NEW_RETURN (new_string, char[this->len_ + 1], 0);
  ACE_OS::strcpy (new_string, this->rep_);

  return new_string;
}

ACE_INLINE const char *
ACE_CString::fast_rep (void) const
{
  return this->rep_;
}

ACE_INLINE const char *
ACE_CString::c_str (void) const
{
  return this->rep_;
}

// Comparison operator.

ACE_INLINE int 
ACE_CString::operator== (const ACE_CString &s) const
{
  ACE_TRACE ("ACE_CString::operator==");

  return this->len_ == s.len_
    && ACE_OS::strcmp (this->rep_, s.rep_) == 0;
}

// Comparison operator.

ACE_INLINE int 
ACE_CString::operator!= (const ACE_CString &s) const
{
  ACE_TRACE ("ACE_CString::operator!=");
  return !(*this == s);
}

ACE_INLINE int 
ACE_CString::compare (const ACE_CString &s) const
{
  ACE_TRACE ("ACE_CString::compare");
  return ACE_OS::strcmp (this->rep_, s.rep_);
}

// Return the <index'th> character in the string.

ACE_INLINE char 
ACE_SString::operator[] (size_t index) const
{
  ACE_TRACE ("ACE_SString::operator[]");
  return this->rep_[index];
}

// Get the underlying pointer (does not make a copy, so beware!).

ACE_INLINE const char *
ACE_SString::rep (void) const
{
  ACE_TRACE ("ACE_SString::rep");
  return this->rep_;
}

// Comparison operator.

ACE_INLINE int 
ACE_SString::operator== (const ACE_SString &s) const
{
  ACE_TRACE ("ACE_SString::operator==");
  return this->len_ == s.len_
    && ACE_OS::strcmp (this->rep_, s.rep_) == 0;
}

// Comparison operator.

ACE_INLINE int 
ACE_SString::operator!= (const ACE_SString &s) const
{
  ACE_TRACE ("ACE_SString::operator!=");
  return !(*this == s);
}

ACE_INLINE int 
ACE_SString::compare (const ACE_SString &s) const
{
  ACE_TRACE ("ACE_CString::compare");
  return ACE_OS::strcmp (this->rep_, s.rep_);
}

// Get a copy of the underlying representation.

ACE_INLINE ACE_USHORT16 *
ACE_WString::rep (void) const
{
  ACE_TRACE ("ACE_WString::rep");
  if (this->len_ <= 0)
    return 0;
  else
    {
      ACE_USHORT16 *t;
      ACE_NEW_RETURN (t, ACE_USHORT16[this->len_ + 1], 0);
      ACE_OS::memcpy (t, this->rep_, this->len_ * sizeof (ACE_USHORT16));

      // null terminate 
      t[this->len_] = 0;

      return t;
    }
}

// Get at the underlying representation directly!

ACE_INLINE const ACE_USHORT16 *
ACE_WString::fast_rep (void) const
{
  return this->rep_;
}

ACE_INLINE const ACE_USHORT16 *
ACE_WString::c_str (void) const
{
  return this->rep_;
}

// Comparison operator.

ACE_INLINE int 
ACE_WString::operator== (const ACE_WString &s) const
{
  ACE_TRACE ("ACE_WString::operator==");
  return this->len_ == s.len_
    && ACE_OS::memcmp ((const void *) this->rep_, 
		       (const void *) s.rep_,
		       this->len_ * sizeof (ACE_USHORT16)) == 0;
}

// Comparison operator.

ACE_INLINE int 
ACE_WString::operator!= (const ACE_WString &s) const
{
  ACE_TRACE ("ACE_WString::operator!=");
  return !(*this == s);
}

ACE_INLINE int 
ACE_WString::compare (const ACE_WString &s) const
{
  ACE_TRACE ("ACE_WString::compare");

  return ACE_OS::memcmp ((const void *) this->rep_, 
			 (const void *) s.rep_,
			 this->len_ * sizeof (ACE_USHORT16));
}

// Return the <index'th> character in the string.

ACE_INLINE ACE_USHORT16
ACE_WString::operator[] (size_t index) const
{
  ACE_TRACE ("ACE_WString::operator[]");
  return this->rep_[index];
}