2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * Representing XML QNames
26 using namespace xmltooling;
29 QName::QName(const XMLCh* uri, const XMLCh* localPart, const XMLCh* prefix)
32 m_uri=m_prefix=m_local=NULL;
35 setLocalPart(localPart);
39 QName::QName(const char* uri, const char* localPart, const char* prefix)
42 m_uri=m_prefix=m_local=NULL;
45 setLocalPart(localPart);
52 XMLString::release(&m_uri);
53 XMLString::release(&m_prefix);
54 XMLString::release(&m_local);
58 void QName::setPrefix(const XMLCh* prefix)
67 XMLString::release(&m_prefix);
68 m_prefix=XMLString::replicate(prefix);
72 void QName::setNamespaceURI(const XMLCh* uri)
81 XMLString::release(&m_uri);
82 m_uri=XMLString::replicate(uri);
86 void QName::setLocalPart(const XMLCh* localPart)
95 XMLString::release(&m_local);
96 m_local=XMLString::replicate(localPart);
100 void QName::setPrefix(const char* prefix)
104 auto_ptr_XMLCh temp(prefix);
111 XMLString::release(&m_prefix);
112 m_prefix=XMLString::transcode(prefix);
116 void QName::setNamespaceURI(const char* uri)
120 auto_ptr_XMLCh temp(uri);
127 XMLString::release(&m_uri);
128 m_uri=XMLString::transcode(uri);
132 void QName::setLocalPart(const char* localPart)
136 auto_ptr_XMLCh temp(localPart);
143 XMLString::release(&m_local);
144 m_local=XMLString::transcode(localPart);
148 #ifndef HAVE_GOOD_STL
149 QName::QName(const QName& src)
151 m_uri=XMLString::replicate(src.getNamespaceURI());
152 m_prefix=XMLString::replicate(src.getPrefix());
153 m_local=XMLString::replicate(src.getLocalPart());
156 QName& QName::operator=(const QName& src)
158 m_uri=XMLString::replicate(src.getNamespaceURI());
159 m_prefix=XMLString::replicate(src.getPrefix());
160 m_local=XMLString::replicate(src.getLocalPart());
165 bool xmltooling::operator==(const QName& op1, const QName& op2)
169 return (!XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI()) &&
170 !XMLString::compareString(op1.getLocalPart(),op2.getLocalPart()));
173 bool xmltooling::operator!=(const QName& op1, const QName& op2)
178 bool xmltooling::operator<(const QName& op1, const QName& op2)
180 int i=XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI());
184 return (XMLString::compareString(op1.getLocalPart(),op2.getLocalPart())<0);
189 string QName::toString() const
193 auto_ptr_char local(getLocalPart());
195 auto_ptr_char pre(getPrefix());
196 return string(pre.get()) + ':' + local.get();
198 else if (hasNamespaceURI()) {
199 auto_ptr_char ns(getNamespaceURI());
200 return string("{") + ns.get() + '}' + local.get();