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

kjs

  • kjs
ustring.h
1 // -*- c-basic-offset: 2 -*-
2 /*
3  * This file is part of the KDE libraries
4  * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
5  * Copyright (C) 2003 Apple Computer, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #ifndef _KJS_USTRING_H_
25 #define _KJS_USTRING_H_
26 
27 #include <tqstring.h>
28 #include "global.h"
29 
33 namespace DOM {
34  class DOMString;
35 }
36 class KJScript;
37 class TQString;
38 class TQConstString;
39 
40 namespace KJS {
41 
42  class UCharReference;
43  class UString;
44 
52  struct KJS_EXPORT UChar {
56  UChar();
57  UChar(char u);
58  UChar(unsigned char u);
64  UChar(unsigned char h , unsigned char l);
69  UChar(unsigned short u);
70  UChar(const UCharReference &c);
74  unsigned char high() const { return uc >> 8; }
78  unsigned char low() const { return uc; }
82  unsigned short unicode() const { return uc; }
83  public:
87  UChar toLower() const;
91  UChar toUpper() const;
95  static UChar null;
96 
97  unsigned short uc;
98  } KJS_PACKED;
99 
100  inline UChar::UChar() { }
101  inline UChar::UChar(unsigned char h , unsigned char l) : uc(h << 8 | l) { }
102  inline UChar::UChar(char u) : uc((unsigned char)u) { }
103  inline UChar::UChar(unsigned char u) : uc(u) { }
104  inline UChar::UChar(unsigned short u) : uc(u) { }
105 
120  class KJS_EXPORT UCharReference {
121  friend class UString;
122  UCharReference(UString *s, unsigned int off) : str(s), offset(off) { }
123  public:
127  UCharReference& operator=(UChar c);
131  UCharReference& operator=(char c) { return operator=(UChar(c)); }
135  unsigned short unicode() const { return ref().uc; }
139  unsigned char low() const { return ref().uc; }
143  unsigned char high() const { return ref().uc >> 8; }
147  UChar toLower() const { return ref().toLower(); }
151  UChar toUpper() const { return ref().toUpper(); }
152  private:
153  // not implemented, can only be constructed from UString
154  UCharReference();
155 
156  UChar& ref() const;
157  UString *str;
158  int offset;
159  };
160 
161  inline UChar::UChar(const UCharReference &c) : uc(c.unicode()) { }
162 
166  class KJS_EXPORT CString {
167  public:
168  CString() : data(0L), length(0) { }
169  CString(const char *c);
170  CString(const char *c, int len);
171  CString(const CString &);
172 
173  ~CString();
174 
175  CString &append(const CString &);
176  CString &operator=(const char *c);
177  CString &operator=(const CString &);
178  CString &operator+=(const CString &c) { return append(c); }
179 
180  int size() const { return length; }
181  const char *c_str() const { return data; }
182  private:
183  char *data;
184  int length;
185  };
186 
190  class KJS_EXPORT UString {
191  friend bool operator==(const UString&, const UString&);
192  friend class UCharReference;
193  friend class Identifier;
194  friend class PropertyMap;
195  friend class PropertyMapHashTableEntry;
199  struct KJS_EXPORT Rep {
200  friend class UString;
201  friend bool operator==(const UString&, const UString&);
202 
203  static Rep *create(UChar *d, int l);
204  void destroy();
205 
206  UChar *data() const { return dat; }
207  int size() const { return len; }
208 
209  unsigned hash() const { if (_hash == 0) _hash = computeHash(dat, len); return _hash; }
210 
211  static unsigned computeHash(const UChar *, int length);
212  static unsigned computeHash(const char *);
213 
214  void ref() { ++rc; }
215  void deref() { if (--rc == 0) destroy(); }
216 
217  UChar *dat;
218  int len;
219  int capacity;
220  int rc;
221  mutable unsigned _hash;
222 
223  enum { capacityForIdentifier = 0x10000000 };
224 
225  static Rep null;
226  static Rep empty;
227  };
228 
229  public:
233  UString();
237  explicit UString(char c);
241  UString(const char *c);
246  UString(const UChar *c, int length);
253  UString(UChar *c, int length, bool copy);
257  UString(const UString &s) { attach(s.rep); }
265  UString(const TQString &);
269  UString(const DOM::DOMString &);
273  UString(const UString &, const UString &);
278  ~UString() { release(); }
279 
283  static UString from(int i);
287  static UString from(unsigned int u);
291  static UString from(long l);
295  static UString from(double d);
296 
300  UString &append(const UString &);
301 
305  CString cstring() const;
313  char *ascii() const;
317  DOM::DOMString string() const;
321  TQString qstring() const;
325  TQConstString qconststring() const;
326 
330  UString &operator=(const char *c);
331  UString &operator=(const UString &);
335  UString &operator+=(const UString &s) { return append(s); }
336 
340  const UChar* data() const { return rep->data(); }
344  bool isNull() const { return (rep == &Rep::null); }
348  bool isEmpty() const { return (!rep->len); }
356  bool is8Bit() const;
360  int size() const { return rep->size(); }
364  UChar operator[](int pos) const;
368  UCharReference operator[](int pos);
369 
378  double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const;
379  double toDouble(bool tolerateTrailingJunk) const;
380  double toDouble() const;
387  unsigned long toULong(bool *ok, bool tolerateEmptyString) const;
388  unsigned long toULong(bool *ok = 0) const;
389 
390  unsigned int toUInt32(bool *ok = 0) const;
391  unsigned int toStrictUInt32(bool *ok = 0) const;
392 
399  unsigned toArrayIndex(bool *ok = 0) const;
400 
404  UString toLower() const;
408  UString toUpper() const;
413  int find(const UString &f, int pos = 0) const;
414  int find(UChar, int pos = 0) const;
420  int rfind(const UString &f, int pos) const;
421  int rfind(UChar, int pos) const;
425  UString substr(int pos = 0, int len = -1) const;
429  static UString null;
430 #ifdef KJS_DEBUG_MEM
431 
434  static void globalClear();
435 #endif
436  private:
437  UString(Rep *r) { attach(r); }
438  void attach(Rep *r);
439  void detach();
440  void release();
441  Rep *rep;
442  };
443 
444  KJS_EXPORT inline bool operator==(const UChar &c1, const UChar &c2) {
445  return (c1.uc == c2.uc);
446  }
447  KJS_EXPORT inline bool operator!=(const UChar& c1, const UChar& c2) {
448  return !KJS::operator==(c1, c2);
449  }
450  KJS_EXPORT bool operator==(const UString& s1, const UString& s2);
451  inline bool operator!=(const UString& s1, const UString& s2) {
452  return !KJS::operator==(s1, s2);
453  }
454  KJS_EXPORT bool operator<(const UString& s1, const UString& s2);
455  KJS_EXPORT bool operator==(const UString& s1, const char *s2);
456  KJS_EXPORT inline bool operator!=(const UString& s1, const char *s2) {
457  return !KJS::operator==(s1, s2);
458  }
459  KJS_EXPORT inline bool operator==(const char *s1, const UString& s2) {
460  return operator==(s2, s1);
461  }
462  KJS_EXPORT inline bool operator!=(const char *s1, const UString& s2) {
463  return !KJS::operator==(s1, s2);
464  }
465  KJS_EXPORT bool operator==(const CString& s1, const CString& s2);
466  KJS_EXPORT inline bool operator!=(const CString& s1, const CString& s2) {
467  return !KJS::operator==(s1, s2);
468  }
469  KJS_EXPORT inline UString operator+(const UString& s1, const UString& s2) {
470  return UString(s1, s2);
471  }
472 
473  KJS_EXPORT int compare(const UString &, const UString &);
474 
475 } // namespace
476 
477 #endif
KJS::UCharReference::unicode
unsigned short unicode() const
Definition: ustring.h:135
KJS::UString::operator+=
UString & operator+=(const UString &s)
Appends the specified string.
Definition: ustring.h:335
KJS::UChar::high
unsigned char high() const
Definition: ustring.h:74
KJS::UString::null
static UString null
Static instance of a null string.
Definition: ustring.h:429
KJS::CString
8 bit char based string class
Definition: ustring.h:166
KJS::PropertyMapHashTableEntry
A hashtable entry for the PropertyMap.
Definition: property_map.h:58
KJS::UChar::null
static UChar null
A static instance of UChar(0).
Definition: ustring.h:95
KJS::UString::UString
UString(const UString &s)
Copy constructor.
Definition: ustring.h:257
KJS::UCharReference::toUpper
UChar toUpper() const
Definition: ustring.h:151
KJS::UChar::toUpper
UChar toUpper() const
Definition: ustring.cpp:145
KJS::UString::data
const UChar * data() const
Definition: ustring.h:340
KJS::UString
Unicode string class.
Definition: ustring.h:190
KJS::UString::~UString
~UString()
Destructor.
Definition: ustring.h:278
KJS::UChar::UChar
UChar()
Construct a character with uninitialized value.
Definition: ustring.h:100
KJS::UChar
Unicode character.
Definition: ustring.h:52
KJS::UCharReference
Dynamic reference to a string character.
Definition: ustring.h:120
KJS
Definition: array_instance.h:28
KJS::UCharReference::low
unsigned char low() const
Definition: ustring.h:139
DOM
Definition: ustring.h:33
KJS::UString::isNull
bool isNull() const
Definition: ustring.h:344
KJS::UChar::toLower
UChar toLower() const
Definition: ustring.cpp:135
KJS::UCharReference::toLower
UChar toLower() const
Definition: ustring.h:147
KJS::UString::isEmpty
bool isEmpty() const
Definition: ustring.h:348
KJS::UChar::unicode
unsigned short unicode() const
Definition: ustring.h:82
KJS::UChar::low
unsigned char low() const
Definition: ustring.h:78
KJS::UCharReference::operator=
UCharReference & operator=(char c)
Same operator as above except the argument that it takes.
Definition: ustring.h:131
KJS::UCharReference::high
unsigned char high() const
Definition: ustring.h:143
KJS::Identifier
Represents an Identifier for a Javascript object.
Definition: identifier.h:32
KJS::PropertyMap
Javascript Property Map.
Definition: property_map.h:69
KJS::UString::size
int size() const
Definition: ustring.h:360

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
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kjs by doxygen 1.8.13
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |