00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef AtomicString_h
00024 #define AtomicString_h
00025
00026 #include "AtomicStringImpl.h"
00027 #include "PlatformString.h"
00028
00029 namespace WebCore {
00030
00031 class AtomicString {
00032 public:
00033 static void init();
00034
00035 AtomicString() { }
00036 AtomicString(const char* s) : m_string(add(s)) { }
00037 AtomicString(const UChar* s, int length) : m_string(add(s, length)) { }
00038 AtomicString(const KJS::UString& s) : m_string(add(s)) { }
00039 AtomicString(const KJS::Identifier& s) : m_string(add(s)) { }
00040 AtomicString(StringImpl* imp) : m_string(add(imp)) { }
00041 AtomicString(AtomicStringImpl* imp) : m_string(imp) { }
00042 AtomicString(const String& s) : m_string(add(s.impl())) { }
00043
00044 operator const String&() const { return m_string; }
00045 const String& domString() const { return m_string; };
00046
00047 operator KJS::Identifier() const;
00048 operator KJS::UString() const;
00049
00050 AtomicStringImpl* impl() const { return static_cast<AtomicStringImpl *>(m_string.impl()); }
00051
00052 const UChar* characters() const { return m_string.characters(); }
00053 unsigned length() const { return m_string.length(); }
00054
00055 UChar operator[](unsigned int i) const { return m_string[i]; }
00056
00057 bool contains(UChar c) const { return m_string.contains(c); }
00058 bool contains(const AtomicString& s, bool caseSensitive = true) const
00059 { return m_string.contains(s.domString(), caseSensitive); }
00060
00061 int find(UChar c, int start = 0) const { return m_string.find(c, start); }
00062 int find(const AtomicString& s, int start = 0, bool caseSentitive = true) const
00063 { return m_string.find(s.domString(), start, caseSentitive); }
00064
00065 bool startsWith(const AtomicString& s, bool caseSensitive = true) const
00066 { return m_string.startsWith(s.domString(), caseSensitive); }
00067 bool endsWith(const AtomicString& s, bool caseSensitive = true) const
00068 { return m_string.endsWith(s.domString(), caseSensitive); }
00069
00070 int toInt(bool* ok = 0) const { return m_string.toInt(ok); }
00071 double toDouble(bool* ok = 0) const { return m_string.toDouble(ok); }
00072 float toFloat(bool* ok = 0) const { return m_string.toFloat(ok); }
00073 bool percentage(int& p) const { return m_string.percentage(p); }
00074 Length* toLengthArray(int& len) const { return m_string.toLengthArray(len); }
00075 Length* toCoordsArray(int& len) const { return m_string.toCoordsArray(len); }
00076
00077 bool isNull() const { return m_string.isNull(); }
00078 bool isEmpty() const { return m_string.isEmpty(); }
00079
00080 static void remove(StringImpl*);
00081
00082 #ifdef __OBJC__
00083 AtomicString(NSString* s) : m_string(add(String(s).impl())) { }
00084 operator NSString*() const { return m_string; }
00085 #endif
00086 #if PLATFORM(SYMBIAN)
00087 AtomicString(const TDesC& s) : m_string(add(String(s).impl())) { }
00088 operator TPtrC() const { return m_string; }
00089 #endif
00090 #if PLATFORM(QT)
00091 AtomicString(const QString& s) : m_string(add(String(s).impl())) { }
00092 operator QString() const { return m_string; }
00093 #endif
00094
00095 AtomicString(const DeprecatedString&);
00096 DeprecatedString deprecatedString() const;
00097
00098 private:
00099 String m_string;
00100
00101 static StringImpl* add(const char*);
00102 static StringImpl* add(const UChar*, int length);
00103 static StringImpl* add(StringImpl*);
00104 static StringImpl* add(const KJS::UString&);
00105 static StringImpl* add(const KJS::Identifier&);
00106 };
00107
00108 inline bool operator==(const AtomicString& a, const AtomicString& b) { return a.impl() == b.impl(); }
00109 bool operator==(const AtomicString& a, const char* b);
00110 inline bool operator==(const AtomicString& a, const String& b) { return equal(a.impl(), b.impl()); }
00111 inline bool operator==(const char* a, const AtomicString& b) { return b == a; }
00112 inline bool operator==(const String& a, const AtomicString& b) { return equal(a.impl(), b.impl()); }
00113
00114 inline bool operator!=(const AtomicString& a, const AtomicString& b) { return a.impl() != b.impl(); }
00115 inline bool operator!=(const AtomicString& a, const char *b) { return !(a == b); }
00116 inline bool operator!=(const AtomicString& a, const String& b) { return !equal(a.impl(), b.impl()); }
00117 inline bool operator!=(const char* a, const AtomicString& b) { return !(b == a); }
00118 inline bool operator!=(const String& a, const AtomicString& b) { return !equal(a.impl(), b.impl()); }
00119
00120 inline bool equalIgnoringCase(const AtomicString& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); }
00121 inline bool equalIgnoringCase(const AtomicString& a, const char* b) { return equalIgnoringCase(a.impl(), b); }
00122 inline bool equalIgnoringCase(const AtomicString& a, const String& b) { return equalIgnoringCase(a.impl(), b.impl()); }
00123 inline bool equalIgnoringCase(const char* a, const AtomicString& b) { return equalIgnoringCase(a, b.impl()); }
00124 inline bool equalIgnoringCase(const String& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); }
00125
00126
00127 #ifndef ATOMICSTRING_HIDE_GLOBALS
00128 extern const AtomicString nullAtom;
00129 extern const AtomicString emptyAtom;
00130 extern const AtomicString textAtom;
00131 extern const AtomicString commentAtom;
00132 extern const AtomicString starAtom;
00133 #endif
00134
00135 }
00136
00137 #endif // AtomicString_h