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 "PlatformString.h"
29 struct AtomicStringHash
;
36 AtomicString(const char* s
) : m_string(add(s
)) { }
37 AtomicString(const UChar
* s
, int length
) : m_string(add(s
, length
)) { }
38 AtomicString(const UChar
* s
) : m_string(add(s
)) { }
40 AtomicString(const JSC::UString
& s
) : m_string(add(s
)) { }
41 AtomicString(const JSC::Identifier
& s
) : m_string(add(s
)) { }
43 AtomicString(StringImpl
* imp
) : m_string(add(imp
)) { }
44 AtomicString(AtomicStringImpl
* imp
) : m_string(imp
) { }
45 AtomicString(const String
& s
) : m_string(add(s
.impl())) { }
47 // Hash table deleted values, which are only constructed and never copied or destroyed.
48 AtomicString(WTF::HashTableDeletedValueType
) : m_string(WTF::HashTableDeletedValue
) { }
49 bool isHashTableDeletedValue() const { return m_string
.isHashTableDeletedValue(); }
52 static AtomicStringImpl
* find(const JSC::Identifier
&);
55 operator const String
&() const { return m_string
; }
56 const String
& string() const { return m_string
; };
59 operator JSC::UString() const;
62 AtomicStringImpl
* impl() const { return static_cast<AtomicStringImpl
*>(m_string
.impl()); }
64 const UChar
* characters() const { return m_string
.characters(); }
65 unsigned length() const { return m_string
.length(); }
67 UChar
operator[](unsigned int i
) const { return m_string
[i
]; }
69 bool contains(UChar c
) const { return m_string
.contains(c
); }
70 bool contains(const AtomicString
& s
, bool caseSensitive
= true) const
71 { return m_string
.contains(s
.string(), caseSensitive
); }
73 int find(UChar c
, int start
= 0) const { return m_string
.find(c
, start
); }
74 int find(const AtomicString
& s
, int start
= 0, bool caseSentitive
= true) const
75 { return m_string
.find(s
.string(), start
, caseSentitive
); }
77 bool startsWith(const AtomicString
& s
, bool caseSensitive
= true) const
78 { return m_string
.startsWith(s
.string(), caseSensitive
); }
79 bool endsWith(const AtomicString
& s
, bool caseSensitive
= true) const
80 { return m_string
.endsWith(s
.string(), caseSensitive
); }
82 int toInt(bool* ok
= 0) const { return m_string
.toInt(ok
); }
83 double toDouble(bool* ok
= 0) const { return m_string
.toDouble(ok
); }
84 float toFloat(bool* ok
= 0) const { return m_string
.toFloat(ok
); }
85 bool percentage(int& p
) const { return m_string
.percentage(p
); }
87 bool isNull() const { return m_string
.isNull(); }
88 bool isEmpty() const { return m_string
.isEmpty(); }
90 static void remove(StringImpl
*);
92 #if PLATFORM(CF) || (PLATFORM(QT) && PLATFORM(DARWIN))
93 AtomicString(CFStringRef s
) : m_string(add(String(s
).impl())) { }
94 CFStringRef
createCFString() const { return m_string
.createCFString(); }
97 AtomicString(NSString
* s
) : m_string(add(String(s
).impl())) { }
98 operator NSString
*() const { return m_string
; }
101 AtomicString(const QString
& s
) : m_string(add(String(s
).impl())) { }
102 operator QString() const { return m_string
; }
108 static PassRefPtr
<StringImpl
> add(const char*);
109 static PassRefPtr
<StringImpl
> add(const UChar
*, int length
);
110 static PassRefPtr
<StringImpl
> add(const UChar
*);
111 static PassRefPtr
<StringImpl
> add(StringImpl
*);
113 static PassRefPtr
<StringImpl
> add(const JSC::UString
&);
114 static PassRefPtr
<StringImpl
> add(const JSC::Identifier
&);
118 inline bool operator==(const AtomicString
& a
, const AtomicString
& b
) { return a
.impl() == b
.impl(); }
119 bool operator==(const AtomicString
& a
, const char* b
);
120 inline bool operator==(const AtomicString
& a
, const String
& b
) { return equal(a
.impl(), b
.impl()); }
121 inline bool operator==(const char* a
, const AtomicString
& b
) { return b
== a
; }
122 inline bool operator==(const String
& a
, const AtomicString
& b
) { return equal(a
.impl(), b
.impl()); }
124 inline bool operator!=(const AtomicString
& a
, const AtomicString
& b
) { return a
.impl() != b
.impl(); }
125 inline bool operator!=(const AtomicString
& a
, const char *b
) { return !(a
== b
); }
126 inline bool operator!=(const AtomicString
& a
, const String
& b
) { return !equal(a
.impl(), b
.impl()); }
127 inline bool operator!=(const char* a
, const AtomicString
& b
) { return !(b
== a
); }
128 inline bool operator!=(const String
& a
, const AtomicString
& b
) { return !equal(a
.impl(), b
.impl()); }
130 inline bool equalIgnoringCase(const AtomicString
& a
, const AtomicString
& b
) { return equalIgnoringCase(a
.impl(), b
.impl()); }
131 inline bool equalIgnoringCase(const AtomicString
& a
, const char* b
) { return equalIgnoringCase(a
.impl(), b
); }
132 inline bool equalIgnoringCase(const AtomicString
& a
, const String
& b
) { return equalIgnoringCase(a
.impl(), b
.impl()); }
133 inline bool equalIgnoringCase(const char* a
, const AtomicString
& b
) { return equalIgnoringCase(a
, b
.impl()); }
134 inline bool equalIgnoringCase(const String
& a
, const AtomicString
& b
) { return equalIgnoringCase(a
.impl(), b
.impl()); }
136 // Define external global variables for the commonly used atomic strings.
137 // These are only usable from the main thread.
138 #ifndef ATOMICSTRING_HIDE_GLOBALS
139 extern const AtomicString nullAtom
;
140 extern const AtomicString emptyAtom
;
141 extern const AtomicString textAtom
;
142 extern const AtomicString commentAtom
;
143 extern const AtomicString starAtom
;
146 } // namespace WebCore
151 // AtomicStringHash is the default hash for AtomicString
152 template<typename T
> struct DefaultHash
;
153 template<> struct DefaultHash
<WebCore::AtomicString
> {
154 typedef WebCore::AtomicStringHash Hash
;
159 #endif // AtomicString_h