1 | /*
|
---|
2 | * This file is part of the KDE libraries
|
---|
3 | * Copyright (C) 2003 Apple Computer, Inc
|
---|
4 | *
|
---|
5 | * This library is free software; you can redistribute it and/or
|
---|
6 | * modify it under the terms of the GNU Library General Public
|
---|
7 | * License as published by the Free Software Foundation; either
|
---|
8 | * version 2 of the License, or (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This library is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
13 | * Library General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU Library General Public License
|
---|
16 | * along with this library; see the file COPYING.LIB. If not, write to
|
---|
17 | * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
|
---|
18 | * Boston, MA 02110-1301, USA.
|
---|
19 | *
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef KJS_IDENTIFIER_H
|
---|
23 | #define KJS_IDENTIFIER_H
|
---|
24 |
|
---|
25 | #include "ustring.h"
|
---|
26 |
|
---|
27 | namespace KJS {
|
---|
28 |
|
---|
29 | class Identifier {
|
---|
30 | friend class PropertyMap;
|
---|
31 | public:
|
---|
32 | static void init();
|
---|
33 |
|
---|
34 | Identifier() { }
|
---|
35 | Identifier(const char *s) : _ustring(add(s)) { }
|
---|
36 | Identifier(const UChar *s, int length) : _ustring(add(s, length)) { }
|
---|
37 | explicit Identifier(const UString &s) : _ustring(add(s.rep)) { }
|
---|
38 |
|
---|
39 | const UString &ustring() const { return _ustring; }
|
---|
40 | DOM::DOMString domString() const;
|
---|
41 | QString qstring() const;
|
---|
42 |
|
---|
43 | const UChar *data() const { return _ustring.data(); }
|
---|
44 | int size() const { return _ustring.size(); }
|
---|
45 |
|
---|
46 | const char *ascii() const { return _ustring.ascii(); }
|
---|
47 |
|
---|
48 | static Identifier from(unsigned y) { return Identifier(UString::from(y)); }
|
---|
49 |
|
---|
50 | bool isNull() const { return _ustring.isNull(); }
|
---|
51 | bool isEmpty() const { return _ustring.isEmpty(); }
|
---|
52 |
|
---|
53 | uint32_t toUInt32(bool *ok) const { return _ustring.toUInt32(ok); }
|
---|
54 | uint32_t toStrictUInt32(bool *ok) const { return _ustring.toStrictUInt32(ok); }
|
---|
55 | unsigned toArrayIndex(bool *ok) const { return _ustring.toArrayIndex(ok); }
|
---|
56 | double toDouble() const { return _ustring.toDouble(); }
|
---|
57 |
|
---|
58 | static const Identifier &null();
|
---|
59 |
|
---|
60 | friend bool operator==(const Identifier &, const Identifier &);
|
---|
61 | friend bool operator!=(const Identifier &, const Identifier &);
|
---|
62 |
|
---|
63 | friend bool operator==(const Identifier &, const char *);
|
---|
64 |
|
---|
65 | static void remove(UString::Rep *);
|
---|
66 |
|
---|
67 | private:
|
---|
68 | UString _ustring;
|
---|
69 |
|
---|
70 | static bool equal(UString::Rep *, const char *);
|
---|
71 | static bool equal(UString::Rep *, const UChar *, int length);
|
---|
72 | static bool equal(UString::Rep *, UString::Rep *);
|
---|
73 |
|
---|
74 | static bool equal(const Identifier &a, const Identifier &b)
|
---|
75 | { return a._ustring.rep == b._ustring.rep; }
|
---|
76 | static bool equal(const Identifier &a, const char *b)
|
---|
77 | { return equal(a._ustring.rep, b); }
|
---|
78 |
|
---|
79 | static UString::Rep *add(const char *);
|
---|
80 | static UString::Rep *add(const UChar *, int length);
|
---|
81 | static UString::Rep *add(UString::Rep *);
|
---|
82 |
|
---|
83 | static void insert(UString::Rep *);
|
---|
84 |
|
---|
85 | static void rehash(int newTableSize);
|
---|
86 | static void expand();
|
---|
87 | static void shrink();
|
---|
88 |
|
---|
89 | static UString::Rep **_table;
|
---|
90 | static int _tableSize;
|
---|
91 | static int _tableSizeMask;
|
---|
92 | static int _keyCount;
|
---|
93 | };
|
---|
94 |
|
---|
95 | #if !KJS_IDENTIFIER_HIDE_GLOBALS
|
---|
96 | extern const Identifier nullIdentifier;
|
---|
97 |
|
---|
98 | inline const Identifier &Identifier::null()
|
---|
99 | { return nullIdentifier; }
|
---|
100 | #endif
|
---|
101 |
|
---|
102 | inline bool operator==(const Identifier &a, const Identifier &b)
|
---|
103 | { return Identifier::equal(a, b); }
|
---|
104 |
|
---|
105 | inline bool operator!=(const Identifier &a, const Identifier &b)
|
---|
106 | { return !Identifier::equal(a, b); }
|
---|
107 |
|
---|
108 | inline bool operator==(const Identifier &a, const char *b)
|
---|
109 | { return Identifier::equal(a, b); }
|
---|
110 |
|
---|
111 | // List of property names, passed to a macro so we can do set them up various
|
---|
112 | // ways without repeating the list.
|
---|
113 | #define KJS_IDENTIFIER_EACH_PROPERTY_NAME_GLOBAL(macro) \
|
---|
114 | macro(arguments) \
|
---|
115 | macro(callee) \
|
---|
116 | macro(constructor) \
|
---|
117 | macro(fromCharCode) \
|
---|
118 | macro(length) \
|
---|
119 | macro(message) \
|
---|
120 | macro(name) \
|
---|
121 | macro(prototype) \
|
---|
122 | macro(toLocaleString) \
|
---|
123 | macro(toString) \
|
---|
124 | macro(toFixed) \
|
---|
125 | macro(toExponential) \
|
---|
126 | macro(toPrecision) \
|
---|
127 | macro(valueOf)
|
---|
128 |
|
---|
129 | // Define external global variables for all property names above (and one more).
|
---|
130 | #if !KJS_IDENTIFIER_HIDE_GLOBALS
|
---|
131 | extern const Identifier specialPrototypePropertyName;
|
---|
132 |
|
---|
133 | #define KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL(name) extern const Identifier name ## PropertyName;
|
---|
134 | KJS_IDENTIFIER_EACH_PROPERTY_NAME_GLOBAL(KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL)
|
---|
135 | #undef KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL
|
---|
136 | #endif
|
---|
137 |
|
---|
138 | }
|
---|
139 |
|
---|
140 | #endif
|
---|