identifier.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KJS_IDENTIFIER_H
00023 #define KJS_IDENTIFIER_H
00024
00025 #include "ustring.h"
00026
00027 namespace KJS {
00028
00032 class KJS_EXPORT Identifier {
00033 friend class PropertyMap;
00034 public:
00038 Identifier() { }
00045 Identifier(const char *s) : _ustring(add(s)) { }
00046 Identifier(const UChar *s, int length) : _ustring(add(s, length)) { }
00047 explicit Identifier(const UString &s) : _ustring(add(s.rep)) { }
00048
00052 const UString &ustring() const { return _ustring; }
00053 DOM::DOMString string() const;
00057 QString qstring() const;
00058
00062 const UChar *data() const { return _ustring.data(); }
00066 int size() const { return _ustring.size(); }
00067
00071 const char *ascii() const { return _ustring.ascii(); }
00072
00073 static Identifier from(unsigned y) { return Identifier(UString::from(y)); }
00074
00078 bool isNull() const { return _ustring.isNull(); }
00082 bool isEmpty() const { return _ustring.isEmpty(); }
00083
00084 unsigned long toULong(bool *ok) const { return _ustring.toULong(ok); }
00085 unsigned toStrictUInt32(bool *ok) const { return _ustring.toStrictUInt32(ok); }
00086 unsigned toArrayIndex(bool *ok) const { return _ustring.toArrayIndex(ok); }
00087
00088 double toDouble() const { return _ustring.toDouble(); }
00089
00093 static const Identifier &null();
00094
00095 friend bool operator==(const Identifier &, const Identifier &);
00096 friend bool operator!=(const Identifier &, const Identifier &);
00097
00098 friend bool operator==(const Identifier &, const char *);
00099
00100 static void remove(UString::Rep *);
00101
00102 private:
00103 UString _ustring;
00104
00105 static bool equal(UString::Rep *, const char *);
00106 static bool equal(UString::Rep *, const UChar *, int length);
00107 static bool equal(UString::Rep *, UString::Rep *);
00108
00109 static bool equal(const Identifier &a, const Identifier &b)
00110 { return a._ustring.rep == b._ustring.rep; }
00111 static bool equal(const Identifier &a, const char *b)
00112 { return equal(a._ustring.rep, b); }
00113
00114 static UString::Rep *add(const char *);
00115 static UString::Rep *add(const UChar *, int length);
00116 static UString::Rep *add(UString::Rep *);
00117
00118 static void insert(UString::Rep *);
00119
00120 static void rehash(int newTableSize);
00121 static void expand();
00122 static void shrink();
00123
00124
00125 static UString::Rep **_table;
00126 static int _tableSize;
00127 static int _tableSizeMask;
00128 static int _keyCount;
00129 };
00130
00131 inline bool operator==(const Identifier &a, const Identifier &b)
00132 { return Identifier::equal(a, b); }
00133
00134 inline bool operator!=(const Identifier &a, const Identifier &b)
00135 { return !Identifier::equal(a, b); }
00136
00137 inline bool operator==(const Identifier &a, const char *b)
00138 { return Identifier::equal(a, b); }
00139
00140 KJS_EXPORT extern const Identifier argumentsPropertyName;
00141 KJS_EXPORT extern const Identifier calleePropertyName;
00142 KJS_EXPORT extern const Identifier constructorPropertyName;
00143 KJS_EXPORT extern const Identifier lengthPropertyName;
00144 KJS_EXPORT extern const Identifier messagePropertyName;
00145 KJS_EXPORT extern const Identifier namePropertyName;
00146 KJS_EXPORT extern const Identifier prototypePropertyName;
00147 KJS_EXPORT extern const Identifier specialPrototypePropertyName;
00148 KJS_EXPORT extern const Identifier toLocaleStringPropertyName;
00149 KJS_EXPORT extern const Identifier toStringPropertyName;
00150 KJS_EXPORT extern const Identifier valueOfPropertyName;
00151
00152 }
00153
00154 #endif
|