]> git.saurik.com Git - apple/javascriptcore.git/blame - kjs/identifier.h
JavaScriptCore-461.tar.gz
[apple/javascriptcore.git] / kjs / identifier.h
CommitLineData
b37bf2e1
A
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
26namespace KJS {
27
28 class Identifier {
29 friend class PropertyMap;
30 public:
31 Identifier() { }
32 Identifier(const char* s) : _ustring(add(s)) { }
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*, const UString::Rep*);
69
70 private:
71 UString _ustring;
72
73 static bool equal(const Identifier& a, const Identifier& b)
74 { return a._ustring.rep() == b._ustring.rep(); }
75 static bool equal(const Identifier& a, const char* b)
76 { return equal(a._ustring.rep(), b); }
77
78 static PassRefPtr<UString::Rep> add(const char*);
79 static PassRefPtr<UString::Rep> add(const UChar*, int length);
80 static PassRefPtr<UString::Rep> add(UString::Rep* r)
81 {
82 if (r->isIdentifier)
83 return r;
84 return addSlowCase(r);
85 }
86 static PassRefPtr<UString::Rep> addSlowCase(UString::Rep *r);
87 };
88
89 inline bool operator==(const Identifier& a, const Identifier& b)
90 { return Identifier::equal(a, b); }
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 char* b)
96 { return Identifier::equal(a, b); }
97
98} // namespace KJS
99
100#endif // KJS_IDENTIFIER_H