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
|
#include <ostream>
#include <algorithm>
#include "XercesString.h"
#include "xercesc/util/PlatformUtils.hpp"
#include "ace/Truncate.h"
using xercesc::XMLString;
using xercesc::XMLPlatformUtils;
namespace XML
{
// On unicode windows, ACE_TCHAR == XMLCh
#if !defined (_MSC_VER) || !defined (ACE_USES_WCHAR)
XStr::XStr (const ACE_TCHAR* str)
: _wstr(0)
{
_wstr = XMLString::transcode(ACE_TEXT_ALWAYS_CHAR (str));
}
#endif
XStr::XStr (XMLCh *wstr)
: _wstr(wstr)
{
}
XStr::XStr (const XMLCh* wstr)
: _wstr(0)
{
_wstr = XMLString::replicate(wstr);
}
XStr::XStr (const XStr &right)
: _wstr(0)
{
_wstr = XMLString::replicate(right._wstr);
}
XStr& XStr::operator= (const XStr& rhs)
{
if (&rhs == this)
return *this;
XStr temp (rhs);
std::swap (this->_wstr, temp._wstr);
return *this;
}
XStr::~XStr ()
{
this->reset ();
}
const XMLCh* XStr::begin () const
{
return _wstr;
}
const XMLCh* XStr::end () const
{
return _wstr + size();
}
bool XStr::append(const XMLCh *tail)
{
XMLSize_t iTailLen = XMLString::stringLen(tail);
XMLSize_t iWorkLen = XMLString::stringLen(_wstr);
XMLSize_t bytes = (iWorkLen + iTailLen + 1) * sizeof (XMLCh);
void *tmp = XMLPlatformUtils::fgMemoryManager->allocate (bytes);
XMLCh *result = reinterpret_cast<XMLCh *> (tmp);
bool bOK = result != 0;
if (bOK)
{
XMLCh *target = result;
XMLString::moveChars(target, _wstr, iWorkLen);
target += iWorkLen;
XMLString::moveChars(target, tail, iTailLen);
target += iTailLen;
*target++ = 0;
XMLString::release(&_wstr);
_wstr = result;
}
return bOK;
}
bool XStr::erase(const XMLCh *head, const XMLCh *tail)
{
bool bOK = head <= tail && head >= begin() && tail <= end();
if (bOK)
{
XMLSize_t bytes = (size() - (tail - head) + 1 ) * sizeof (XMLCh);
void *tmp = XMLPlatformUtils::fgMemoryManager->allocate (bytes);
XMLCh *result = reinterpret_cast<XMLCh *> (tmp);
XMLCh *target = result;
bOK = target != 0;
if (bOK)
{
const XMLCh *cursor = begin();
while (cursor != head) *target++ = *cursor++;
cursor = tail;
while ( cursor != end() ) *target++ = *cursor++;
*target ++ = 0;
XMLString::release(&_wstr);
_wstr = result;
}
}
return bOK;
}
int XStr::size () const
{
return ACE_Utils::truncate_cast<int> (XMLString::stringLen(_wstr));
}
XMLCh XStr::operator [] (const int i)
{
return _wstr[i];
}
XMLCh XStr::operator [] (const int i) const
{
return _wstr[i];
}
XMLCh * XStr::release ()
{
XMLCh* tmp = _wstr;
this->_wstr = 0;
return tmp;
}
void
XStr::reset ()
{
if (_wstr)
XMLString::release(&_wstr);
_wstr = 0;
}
bool operator== (const XStr& lhs, const XStr& rhs)
{
return XMLString::compareIString (lhs,rhs) == 0;
}
bool operator!= (const XStr& lhs, const XStr& rhs)
{
return !operator==(lhs, rhs);
}
std::ostream&
operator<< (std::ostream& o, XStr const& str)
{
char* s = XMLString::transcode (str);
o << s;
XMLString::release (&s); // idiots?
return o;
}
}
|