]>
git.saurik.com Git - apple/javascriptcore.git/blob - kjs/identifier.h
2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
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.
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.
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.
21 #ifndef KJS_IDENTIFIER_H
22 #define KJS_IDENTIFIER_H
29 friend class PropertyMap
;
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())) { }
37 // Special constructor for cases where we overwrite an object in place.
38 Identifier(PlacementNewAdoptType
) : _ustring(PlacementNewAdopt
) { }
40 const UString
& ustring() const { return _ustring
; }
41 DOM::DOMString
domString() const;
43 const UChar
* data() const { return _ustring
.data(); }
44 int size() const { return _ustring
.size(); }
46 const char* ascii() const { return _ustring
.ascii(); }
48 static Identifier
from(unsigned y
) { return Identifier(UString::from(y
)); }
50 bool isNull() const { return _ustring
.isNull(); }
51 bool isEmpty() const { return _ustring
.isEmpty(); }
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(); }
59 friend bool operator==(const Identifier
&, const Identifier
&);
60 friend bool operator!=(const Identifier
&, const Identifier
&);
62 friend bool operator==(const Identifier
&, const char*);
64 static void remove(UString::Rep
* );
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
*);
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
); }
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
)
84 return addSlowCase(r
);
86 static PassRefPtr
<UString::Rep
> addSlowCase(UString::Rep
*r
);
89 inline bool operator==(const Identifier
& a
, const Identifier
& b
)
90 { return Identifier::equal(a
, b
); }
92 inline bool operator!=(const Identifier
& a
, const Identifier
& b
)
93 { return !Identifier::equal(a
, b
); }
95 inline bool operator==(const Identifier
& a
, const char* b
)
96 { return Identifier::equal(a
, b
); }
100 #endif // KJS_IDENTIFIER_H