• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kjs
 

kjs

  • kjs
ustring.h
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
4  * Copyright (C) 2003 Apple Computer, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef _KJS_USTRING_H_
24 #define _KJS_USTRING_H_
25 
26 #include <tqstring.h>
27 #include "global.h"
28 
32 namespace DOM {
33  class DOMString;
34 }
35 class KJScript;
36 class TQString;
37 class TQConstString;
38 
39 namespace KJS {
40 
41  class UCharReference;
42  class UString;
43 
51  struct KJS_EXPORT UChar {
55  UChar();
56  UChar(char u);
57  UChar(unsigned char u);
63  UChar(unsigned char h , unsigned char l);
68  UChar(unsigned short u);
69  UChar(const UCharReference &c);
73  unsigned char high() const { return uc >> 8; }
77  unsigned char low() const { return uc; }
81  unsigned short unicode() const { return uc; }
82  public:
86  UChar toLower() const;
90  UChar toUpper() const;
94  static UChar null;
95 
96  unsigned short uc;
97  } KJS_PACKED;
98 
99  inline UChar::UChar() { }
100  inline UChar::UChar(unsigned char h , unsigned char l) : uc(h << 8 | l) { }
101  inline UChar::UChar(char u) : uc((unsigned char)u) { }
102  inline UChar::UChar(unsigned char u) : uc(u) { }
103  inline UChar::UChar(unsigned short u) : uc(u) { }
104 
119  class KJS_EXPORT UCharReference {
120  friend class UString;
121  UCharReference(UString *s, unsigned int off) : str(s), offset(off) { }
122  public:
126  UCharReference& operator=(UChar c);
130  UCharReference& operator=(char c) { return operator=(UChar(c)); }
134  unsigned short unicode() const { return ref().uc; }
138  unsigned char low() const { return ref().uc; }
142  unsigned char high() const { return ref().uc >> 8; }
146  UChar toLower() const { return ref().toLower(); }
150  UChar toUpper() const { return ref().toUpper(); }
151  private:
152  // not implemented, can only be constructed from UString
153  UCharReference();
154 
155  UChar& ref() const;
156  UString *str;
157  int offset;
158  };
159 
160  inline UChar::UChar(const UCharReference &c) : uc(c.unicode()) { }
161 
165  class KJS_EXPORT CString {
166  public:
167  CString() : data(0L), length(0) { }
168  CString(const char *c);
169  CString(const char *c, int len);
170  CString(const CString &);
171 
172  ~CString();
173 
174  CString &append(const CString &);
175  CString &operator=(const char *c);
176  CString &operator=(const CString &);
177  CString &operator+=(const CString &c) { return append(c); }
178 
179  int size() const { return length; }
180  const char *c_str() const { return data; }
181  private:
182  char *data;
183  int length;
184  };
185 
189  class KJS_EXPORT UString {
190  friend bool operator==(const UString&, const UString&);
191  friend class UCharReference;
192  friend class Identifier;
193  friend class PropertyMap;
194  friend class PropertyMapHashTableEntry;
198  struct KJS_EXPORT Rep {
199  friend class UString;
200  friend bool operator==(const UString&, const UString&);
201 
202  static Rep *create(UChar *d, int l);
203  void destroy();
204 
205  UChar *data() const { return dat; }
206  int size() const { return len; }
207 
208  unsigned hash() const { if (_hash == 0) _hash = computeHash(dat, len); return _hash; }
209 
210  static unsigned computeHash(const UChar *, int length);
211  static unsigned computeHash(const char *);
212 
213  void ref() { ++rc; }
214  void deref() { if (--rc == 0) destroy(); }
215 
216  UChar *dat;
217  int len;
218  int capacity;
219  int rc;
220  mutable unsigned _hash;
221 
222  enum { capacityForIdentifier = 0x10000000 };
223 
224  static Rep null;
225  static Rep empty;
226  };
227 
228  public:
232  UString();
236  explicit UString(char c);
240  UString(const char *c);
245  UString(const UChar *c, int length);
252  UString(UChar *c, int length, bool copy);
256  UString(const UString &s) { attach(s.rep); }
264  UString(const TQString &);
268  UString(const DOM::DOMString &);
272  UString(const UString &, const UString &);
277  ~UString() { release(); }
278 
282  static UString from(int i);
286  static UString from(unsigned int u);
290  static UString from(long l);
294  static UString from(double d);
295 
299  UString &append(const UString &);
300 
304  CString cstring() const;
312  char *ascii() const;
316  DOM::DOMString string() const;
320  TQString qstring() const;
324  TQConstString qconststring() const;
325 
329  UString &operator=(const char *c);
330  UString &operator=(const UString &);
334  UString &operator+=(const UString &s) { return append(s); }
335 
339  const UChar* data() const { return rep->data(); }
343  bool isNull() const { return (rep == &Rep::null); }
347  bool isEmpty() const { return (!rep->len); }
355  bool is8Bit() const;
359  int size() const { return rep->size(); }
363  UChar operator[](int pos) const;
367  UCharReference operator[](int pos);
368 
377  double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const;
378  double toDouble(bool tolerateTrailingJunk) const;
379  double toDouble() const;
386  unsigned long toULong(bool *ok, bool tolerateEmptyString) const;
387  unsigned long toULong(bool *ok = 0) const;
388 
389  unsigned int toUInt32(bool *ok = 0) const;
390  unsigned int toStrictUInt32(bool *ok = 0) const;
391 
398  unsigned toArrayIndex(bool *ok = 0) const;
399 
403  UString toLower() const;
407  UString toUpper() const;
412  int find(const UString &f, int pos = 0) const;
413  int find(UChar, int pos = 0) const;
419  int rfind(const UString &f, int pos) const;
420  int rfind(UChar, int pos) const;
424  UString substr(int pos = 0, int len = -1) const;
428  static UString null;
429 #ifdef KJS_DEBUG_MEM
430 
433  static void globalClear();
434 #endif
435  private:
436  UString(Rep *r) { attach(r); }
437  void attach(Rep *r);
438  void detach();
439  void release();
440  Rep *rep;
441  };
442 
443  KJS_EXPORT inline bool operator==(const UChar &c1, const UChar &c2) {
444  return (c1.uc == c2.uc);
445  }
446  KJS_EXPORT inline bool operator!=(const UChar& c1, const UChar& c2) {
447  return !KJS::operator==(c1, c2);
448  }
449  KJS_EXPORT bool operator==(const UString& s1, const UString& s2);
450  inline bool operator!=(const UString& s1, const UString& s2) {
451  return !KJS::operator==(s1, s2);
452  }
453  KJS_EXPORT bool operator<(const UString& s1, const UString& s2);
454  KJS_EXPORT bool operator==(const UString& s1, const char *s2);
455  KJS_EXPORT inline bool operator!=(const UString& s1, const char *s2) {
456  return !KJS::operator==(s1, s2);
457  }
458  KJS_EXPORT inline bool operator==(const char *s1, const UString& s2) {
459  return operator==(s2, s1);
460  }
461  KJS_EXPORT inline bool operator!=(const char *s1, const UString& s2) {
462  return !KJS::operator==(s1, s2);
463  }
464  KJS_EXPORT bool operator==(const CString& s1, const CString& s2);
465  KJS_EXPORT inline bool operator!=(const CString& s1, const CString& s2) {
466  return !KJS::operator==(s1, s2);
467  }
468  KJS_EXPORT inline UString operator+(const UString& s1, const UString& s2) {
469  return UString(s1, s2);
470  }
471 
472  KJS_EXPORT int compare(const UString &, const UString &);
473 
474 } // namespace
475 
476 #endif
KJS::UChar::unicode
unsigned short unicode() const
Definition: ustring.h:81
KJS::UString::operator+=
UString & operator+=(const UString &s)
Appends the specified string.
Definition: ustring.h:334
KJS::UString::size
int size() const
Definition: ustring.h:359
KJS::UString::null
static UString null
Static instance of a null string.
Definition: ustring.h:428
KJS::UCharReference::toLower
UChar toLower() const
Definition: ustring.h:146
KJS::CString
8 bit char based string class
Definition: ustring.h:165
KJS::PropertyMapHashTableEntry
A hashtable entry for the PropertyMap.
Definition: property_map.h:57
KJS::UChar::null
static UChar null
A static instance of UChar(0).
Definition: ustring.h:94
KJS::UString::UString
UString(const UString &s)
Copy constructor.
Definition: ustring.h:256
KJS::UChar::high
unsigned char high() const
Definition: ustring.h:73
KJS::UChar::low
unsigned char low() const
Definition: ustring.h:77
KJS::UString
Unicode string class.
Definition: ustring.h:189
KJS::UString::~UString
~UString()
Destructor.
Definition: ustring.h:277
KJS::UChar::UChar
UChar()
Construct a character with uninitialized value.
Definition: ustring.h:99
KJS::UChar
Unicode character.
Definition: ustring.h:51
KJS::UCharReference
Dynamic reference to a string character.
Definition: ustring.h:119
KJS::UString::isNull
bool isNull() const
Definition: ustring.h:343
KJS
Definition: array_instance.h:27
DOM
Definition: ustring.h:32
KJS::UCharReference::toUpper
UChar toUpper() const
Definition: ustring.h:150
KJS::UCharReference::low
unsigned char low() const
Definition: ustring.h:138
KJS::UChar::toUpper
UChar toUpper() const
Definition: ustring.cpp:144
KJS::UChar::toLower
UChar toLower() const
Definition: ustring.cpp:134
KJS::UCharReference::unicode
unsigned short unicode() const
Definition: ustring.h:134
KJS::UCharReference::high
unsigned char high() const
Definition: ustring.h:142
KJS::UCharReference::operator=
UCharReference & operator=(char c)
Same operator as above except the argument that it takes.
Definition: ustring.h:130
KJS::UString::isEmpty
bool isEmpty() const
Definition: ustring.h:347
KJS::Identifier
Represents an Identifier for a Javascript object.
Definition: identifier.h:32
KJS::UString::data
const UChar * data() const
Definition: ustring.h:339
KJS::PropertyMap
Javascript Property Map.
Definition: property_map.h:68

kjs

Skip menu "kjs"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kjs

Skip menu "kjs"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kjs by doxygen 1.8.8
This website is maintained by Timothy Pearson.