4 #include "XercesString.h"
5 #include "xercesc/util/PlatformUtils.hpp"
7 #include "ace/Truncate.h"
9 using xercesc::XMLString
;
10 using xercesc::XMLPlatformUtils
;
14 // On unicode windows, ACE_TCHAR == XMLCh
15 #if !defined (_MSC_VER) || !defined (ACE_USES_WCHAR)
16 XStr::XStr (const ACE_TCHAR
* str
)
19 _wstr
= XMLString::transcode(ACE_TEXT_ALWAYS_CHAR (str
));
23 XStr::XStr (XMLCh
*wstr
)
28 XStr::XStr (const XMLCh
* wstr
)
31 _wstr
= XMLString::replicate(wstr
);
34 XStr::XStr (const XStr
&right
)
37 _wstr
= XMLString::replicate(right
._wstr
);
40 XStr
& XStr::operator= (const XStr
& rhs
)
45 std::swap (this->_wstr
, temp
._wstr
);
54 const XMLCh
* XStr::begin () const
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;
76 XMLCh
*target
= result
;
77 XMLString::moveChars(target
, _wstr
, iWorkLen
);
79 XMLString::moveChars(target
, tail
, iTailLen
);
82 XMLString::release(&_wstr
);
88 bool XStr::erase(const XMLCh
*head
, const XMLCh
*tail
)
90 bool bOK
= head
<= tail
&& head
>= begin() && tail
<= end();
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
;
101 const XMLCh
*cursor
= begin();
103 while (cursor
!= head
) *target
++ = *cursor
++;
105 while ( cursor
!= end() ) *target
++ = *cursor
++;
107 XMLString::release(&_wstr
);
114 int XStr::size () const
116 return ACE_Utils::truncate_cast
<int> (XMLString::stringLen(_wstr
));
119 XMLCh
XStr::operator [] (const int i
)
124 XMLCh
XStr::operator [] (const int i
) const
129 XMLCh
* XStr::release ()
140 XMLString::release(&_wstr
);
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
);
156 operator<< (std::ostream
& o
, XStr
const& str
)
158 char* s
= XMLString::transcode (str
);
162 XMLString::release (&s
); // idiots?