-
Notifications
You must be signed in to change notification settings - Fork 4
/
XString.cpp
90 lines (78 loc) · 1.38 KB
/
XString.cpp
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
/*
* XString: a simple class for translation between
* XMLCh strings and local coding
*
* Class implementation
* September 21, 2003
* Richard Jones
*/
#include "XString.hpp"
#include <iostream>
int dumper = 0;
XString::XString(void)
: fUnicode(0)
{}
XString::XString(const XMLCh* const x)
: fUnicode(0)
{
if (x)
{
char* str = xercesc::XMLString::transcode(x);
(std::string&)*this = str;
xercesc::XMLString::release(&str);
}
}
XString::XString(const char* const s)
: fUnicode(0)
{
if (s)
{
(std::string&)*this = s;
}
}
XString::XString(const std::string& s)
: std::string(s),
fUnicode(0)
{}
XString::XString(const XString& X)
: std::string(X),
fUnicode(0)
{}
XString::~XString()
{
if (fUnicode)
{
xercesc::XMLString::release(&fUnicode);
}
}
XString& XString::operator=(const XString& X)
{
(std::string&)*this = (std::string&)X;
if (fUnicode)
{
xercesc::XMLString::release(&fUnicode);
}
return *this;
}
const XMLCh* XString::unicode_str()
{
if (fUnicode == 0)
{
fUnicode = xercesc::XMLString::transcode(this->c_str());
}
return fUnicode;
}
const XString XString::basename() const
{
XString s(*this);
size_type p = s.find_last_of("/");
if (p != npos)
{
s = s.substr(p+1,s.size());
}
return s;
}
void XString::dump()
{
std::cout << *this << std::endl;
}