KHtml

AtomicString.h
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20 
21 #ifndef AtomicString_h
22 #define AtomicString_h
23 
24 #include "AtomicStringImpl.h"
25 #include "dom/dom_string.h"
26 
27 using DOM::DOMString;
28 using DOM::DOMStringImpl;
29 
30 namespace khtml
31 {
32 
33 class AtomicString
34 {
35 public:
36  static void init();
37 
38  AtomicString() { }
39  AtomicString(const char *s) : m_string(add(s)) { }
40  AtomicString(const QChar *s, int length) : m_string(add(s, length)) { }
41  AtomicString(const QChar *s) : m_string(add(s)) { }
42  //AtomicString(const KJS::UString& s) : m_string(add(s)) { }
43  //AtomicString(const KJS::Identifier& s) : m_string(add(s)) { }
44  AtomicString(DOMStringImpl *imp) : m_string(add(imp)) { }
45  AtomicString(AtomicStringImpl *imp) : m_string(imp) { }
46  AtomicString(const DOMString &s) : m_string(add(s.implementation())) { }
47 
48  //static AtomicStringImpl* find(const KJS::Identifier&);
49 
50  operator const DOMString &() const
51  {
52  return m_string;
53  }
54  const DOMString &string() const
55  {
56  return m_string;
57  };
58 
59  //operator KJS::UString() const;
60 
61  AtomicStringImpl *impl() const
62  {
63  return static_cast<AtomicStringImpl *>(m_string.implementation());
64  }
65 
66  const QChar *characters() const
67  {
68  return m_string.characters();
69  }
70  unsigned length() const
71  {
72  return m_string.length();
73  }
74 
75  QChar operator[](unsigned int i) const
76  {
77  return m_string[i];
78  }
79 
80  /*FIXME: not yet implemented in DOMString
81  bool contains(QChar c) const { return m_string.contains(c); }
82  bool contains(const AtomicString& s, bool caseSensitive = true) const
83  { return m_string.contains(s.string(), caseSensitive); }
84 
85  int find(QChar c, int start = 0) const { return m_string.find(c, start); }
86  int find(const AtomicString& s, int start = 0, bool caseSentitive = true) const
87  { return m_string.find(s.string(), start, caseSentitive); }
88 
89  bool startsWith(const AtomicString& s, bool caseSensitive = true) const
90  { return m_string.startsWith(s.string(), caseSensitive); }
91  bool endsWith(const AtomicString& s, bool caseSensitive = true) const
92  { return m_string.endsWith(s.string(), caseSensitive); }
93 
94  int toInt(bool* ok = 0) const { return m_string.toInt(ok); }
95  double toDouble(bool* ok = 0) const { return m_string.toDouble(ok); }
96  float toFloat(bool* ok = 0) const { return m_string.toFloat(ok); }
97  bool percentage(int& p) const { return m_string.percentage(p); }
98  Length* toLengthArray(int& len) const { return m_string.toLengthArray(len); }
99  Length* toCoordsArray(int& len) const { return m_string.toCoordsArray(len); }*/
100 
101  bool isNull() const
102  {
103  return m_string.isNull();
104  }
105  bool isEmpty() const
106  {
107  return m_string.isEmpty();
108  }
109 
110  static void remove(DOMStringImpl *);
111 
112 private:
113  DOMString m_string;
114 
115  static DOMStringImpl *add(const char *);
116  static DOMStringImpl *add(const QChar *, int length);
117  static DOMStringImpl *add(const QChar *);
118  static DOMStringImpl *add(DOMStringImpl *);
119  //static PassRefPtr<DOMStringImpl> add(const KJS::UString&);
120  //static PassRefPtr<DOMStringImpl> add(const KJS::Identifier&);
121 };
122 
123 inline bool operator==(const AtomicString &a, const AtomicString &b)
124 {
125  return a.impl() == b.impl();
126 }
127 bool operator==(const AtomicString &a, const char *b);
128 //inline bool operator==(const AtomicString& a, const DOMString& b) { return equal(a.impl(), b.implementation()); }
129 inline bool operator==(const char *a, const AtomicString &b)
130 {
131  return b == a;
132 }
133 /*inline bool operator==(const DOMString& a, const AtomicString& b) { return equal(a.implementation(), b.impl()); }*/
134 
135 inline bool operator!=(const AtomicString &a, const AtomicString &b)
136 {
137  return a.impl() != b.impl();
138 }
139 /*inline bool operator!=(const AtomicString& a, const char *b) { return !(a == b); }
140 inline bool operator!=(const AtomicString& a, const String& b) { return !equal(a.impl(), b.impl()); }
141 inline bool operator!=(const char* a, const AtomicString& b) { return !(b == a); }
142 inline bool operator!=(const String& a, const AtomicString& b) { return !equal(a.impl(), b.impl()); }
143 
144 inline bool equalIgnoringCase(const AtomicString& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); }
145 inline bool equalIgnoringCase(const AtomicString& a, const char* b) { return equalIgnoringCase(a.impl(), b); }
146 inline bool equalIgnoringCase(const AtomicString& a, const String& b) { return equalIgnoringCase(a.impl(), b.impl()); }
147 inline bool equalIgnoringCase(const char* a, const AtomicString& b) { return equalIgnoringCase(a, b.impl()); }
148 inline bool equalIgnoringCase(const String& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); }*/
149 
150 // Define external global variables for the commonly used atomic strings.
151 #ifndef ATOMICSTRING_HIDE_GLOBALS
152 extern const AtomicString nullAtom;
153 extern const AtomicString emptyAtom;
154 extern const AtomicString textAtom;
155 extern const AtomicString commentAtom;
156 extern const AtomicString starAtom;
157 #endif
158 
159 }
160 
161 #endif // AtomicString_h
This file is part of the HTML rendering engine for KDE.
KIOFILEWIDGETS_EXPORT void add(const QString &fileClass, const QString &directory)
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
bool isNull() const const
QCA_EXPORT void init()
bool operator!=(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:47:58 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.