File indexing completed on 2024-04-28 15:23:03

0001 /*
0002  * This file is part of the DOM implementation for KDE.
0003  *
0004  * Copyright (C) 2005, 2006 Apple Computer, Inc.
0005  * Copyright (C) 2008 Vyacheslav Tokarev (tsjoker@gmail.com)
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Library General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Library General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Library General Public License
0018  * along with this library; see the file COPYING.LIB.  If not, write to
0019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020  * Boston, MA 02110-1301, USA.
0021  *
0022  */
0023 
0024 #include "QualifiedName.h"
0025 #include "xml/dom_nodeimpl.h"
0026 
0027 namespace DOM
0028 {
0029 
0030 QualifiedName::QualifiedName(const DOMString &prefix, const DOMString &localName, const DOMString &namespaceURI)
0031 {
0032     m_prefix = PrefixName::fromString(prefix);
0033     m_localName = LocalName::fromString(localName);
0034     m_namespace = NamespaceName::fromString(namespaceURI);
0035 }
0036 
0037 QualifiedName::QualifiedName(const QualifiedName &name)
0038 {
0039     m_prefix = name.prefixId();
0040     m_namespace = name.namespaceNameId();
0041     m_localName = name.localNameId();
0042 }
0043 
0044 QualifiedName::QualifiedName(int prefix, int localName, int namespaceName)
0045 {
0046     m_prefix = PrefixName::fromId(prefix);
0047     m_localName = LocalName::fromId(localName);
0048     m_namespace = NamespaceName::fromId(namespaceName);
0049 }
0050 
0051 QualifiedName::QualifiedName(quint32 id, PrefixName prefix)
0052 {
0053     m_prefix = prefix;
0054     m_localName = LocalName::fromId(localNamePart(id));
0055     m_namespace = NamespaceName::fromId(namespacePart(id));
0056 }
0057 
0058 const QualifiedName &QualifiedName::operator=(const QualifiedName &name)
0059 {
0060     m_prefix = name.prefixId();
0061     m_namespace = name.namespaceNameId();
0062     m_localName = name.localNameId();
0063     return *this;
0064 }
0065 
0066 bool QualifiedName::operator==(const QualifiedName &other) const
0067 {
0068     /*// qCDebug(KHTML_LOG) << m_prefix.id() << other.prefixId().id() << ((m_prefix == other.prefixId()));
0069     // qCDebug(KHTML_LOG) << (m_prefix == other.prefixId()) << (m_localName == other.localNameId()) << (m_namespace == other.namespaceNameId());*/
0070     return (m_prefix == other.prefixId() && m_localName == other.localNameId() && m_namespace == other.namespaceNameId());
0071 }
0072 
0073 bool QualifiedName::hasPrefix() const
0074 {
0075     return m_prefix.id() != 0/*emptyPrefix*/;
0076 }
0077 
0078 bool QualifiedName::matches(const QualifiedName &other) const
0079 {
0080     //FIXME: IMPLEMENT
0081     return *this == other || (m_localName == other.localNameId() && (m_prefix == other.prefixId() || m_namespace == other.namespaceNameId()));
0082 }
0083 
0084 void QualifiedName::setPrefix(const PrefixName &prefix)
0085 {
0086     m_prefix = prefix;
0087 }
0088 
0089 void QualifiedName::setPrefix(const DOMString &prefix)
0090 {
0091     m_prefix = PrefixName::fromString(prefix);
0092 }
0093 
0094 unsigned QualifiedName::id() const
0095 {
0096     return (m_namespace.id() << 16) ^ (m_localName.id());
0097 }
0098 
0099 DOMString QualifiedName::tagName() const
0100 {
0101     DOMString prefix = m_prefix.toString();
0102     DOMString localName = m_localName.toString();
0103     if (prefix.isEmpty()) {
0104         return localName;
0105     }
0106     return prefix + DOMString(":") + localName;
0107 }
0108 
0109 DOMString QualifiedName::prefix() const
0110 {
0111     return m_prefix.toString();
0112 }
0113 
0114 DOMString QualifiedName::localName() const
0115 {
0116     return m_localName.toString();
0117 }
0118 
0119 DOMString QualifiedName::namespaceURI() const
0120 {
0121     return m_namespace.toString();
0122 }
0123 
0124 DOMString QualifiedName::toString() const
0125 {
0126     return prefix() + DOMString(":") + localName();
0127 }
0128 
0129 }
0130