| OLD | NEW |
| (Empty) |
| 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 "PlatformString.h" | |
| 26 | |
| 27 namespace WebCore { | |
| 28 | |
| 29 class AtomicString { | |
| 30 public: | |
| 31 static void init(); | |
| 32 | |
| 33 AtomicString() { } | |
| 34 AtomicString(const char* s) : m_string(add(s)) { } | |
| 35 AtomicString(const UChar* s, int length) : m_string(add(s, length)) { } | |
| 36 AtomicString(const UChar* s) : m_string(add(s)) { } | |
| 37 #if USE(JSC) | |
| 38 AtomicString(const KJS::UString& s) : m_string(add(s)) { } | |
| 39 AtomicString(const KJS::Identifier& s) : m_string(add(s)) { } | |
| 40 #endif | |
| 41 AtomicString(StringImpl* imp) : m_string(add(imp)) { } | |
| 42 AtomicString(AtomicStringImpl* imp) : m_string(imp) { } | |
| 43 AtomicString(const String& s) : m_string(add(s.impl())) { } | |
| 44 | |
| 45 #if USE(JSC) | |
| 46 static AtomicStringImpl* find(const KJS::Identifier&); | |
| 47 #endif | |
| 48 | |
| 49 operator const String&() const { return m_string; } | |
| 50 const String& string() const { return m_string; }; | |
| 51 | |
| 52 #if USE(JSC) | |
| 53 operator KJS::UString() const; | |
| 54 #endif | |
| 55 | |
| 56 AtomicStringImpl* impl() const { return static_cast<AtomicStringImpl *>(m_st
ring.impl()); } | |
| 57 | |
| 58 const UChar* characters() const { return m_string.characters(); } | |
| 59 unsigned length() const { return m_string.length(); } | |
| 60 | |
| 61 UChar operator[](unsigned int i) const { return m_string[i]; } | |
| 62 | |
| 63 bool contains(UChar c) const { return m_string.contains(c); } | |
| 64 bool contains(const AtomicString& s, bool caseSensitive = true) const | |
| 65 { return m_string.contains(s.string(), caseSensitive); } | |
| 66 | |
| 67 int find(UChar c, int start = 0) const { return m_string.find(c, start); } | |
| 68 int find(const AtomicString& s, int start = 0, bool caseSentitive = true) co
nst | |
| 69 { return m_string.find(s.string(), start, caseSentitive); } | |
| 70 | |
| 71 bool startsWith(const AtomicString& s, bool caseSensitive = true) const | |
| 72 { return m_string.startsWith(s.string(), caseSensitive); } | |
| 73 bool endsWith(const AtomicString& s, bool caseSensitive = true) const | |
| 74 { return m_string.endsWith(s.string(), caseSensitive); } | |
| 75 | |
| 76 int toInt(bool* ok = 0) const { return m_string.toInt(ok); } | |
| 77 double toDouble(bool* ok = 0) const { return m_string.toDouble(ok); } | |
| 78 float toFloat(bool* ok = 0) const { return m_string.toFloat(ok); } | |
| 79 bool percentage(int& p) const { return m_string.percentage(p); } | |
| 80 Length* toLengthArray(int& len) const { return m_string.toLengthArray(len);
} | |
| 81 Length* toCoordsArray(int& len) const { return m_string.toCoordsArray(len);
} | |
| 82 | |
| 83 bool isNull() const { return m_string.isNull(); } | |
| 84 bool isEmpty() const { return m_string.isEmpty(); } | |
| 85 | |
| 86 static void remove(StringImpl*); | |
| 87 | |
| 88 #ifdef __OBJC__ | |
| 89 AtomicString(NSString* s) : m_string(add(String(s).impl())) { } | |
| 90 operator NSString*() const { return m_string; } | |
| 91 #endif | |
| 92 #if PLATFORM(SYMBIAN) | |
| 93 AtomicString(const TDesC& s) : m_string(add(String(s).impl())) { } | |
| 94 operator TPtrC() const { return m_string; } | |
| 95 #endif | |
| 96 #if PLATFORM(QT) | |
| 97 AtomicString(const QString& s) : m_string(add(String(s).impl())) { } | |
| 98 operator QString() const { return m_string; } | |
| 99 #endif | |
| 100 | |
| 101 private: | |
| 102 String m_string; | |
| 103 | |
| 104 static PassRefPtr<StringImpl> add(const char*); | |
| 105 static PassRefPtr<StringImpl> add(const UChar*, int length); | |
| 106 static PassRefPtr<StringImpl> add(const UChar*); | |
| 107 static PassRefPtr<StringImpl> add(StringImpl*); | |
| 108 #if USE(JSC) | |
| 109 static PassRefPtr<StringImpl> add(const KJS::UString&); | |
| 110 static PassRefPtr<StringImpl> add(const KJS::Identifier&); | |
| 111 #endif | |
| 112 }; | |
| 113 | |
| 114 inline bool operator==(const AtomicString& a, const AtomicString& b) { return a.
impl() == b.impl(); } | |
| 115 bool operator==(const AtomicString& a, const char* b); | |
| 116 inline bool operator==(const AtomicString& a, const String& b) { return equal(a.
impl(), b.impl()); } | |
| 117 inline bool operator==(const char* a, const AtomicString& b) { return b == a; } | |
| 118 inline bool operator==(const String& a, const AtomicString& b) { return equal(a.
impl(), b.impl()); } | |
| 119 | |
| 120 inline bool operator!=(const AtomicString& a, const AtomicString& b) { return a.
impl() != b.impl(); } | |
| 121 inline bool operator!=(const AtomicString& a, const char *b) { return !(a == b);
} | |
| 122 inline bool operator!=(const AtomicString& a, const String& b) { return !equal(a
.impl(), b.impl()); } | |
| 123 inline bool operator!=(const char* a, const AtomicString& b) { return !(b == a);
} | |
| 124 inline bool operator!=(const String& a, const AtomicString& b) { return !equal(a
.impl(), b.impl()); } | |
| 125 | |
| 126 inline bool equalIgnoringCase(const AtomicString& a, const AtomicString& b) { re
turn equalIgnoringCase(a.impl(), b.impl()); } | |
| 127 inline bool equalIgnoringCase(const AtomicString& a, const char* b) { return equ
alIgnoringCase(a.impl(), b); } | |
| 128 inline bool equalIgnoringCase(const AtomicString& a, const String& b) { return e
qualIgnoringCase(a.impl(), b.impl()); } | |
| 129 inline bool equalIgnoringCase(const char* a, const AtomicString& b) { return equ
alIgnoringCase(a, b.impl()); } | |
| 130 inline bool equalIgnoringCase(const String& a, const AtomicString& b) { return e
qualIgnoringCase(a.impl(), b.impl()); } | |
| 131 | |
| 132 // Define external global variables for the commonly used atomic strings. | |
| 133 #ifndef ATOMICSTRING_HIDE_GLOBALS | |
| 134 extern const AtomicString nullAtom; | |
| 135 extern const AtomicString emptyAtom; | |
| 136 extern const AtomicString textAtom; | |
| 137 extern const AtomicString commentAtom; | |
| 138 extern const AtomicString starAtom; | |
| 139 #endif | |
| 140 | |
| 141 } // namespace WebCore | |
| 142 | |
| 143 #endif // AtomicString_h | |
| OLD | NEW |