Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / XML_Utils / XercesString.cpp
blob002368b091d46e501e935c4fc5ef6ae77356825a
1 #include <ostream>
2 #include <algorithm>
4 #include "XercesString.h"
5 #include "xercesc/util/PlatformUtils.hpp"
7 #include "ace/Truncate.h"
9 using xercesc::XMLString;
10 using xercesc::XMLPlatformUtils;
12 namespace XML
14 // On unicode windows, ACE_TCHAR == XMLCh
15 #if !defined (_MSC_VER) || !defined (ACE_USES_WCHAR)
16 XStr::XStr (const ACE_TCHAR* str)
17 : _wstr(0)
19 _wstr = XMLString::transcode(ACE_TEXT_ALWAYS_CHAR (str));
21 #endif
23 XStr::XStr (XMLCh *wstr)
24 : _wstr(wstr)
28 XStr::XStr (const XMLCh* wstr)
29 : _wstr(0)
31 _wstr = XMLString::replicate(wstr);
34 XStr::XStr (const XStr &right)
35 : _wstr(0)
37 _wstr = XMLString::replicate(right._wstr);
40 XStr& XStr::operator= (const XStr& rhs)
42 if (&rhs == this)
43 return *this;
44 XStr temp (rhs);
45 std::swap (this->_wstr, temp._wstr);
46 return *this;
49 XStr::~XStr ()
51 this->reset ();
54 const XMLCh* XStr::begin () const
56 return _wstr;
59 const XMLCh* XStr::end () const
61 return _wstr + size();
64 bool XStr::append(const XMLCh *tail)
66 XMLSize_t iTailLen = XMLString::stringLen(tail);
67 XMLSize_t iWorkLen = XMLString::stringLen(_wstr);
69 XMLSize_t bytes = (iWorkLen + iTailLen + 1) * sizeof (XMLCh);
70 void *tmp = XMLPlatformUtils::fgMemoryManager->allocate (bytes);
71 XMLCh *result = reinterpret_cast<XMLCh *> (tmp);
73 bool bOK = result != 0;
74 if (bOK)
76 XMLCh *target = result;
77 XMLString::moveChars(target, _wstr, iWorkLen);
78 target += iWorkLen;
79 XMLString::moveChars(target, tail, iTailLen);
80 target += iTailLen;
81 *target++ = 0;
82 XMLString::release(&_wstr);
83 _wstr = result;
85 return bOK;
88 bool XStr::erase(const XMLCh *head, const XMLCh *tail)
90 bool bOK = head <= tail && head >= begin() && tail <= end();
91 if (bOK)
93 XMLSize_t bytes = (size() - (tail - head) + 1 ) * sizeof (XMLCh);
94 void *tmp = XMLPlatformUtils::fgMemoryManager->allocate (bytes);
95 XMLCh *result = reinterpret_cast<XMLCh *> (tmp);
97 XMLCh *target = result;
98 bOK = target != 0;
99 if (bOK)
101 const XMLCh *cursor = begin();
103 while (cursor != head) *target++ = *cursor++;
104 cursor = tail;
105 while ( cursor != end() ) *target++ = *cursor++;
106 *target ++ = 0;
107 XMLString::release(&_wstr);
108 _wstr = result;
111 return bOK;
114 int XStr::size () const
116 return ACE_Utils::truncate_cast<int> (XMLString::stringLen(_wstr));
119 XMLCh XStr::operator [] (const int i)
121 return _wstr[i];
124 XMLCh XStr::operator [] (const int i) const
126 return _wstr[i];
129 XMLCh * XStr::release ()
131 XMLCh* tmp = _wstr;
132 this->_wstr = 0;
133 return tmp;
136 void
137 XStr::reset ()
139 if (_wstr)
140 XMLString::release(&_wstr);
141 _wstr = 0;
144 bool operator== (const XStr& lhs, const XStr& rhs)
146 return XMLString::compareIString (lhs,rhs) == 0;
149 bool operator!= (const XStr& lhs, const XStr& rhs)
151 return !operator==(lhs, rhs);
155 std::ostream&
156 operator<< (std::ostream& o, XStr const& str)
158 char* s = XMLString::transcode (str);
160 o << s;
162 XMLString::release (&s); // idiots?
163 return o;