File indexing completed on 2024-10-06 12:19:32
0001 /* 0002 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 * 0019 */ 0020 0021 #ifndef AtomicString_h 0022 #define AtomicString_h 0023 0024 #include "AtomicStringImpl.h" 0025 #include "dom/dom_string.h" 0026 0027 using DOM::DOMString; 0028 using DOM::DOMStringImpl; 0029 0030 namespace khtml 0031 { 0032 0033 class AtomicString 0034 { 0035 public: 0036 static void init(); 0037 0038 AtomicString() { } 0039 AtomicString(const char *s) : m_string(add(s)) { } 0040 AtomicString(const QChar *s, int length) : m_string(add(s, length)) { } 0041 AtomicString(const QChar *s) : m_string(add(s)) { } 0042 //AtomicString(const KJS::UString& s) : m_string(add(s)) { } 0043 //AtomicString(const KJS::Identifier& s) : m_string(add(s)) { } 0044 AtomicString(DOMStringImpl *imp) : m_string(add(imp)) { } 0045 AtomicString(AtomicStringImpl *imp) : m_string(imp) { } 0046 AtomicString(const DOMString &s) : m_string(add(s.implementation())) { } 0047 0048 //static AtomicStringImpl* find(const KJS::Identifier&); 0049 0050 operator const DOMString &() const 0051 { 0052 return m_string; 0053 } 0054 const DOMString &string() const 0055 { 0056 return m_string; 0057 }; 0058 0059 //operator KJS::UString() const; 0060 0061 AtomicStringImpl *impl() const 0062 { 0063 return static_cast<AtomicStringImpl *>(m_string.implementation()); 0064 } 0065 0066 const QChar *characters() const 0067 { 0068 return m_string.characters(); 0069 } 0070 unsigned length() const 0071 { 0072 return m_string.length(); 0073 } 0074 0075 QChar operator[](unsigned int i) const 0076 { 0077 return m_string[i]; 0078 } 0079 0080 /*FIXME: not yet implemented in DOMString 0081 bool contains(QChar c) const { return m_string.contains(c); } 0082 bool contains(const AtomicString& s, bool caseSensitive = true) const 0083 { return m_string.contains(s.string(), caseSensitive); } 0084 0085 int find(QChar c, int start = 0) const { return m_string.find(c, start); } 0086 int find(const AtomicString& s, int start = 0, bool caseSentitive = true) const 0087 { return m_string.find(s.string(), start, caseSentitive); } 0088 0089 bool startsWith(const AtomicString& s, bool caseSensitive = true) const 0090 { return m_string.startsWith(s.string(), caseSensitive); } 0091 bool endsWith(const AtomicString& s, bool caseSensitive = true) const 0092 { return m_string.endsWith(s.string(), caseSensitive); } 0093 0094 int toInt(bool* ok = 0) const { return m_string.toInt(ok); } 0095 double toDouble(bool* ok = 0) const { return m_string.toDouble(ok); } 0096 float toFloat(bool* ok = 0) const { return m_string.toFloat(ok); } 0097 bool percentage(int& p) const { return m_string.percentage(p); } 0098 Length* toLengthArray(int& len) const { return m_string.toLengthArray(len); } 0099 Length* toCoordsArray(int& len) const { return m_string.toCoordsArray(len); }*/ 0100 0101 bool isNull() const 0102 { 0103 return m_string.isNull(); 0104 } 0105 bool isEmpty() const 0106 { 0107 return m_string.isEmpty(); 0108 } 0109 0110 static void remove(DOMStringImpl *); 0111 0112 private: 0113 DOMString m_string; 0114 0115 static DOMStringImpl *add(const char *); 0116 static DOMStringImpl *add(const QChar *, int length); 0117 static DOMStringImpl *add(const QChar *); 0118 static DOMStringImpl *add(DOMStringImpl *); 0119 //static PassRefPtr<DOMStringImpl> add(const KJS::UString&); 0120 //static PassRefPtr<DOMStringImpl> add(const KJS::Identifier&); 0121 }; 0122 0123 inline bool operator==(const AtomicString &a, const AtomicString &b) 0124 { 0125 return a.impl() == b.impl(); 0126 } 0127 bool operator==(const AtomicString &a, const char *b); 0128 //inline bool operator==(const AtomicString& a, const DOMString& b) { return equal(a.impl(), b.implementation()); } 0129 inline bool operator==(const char *a, const AtomicString &b) 0130 { 0131 return b == a; 0132 } 0133 /*inline bool operator==(const DOMString& a, const AtomicString& b) { return equal(a.implementation(), b.impl()); }*/ 0134 0135 inline bool operator!=(const AtomicString &a, const AtomicString &b) 0136 { 0137 return a.impl() != b.impl(); 0138 } 0139 /*inline bool operator!=(const AtomicString& a, const char *b) { return !(a == b); } 0140 inline bool operator!=(const AtomicString& a, const String& b) { return !equal(a.impl(), b.impl()); } 0141 inline bool operator!=(const char* a, const AtomicString& b) { return !(b == a); } 0142 inline bool operator!=(const String& a, const AtomicString& b) { return !equal(a.impl(), b.impl()); } 0143 0144 inline bool equalIgnoringCase(const AtomicString& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); } 0145 inline bool equalIgnoringCase(const AtomicString& a, const char* b) { return equalIgnoringCase(a.impl(), b); } 0146 inline bool equalIgnoringCase(const AtomicString& a, const String& b) { return equalIgnoringCase(a.impl(), b.impl()); } 0147 inline bool equalIgnoringCase(const char* a, const AtomicString& b) { return equalIgnoringCase(a, b.impl()); } 0148 inline bool equalIgnoringCase(const String& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); }*/ 0149 0150 // Define external global variables for the commonly used atomic strings. 0151 #ifndef ATOMICSTRING_HIDE_GLOBALS 0152 extern const AtomicString nullAtom; 0153 extern const AtomicString emptyAtom; 0154 extern const AtomicString textAtom; 0155 extern const AtomicString commentAtom; 0156 extern const AtomicString starAtom; 0157 #endif 0158 0159 } 0160 0161 #endif // AtomicString_h