KHtml

QualifiedName.cpp
1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright (C) 2005, 2006 Apple Computer, Inc.
5  * Copyright (C) 2008 Vyacheslav Tokarev ([email protected])
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #include "QualifiedName.h"
25 #include "xml/dom_nodeimpl.h"
26 
27 namespace DOM
28 {
29 
30 QualifiedName::QualifiedName(const DOMString &prefix, const DOMString &localName, const DOMString &namespaceURI)
31 {
32  m_prefix = PrefixName::fromString(prefix);
33  m_localName = LocalName::fromString(localName);
34  m_namespace = NamespaceName::fromString(namespaceURI);
35 }
36 
37 QualifiedName::QualifiedName(const QualifiedName &name)
38 {
39  m_prefix = name.prefixId();
40  m_namespace = name.namespaceNameId();
41  m_localName = name.localNameId();
42 }
43 
44 QualifiedName::QualifiedName(int prefix, int localName, int namespaceName)
45 {
46  m_prefix = PrefixName::fromId(prefix);
47  m_localName = LocalName::fromId(localName);
48  m_namespace = NamespaceName::fromId(namespaceName);
49 }
50 
51 QualifiedName::QualifiedName(quint32 id, PrefixName prefix)
52 {
53  m_prefix = prefix;
54  m_localName = LocalName::fromId(localNamePart(id));
55  m_namespace = NamespaceName::fromId(namespacePart(id));
56 }
57 
58 const QualifiedName &QualifiedName::operator=(const QualifiedName &name)
59 {
60  m_prefix = name.prefixId();
61  m_namespace = name.namespaceNameId();
62  m_localName = name.localNameId();
63  return *this;
64 }
65 
66 bool QualifiedName::operator==(const QualifiedName &other) const
67 {
68  /*// qCDebug(KHTML_LOG) << m_prefix.id() << other.prefixId().id() << ((m_prefix == other.prefixId()));
69  // qCDebug(KHTML_LOG) << (m_prefix == other.prefixId()) << (m_localName == other.localNameId()) << (m_namespace == other.namespaceNameId());*/
70  return (m_prefix == other.prefixId() && m_localName == other.localNameId() && m_namespace == other.namespaceNameId());
71 }
72 
73 bool QualifiedName::hasPrefix() const
74 {
75  return m_prefix.id() != 0/*emptyPrefix*/;
76 }
77 
78 bool QualifiedName::matches(const QualifiedName &other) const
79 {
80  //FIXME: IMPLEMENT
81  return *this == other || (m_localName == other.localNameId() && (m_prefix == other.prefixId() || m_namespace == other.namespaceNameId()));
82 }
83 
84 void QualifiedName::setPrefix(const PrefixName &prefix)
85 {
86  m_prefix = prefix;
87 }
88 
89 void QualifiedName::setPrefix(const DOMString &prefix)
90 {
91  m_prefix = PrefixName::fromString(prefix);
92 }
93 
94 unsigned QualifiedName::id() const
95 {
96  return (m_namespace.id() << 16) ^ (m_localName.id());
97 }
98 
99 DOMString QualifiedName::tagName() const
100 {
101  DOMString prefix = m_prefix.toString();
102  DOMString localName = m_localName.toString();
103  if (prefix.isEmpty()) {
104  return localName;
105  }
106  return prefix + DOMString(":") + localName;
107 }
108 
109 DOMString QualifiedName::prefix() const
110 {
111  return m_prefix.toString();
112 }
113 
114 DOMString QualifiedName::localName() const
115 {
116  return m_localName.toString();
117 }
118 
119 DOMString QualifiedName::namespaceURI() const
120 {
121  return m_namespace.toString();
122 }
123 
124 DOMString QualifiedName::toString() const
125 {
126  return prefix() + DOMString(":") + localName();
127 }
128 
129 }
130 
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
This library provides a full-featured HTML parser and widget.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:06 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.