KJS

identifier.h
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 Street, 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 #include <wtf/HashFunctions.h>
28 #include <wtf/HashTraits.h>
29 
30 namespace KJS
31 {
32 
36 class KJS_EXPORT Identifier
37 {
38  friend class PropertyMap;
39 public:
43  Identifier() { }
50  Identifier(const char *s) : _ustring(add(s)) { }
51  Identifier(const UChar *s, int length) : _ustring(add(s, length)) { }
52  explicit Identifier(UString::Rep *rep) : _ustring(add(rep)) { }
53  explicit Identifier(const UString &s) : _ustring(add(s.rep())) { }
54 
58  const UString &ustring() const
59  {
60  return _ustring;
61  }
62  KJS_EXTERNAL_EXPORT DOM::DOMString domString() const;
66  KJS_EXTERNAL_EXPORT QString qstring() const;
67 
71  const UChar *data() const
72  {
73  return _ustring.data();
74  }
78  int size() const
79  {
80  return _ustring.size();
81  }
82 
86  const char *ascii() const
87  {
88  return _ustring.ascii();
89  }
90 
91  static Identifier from(unsigned y)
92  {
93  return Identifier(UString::from(y));
94  }
95 
99  bool isNull() const
100  {
101  return _ustring.isNull();
102  }
106  bool isEmpty() const
107  {
108  return _ustring.isEmpty();
109  }
110 
111  uint32_t toStrictUInt32(bool *ok) const
112  {
113  return _ustring.toStrictUInt32(ok);
114  }
115  unsigned toArrayIndex(bool *ok) const
116  {
117  return _ustring.toArrayIndex(ok);
118  }
119  double toDouble() const
120  {
121  return _ustring.toDouble();
122  }
123 
124  friend bool operator==(const Identifier &, const Identifier &);
125  friend bool operator!=(const Identifier &, const Identifier &);
126 
127  friend bool operator==(const Identifier &, const char *);
128 
129  static void remove(UString::Rep *);
130  static bool equal(const UString::Rep *, const char *);
131  static bool equal(const UString::Rep *, const UChar *, int length);
132 
133 private:
134  UString _ustring;
135 
136  static bool equal(const Identifier &a, const Identifier &b)
137  {
138  return a._ustring.rep() == b._ustring.rep();
139  }
140  static bool equal(const Identifier &a, const char *b)
141  {
142  return equal(a._ustring.rep(), b);
143  }
144 
145  static PassRefPtr<UString::Rep> add(const char *);
146  static PassRefPtr<UString::Rep> add(const UChar *, int length);
147  static PassRefPtr<UString::Rep> add(UString::Rep *r)
148  {
149  if (r->isIdentifier) {
150  return r;
151  }
152  return addSlowCase(r);
153  }
154  static PassRefPtr<UString::Rep> addSlowCase(UString::Rep *r);
155 };
156 
157 inline bool operator==(const Identifier &a, const Identifier &b)
158 {
159  return Identifier::equal(a, b);
160 }
161 
162 inline bool operator!=(const Identifier &a, const Identifier &b)
163 {
164  return !Identifier::equal(a, b);
165 }
166 
167 inline bool operator==(const Identifier &a, const char *b)
168 {
169  return Identifier::equal(a, b);
170 }
171 
172 } // namespace KJS
173 
174 #endif // KJS_IDENTIFIER_H
bool isNull() const
Returns the identfiers state of being unset.
Definition: identifier.h:99
const UChar * data() const
returns a UChar pointer to the string of the identifier with a size defined by size().
Definition: identifier.h:71
bool isEmpty() const
Returns that the identifiers string is set, but is empty.
Definition: identifier.h:106
Identifier(const char *s)
Creates an identifier with the name of the string.
Definition: identifier.h:50
const char * ascii() const
Char * of the identifier&#39;s string.
Definition: identifier.h:86
Unicode string class.
Definition: ustring.h:153
static UString from(int i)
Constructs a string from an int.
Definition: ustring.cpp:562
Unicode character.
Definition: ustring.h:70
const UString & ustring() const
returns a UString of the identifier
Definition: identifier.h:58
int size() const
The size of the UChar string returned.
Definition: identifier.h:78
Identifier()
Creates an empty identifier.
Definition: identifier.h:43
Represents an Identifier for a Javascript object.
Definition: identifier.h:36
Javascript Property Map.
Definition: property_map.h:81
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Aug 11 2020 23:02:27 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.