1 | /*
|
---|
2 | * Copyright (C) 2003, 2006, 2007 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 KJS_IDENTIFIER_H
|
---|
22 | #define KJS_IDENTIFIER_H
|
---|
23 |
|
---|
24 | #include "ustring.h"
|
---|
25 |
|
---|
26 | namespace KJS {
|
---|
27 |
|
---|
28 | class Identifier {
|
---|
29 | friend class PropertyMap;
|
---|
30 | public:
|
---|
31 | Identifier() { }
|
---|
32 | Identifier(const char* s) : _ustring(add(s)) { } // Only to be used with string literals.
|
---|
33 | Identifier(const UChar* s, int length) : _ustring(add(s, length)) { }
|
---|
34 | explicit Identifier(UString::Rep* rep) : _ustring(add(rep)) { }
|
---|
35 | explicit Identifier(const UString& s) : _ustring(add(s.rep())) { }
|
---|
36 |
|
---|
37 | // Special constructor for cases where we overwrite an object in place.
|
---|
38 | Identifier(PlacementNewAdoptType) : _ustring(PlacementNewAdopt) { }
|
---|
39 |
|
---|
40 | const UString& ustring() const { return _ustring; }
|
---|
41 | DOM::DOMString domString() 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 toUInt32(bool* ok, bool tolerateEmptyString) const { return _ustring.toUInt32(ok, tolerateEmptyString); };
|
---|
55 | uint32_t toStrictUInt32(bool* ok) const { return _ustring.toStrictUInt32(ok); }
|
---|
56 | unsigned toArrayIndex(bool* ok) const { return _ustring.toArrayIndex(ok); }
|
---|
57 | double toDouble() const { return _ustring.toDouble(); }
|
---|
58 |
|
---|
59 | friend bool operator==(const Identifier&, const Identifier&);
|
---|
60 | friend bool operator!=(const Identifier&, const Identifier&);
|
---|
61 |
|
---|
62 | friend bool operator==(const Identifier&, const char*);
|
---|
63 |
|
---|
64 | static void remove(UString::Rep*);
|
---|
65 |
|
---|
66 | static bool equal(const UString::Rep*, const char*);
|
---|
67 | static bool equal(const UString::Rep*, const UChar*, int length);
|
---|
68 | static bool equal(const UString::Rep* a, const UString::Rep* b) { return KJS::equal(a, b); }
|
---|
69 |
|
---|
70 | static PassRefPtr<UString::Rep> add(const char*);
|
---|
71 |
|
---|
72 | static void initializeIdentifierThreading();
|
---|
73 |
|
---|
74 | private:
|
---|
75 | UString _ustring;
|
---|
76 |
|
---|
77 | static bool equal(const Identifier& a, const Identifier& b)
|
---|
78 | { return a._ustring.rep() == b._ustring.rep(); }
|
---|
79 | static bool equal(const Identifier& a, const char* b)
|
---|
80 | { return equal(a._ustring.rep(), b); }
|
---|
81 |
|
---|
82 | static PassRefPtr<UString::Rep> add(const UChar*, int length);
|
---|
83 | static PassRefPtr<UString::Rep> add(UString::Rep* r)
|
---|
84 | {
|
---|
85 | if (r->identifierTable)
|
---|
86 | return r;
|
---|
87 | return addSlowCase(r);
|
---|
88 | }
|
---|
89 | static PassRefPtr<UString::Rep> addSlowCase(UString::Rep *r);
|
---|
90 | };
|
---|
91 |
|
---|
92 | inline bool operator==(const Identifier& a, const Identifier& b)
|
---|
93 | { return Identifier::equal(a, b); }
|
---|
94 |
|
---|
95 | inline bool operator!=(const Identifier& a, const Identifier& b)
|
---|
96 | { return !Identifier::equal(a, b); }
|
---|
97 |
|
---|
98 | inline bool operator==(const Identifier& a, const char* b)
|
---|
99 | { return Identifier::equal(a, b); }
|
---|
100 |
|
---|
101 | } // namespace KJS
|
---|
102 |
|
---|
103 | #endif // KJS_IDENTIFIER_H
|
---|