2 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
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.
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.
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.
21 #ifndef AtomicString_h
22 #define AtomicString_h
24 #include "AtomicStringImpl.h"
25 #include "dom/dom_string.h"
28 using DOM::DOMStringImpl
;
37 AtomicString(const char* s
) : m_string(add(s
)) { }
38 AtomicString(const QChar
* s
, int length
) : m_string(add(s
, length
)) { }
39 AtomicString(const QChar
* s
) : m_string(add(s
)) { }
40 //AtomicString(const KJS::UString& s) : m_string(add(s)) { }
41 //AtomicString(const KJS::Identifier& s) : m_string(add(s)) { }
42 AtomicString(DOMStringImpl
* imp
) : m_string(add(imp
)) { }
43 AtomicString(AtomicStringImpl
* imp
) : m_string(imp
) { }
44 AtomicString(const DOMString
& s
) : m_string(add(s
.implementation())) { }
46 //static AtomicStringImpl* find(const KJS::Identifier&);
48 operator const DOMString
&() const { return m_string
; }
49 const DOMString
& string() const { return m_string
; };
51 //operator KJS::UString() const;
53 AtomicStringImpl
* impl() const { return static_cast<AtomicStringImpl
*>(m_string
.implementation()); }
55 const QChar
* characters() const { return m_string
.characters(); }
56 unsigned length() const { return m_string
.length(); }
58 QChar
operator[](unsigned int i
) const { return m_string
[i
]; }
60 /*FIXME: not yet implemented in DOMString
61 bool contains(QChar c) const { return m_string.contains(c); }
62 bool contains(const AtomicString& s, bool caseSensitive = true) const
63 { return m_string.contains(s.string(), caseSensitive); }
65 int find(QChar c, int start = 0) const { return m_string.find(c, start); }
66 int find(const AtomicString& s, int start = 0, bool caseSentitive = true) const
67 { return m_string.find(s.string(), start, caseSentitive); }
69 bool startsWith(const AtomicString& s, bool caseSensitive = true) const
70 { return m_string.startsWith(s.string(), caseSensitive); }
71 bool endsWith(const AtomicString& s, bool caseSensitive = true) const
72 { return m_string.endsWith(s.string(), caseSensitive); }
74 int toInt(bool* ok = 0) const { return m_string.toInt(ok); }
75 double toDouble(bool* ok = 0) const { return m_string.toDouble(ok); }
76 float toFloat(bool* ok = 0) const { return m_string.toFloat(ok); }
77 bool percentage(int& p) const { return m_string.percentage(p); }
78 Length* toLengthArray(int& len) const { return m_string.toLengthArray(len); }
79 Length* toCoordsArray(int& len) const { return m_string.toCoordsArray(len); }*/
81 bool isNull() const { return m_string
.isNull(); }
82 bool isEmpty() const { return m_string
.isEmpty(); }
84 static void remove(DOMStringImpl
*);
89 static DOMStringImpl
* add(const char*);
90 static DOMStringImpl
* add(const QChar
*, int length
);
91 static DOMStringImpl
* add(const QChar
*);
92 static DOMStringImpl
* add(DOMStringImpl
*);
93 //static PassRefPtr<DOMStringImpl> add(const KJS::UString&);
94 //static PassRefPtr<DOMStringImpl> add(const KJS::Identifier&);
97 inline bool operator==(const AtomicString
& a
, const AtomicString
& b
) { return a
.impl() == b
.impl(); }
98 bool operator==(const AtomicString
& a
, const char* b
);
99 //inline bool operator==(const AtomicString& a, const DOMString& b) { return equal(a.impl(), b.implementation()); }
100 inline bool operator==(const char* a
, const AtomicString
& b
) { return b
== a
; }
101 /*inline bool operator==(const DOMString& a, const AtomicString& b) { return equal(a.implementation(), b.impl()); }*/
103 inline bool operator!=(const AtomicString
& a
, const AtomicString
& b
) { return a
.impl() != b
.impl(); }
104 /*inline bool operator!=(const AtomicString& a, const char *b) { return !(a == b); }
105 inline bool operator!=(const AtomicString& a, const String& b) { return !equal(a.impl(), b.impl()); }
106 inline bool operator!=(const char* a, const AtomicString& b) { return !(b == a); }
107 inline bool operator!=(const String& a, const AtomicString& b) { return !equal(a.impl(), b.impl()); }
109 inline bool equalIgnoringCase(const AtomicString& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); }
110 inline bool equalIgnoringCase(const AtomicString& a, const char* b) { return equalIgnoringCase(a.impl(), b); }
111 inline bool equalIgnoringCase(const AtomicString& a, const String& b) { return equalIgnoringCase(a.impl(), b.impl()); }
112 inline bool equalIgnoringCase(const char* a, const AtomicString& b) { return equalIgnoringCase(a, b.impl()); }
113 inline bool equalIgnoringCase(const String& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); }*/
115 // Define external global variables for the commonly used atomic strings.
116 #ifndef ATOMICSTRING_HIDE_GLOBALS
117 extern const AtomicString nullAtom
;
118 extern const AtomicString emptyAtom
;
119 extern const AtomicString textAtom
;
120 extern const AtomicString commentAtom
;
121 extern const AtomicString starAtom
;
126 #endif // AtomicString_h