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);
42 XMLString::release(&m_uri);
43 XMLString::release(&m_prefix);
44 XMLString::release(&m_local);
48 void QName::setPrefix(const XMLCh* prefix)
57 XMLString::release(&m_prefix);
58 m_prefix=XMLString::replicate(prefix);
62 void QName::setNamespaceURI(const XMLCh* uri)
71 XMLString::release(&m_uri);
72 m_uri=XMLString::replicate(uri);
76 void QName::setLocalPart(const XMLCh* localPart)
85 XMLString::release(&m_local);
86 m_local=XMLString::replicate(localPart);
91 QName::QName(const QName& src)
93 m_uri=XMLString::replicate(src.getNamespaceURI());
94 m_prefix=XMLString::replicate(src.getPrefix());
95 m_local=XMLString::replicate(src.getLocalPart());
98 QName& QName::operator=(const QName& src)
100 m_uri=XMLString::replicate(src.getNamespaceURI());
101 m_prefix=XMLString::replicate(src.getPrefix());
102 m_local=XMLString::replicate(src.getLocalPart());
107 bool xmltooling::operator==(const QName& op1, const QName& op2)
109 return (!XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI()) &&
110 !XMLString::compareString(op1.getLocalPart(),op2.getLocalPart()));
113 bool xmltooling::operator!=(const QName& op1, const QName& op2)
118 bool xmltooling::operator<(const QName& op1, const QName& op2)
120 int i=XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI());
124 return (XMLString::compareString(op1.getLocalPart(),op2.getLocalPart())<0);
129 string QName::toString() const
133 auto_ptr_char local(getLocalPart());
135 auto_ptr_char pre(getPrefix());
136 return string(pre.get()) + ':' + local.get();
138 else if (hasNamespaceURI()) {
139 auto_ptr_char ns(getNamespaceURI());
140 return string("{") + ns.get() + '}' + local.get();