1 | // |
2 | // Name.cpp |
3 | // |
4 | // Library: XML |
5 | // Package: XML |
6 | // Module: Name |
7 | // |
8 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/XML/Name.h" |
16 | #include <algorithm> |
17 | |
18 | |
19 | namespace Poco { |
20 | namespace XML { |
21 | |
22 | |
23 | const XMLString Name::EMPTY_NAME; |
24 | |
25 | |
26 | Name::Name() |
27 | { |
28 | } |
29 | |
30 | |
31 | Name::Name(const XMLString& qname): |
32 | _qname(qname) |
33 | { |
34 | } |
35 | |
36 | |
37 | Name::Name(const XMLString& qname, const XMLString& namespaceURI): |
38 | _qname(qname), |
39 | _namespaceURI(namespaceURI), |
40 | _localName(localName(qname)) |
41 | { |
42 | } |
43 | |
44 | |
45 | Name::Name(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName): |
46 | _qname(qname), |
47 | _namespaceURI(namespaceURI), |
48 | _localName(localName) |
49 | { |
50 | } |
51 | |
52 | |
53 | Name::Name(const Name& name): |
54 | _qname(name._qname), |
55 | _namespaceURI(name._namespaceURI), |
56 | _localName(name._localName) |
57 | { |
58 | } |
59 | |
60 | |
61 | Name::~Name() |
62 | { |
63 | } |
64 | |
65 | |
66 | Name& Name::operator = (const Name& name) |
67 | { |
68 | if (this != &name) |
69 | { |
70 | _qname = name._qname; |
71 | _namespaceURI = name._namespaceURI; |
72 | _localName = name._localName; |
73 | } |
74 | return *this; |
75 | } |
76 | |
77 | |
78 | void Name::swap(Name& name) |
79 | { |
80 | std::swap(_qname, name._qname); |
81 | std::swap(_namespaceURI, name._namespaceURI); |
82 | std::swap(_localName, name._localName); |
83 | } |
84 | |
85 | |
86 | void Name::assign(const XMLString& qname) |
87 | { |
88 | _qname = qname; |
89 | _namespaceURI.clear(); |
90 | _localName.clear(); |
91 | } |
92 | |
93 | |
94 | void Name::assign(const XMLString& qname, const XMLString& namespaceURI) |
95 | { |
96 | _qname = qname; |
97 | _namespaceURI = namespaceURI; |
98 | _localName = localName(qname); |
99 | } |
100 | |
101 | |
102 | void Name::assign(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) |
103 | { |
104 | _qname = qname; |
105 | _namespaceURI = namespaceURI; |
106 | _localName = localName; |
107 | } |
108 | |
109 | |
110 | bool Name::equals(const Name& name) const |
111 | { |
112 | return name._namespaceURI == _namespaceURI && name._localName == _localName && name._qname == _qname; |
113 | } |
114 | |
115 | |
116 | bool Name::equals(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const |
117 | { |
118 | return _namespaceURI == namespaceURI && _localName == localName && _qname == qname; |
119 | } |
120 | |
121 | |
122 | bool Name::equalsWeakly(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const |
123 | { |
124 | return (_qname == qname && !qname.empty()) || (_namespaceURI == namespaceURI && _localName == localName && !_localName.empty()); |
125 | } |
126 | |
127 | |
128 | XMLString Name::prefix() const |
129 | { |
130 | return prefix(_qname); |
131 | } |
132 | |
133 | |
134 | void Name::split(const XMLString& qname, XMLString& prefix, XMLString& localName) |
135 | { |
136 | XMLString::size_type pos = qname.find(':'); |
137 | if (pos != XMLString::npos) |
138 | { |
139 | prefix.assign(qname, 0, pos); |
140 | localName.assign(qname, pos + 1, qname.size() - pos - 1); |
141 | } |
142 | else |
143 | { |
144 | prefix.clear(); |
145 | localName.assign(qname); |
146 | } |
147 | } |
148 | |
149 | |
150 | XMLString Name::localName(const XMLString& qname) |
151 | { |
152 | XMLString::size_type pos = qname.find(':'); |
153 | if (pos != XMLString::npos) |
154 | return XMLString(qname, pos + 1, qname.size() - pos - 1); |
155 | else |
156 | return qname; |
157 | } |
158 | |
159 | |
160 | XMLString Name::prefix(const XMLString& qname) |
161 | { |
162 | XMLString::size_type pos = qname.find(':'); |
163 | if (pos != XMLString::npos) |
164 | return XMLString(qname, 0, pos); |
165 | else |
166 | return EMPTY_NAME; |
167 | } |
168 | |
169 | |
170 | } } // namespace Poco::XML |
171 | |