ustring.h
// -*- c-basic-offset: 2 -*-
/*
* This file is part of the KDE libraries
* Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
* Copyright (C) 2003 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef _KJS_USTRING_H_
#define _KJS_USTRING_H_
#include "global.h"
namespace DOM {
class DOMString;
}
class KJScript;
class QString;
class QConstString;
namespace KJS {
class UCharReference;
class UString;
struct KJS_EXPORT UChar {
UChar();
UChar(char u);
UChar(unsigned char u);
UChar(unsigned char h , unsigned char l);
UChar(unsigned short u);
UChar(const UCharReference &c);
unsigned char high() const { return uc >> 8; }
unsigned char low() const { return uc; }
unsigned short unicode() const { return uc; }
public:
UChar toLower() const;
UChar toUpper() const;
static UChar null;
unsigned short uc;
} KJS_PACKED;
inline UChar::UChar() { }
inline UChar::UChar(unsigned char h , unsigned char l) : uc(h << 8 | l) { }
inline UChar::UChar(char u) : uc((unsigned char)u) { }
inline UChar::UChar(unsigned char u) : uc(u) { }
inline UChar::UChar(unsigned short u) : uc(u) { }
class KJS_EXPORT UCharReference {
friend class UString;
UCharReference(UString *s, unsigned int off) : str(s), offset(off) { }
public:
UCharReference& operator=(UChar c);
UCharReference& operator=(char c) { return operator=(UChar(c)); }
unsigned short unicode() const { return ref().uc; }
unsigned char low() const { return ref().uc; }
unsigned char high() const { return ref().uc >> 8; }
UChar toLower() const { return ref().toLower(); }
UChar toUpper() const { return ref().toUpper(); }
private:
// not implemented, can only be constructed from UString
UCharReference();
UChar& ref() const;
UString *str;
int offset;
};
inline UChar::UChar(const UCharReference &c) : uc(c.unicode()) { }
class KJS_EXPORT CString {
public:
CString() : data(0L), length(0) { }
CString(const char *c);
CString(const char *c, int len);
CString(const CString &);
~CString();
CString &append(const CString &);
CString &operator=(const char *c);
CString &operator=(const CString &);
CString &operator+=(const CString &c) { return append(c); }
int size() const { return length; }
const char *c_str() const { return data; }
private:
char *data;
int length;
};
class KJS_EXPORT UString {
friend bool operator==(const UString&, const UString&);
friend class UCharReference;
friend class Identifier;
friend class PropertyMap;
friend class PropertyMapHashTableEntry;
struct KJS_EXPORT Rep {
friend class UString;
friend bool operator==(const UString&, const UString&);
static Rep *create(UChar *d, int l);
void destroy();
UChar *data() const { return dat; }
int size() const { return len; }
unsigned hash() const { if (_hash == 0) _hash = computeHash(dat, len); return _hash; }
static unsigned computeHash(const UChar *, int length);
static unsigned computeHash(const char *);
void ref() { ++rc; }
void deref() { if (--rc == 0) destroy(); }
UChar *dat;
int len;
int capacity;
int rc;
mutable unsigned _hash;
enum { capacityForIdentifier = 0x10000000 };
static Rep null;
static Rep empty;
};
public:
UString();
explicit UString(char c);
UString(const char *c);
UString(const UChar *c, int length);
UString(UChar *c, int length, bool copy);
UString(const UString &s) { attach(s.rep); }
UString(const QString &);
UString(const DOM::DOMString &);
UString(const UString &, const UString &);
~UString() { release(); }
static UString from(int i);
static UString from(unsigned int u);
static UString from(long l);
static UString from(double d);
UString &append(const UString &);
CString cstring() const;
char *ascii() const;
DOM::DOMString string() const;
QString qstring() const;
QConstString qconststring() const;
UString &operator=(const char *c);
UString &operator=(const UString &);
UString &operator+=(const UString &s) { return append(s); }
const UChar* data() const { return rep->data(); }
bool isNull() const { return (rep == &Rep::null); }
bool isEmpty() const { return (!rep->len); }
bool is8Bit() const;
int size() const { return rep->size(); }
UChar operator[](int pos) const;
UCharReference operator[](int pos);
double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const;
double toDouble(bool tolerateTrailingJunk) const;
double toDouble() const;
unsigned long toULong(bool *ok, bool tolerateEmptyString) const;
unsigned long toULong(bool *ok = 0) const;
unsigned int toUInt32(bool *ok = 0) const;
unsigned int toStrictUInt32(bool *ok = 0) const;
unsigned toArrayIndex(bool *ok = 0) const;
UString toLower() const;
UString toUpper() const;
int find(const UString &f, int pos = 0) const;
int find(UChar, int pos = 0) const;
int rfind(const UString &f, int pos) const;
int rfind(UChar, int pos) const;
UString substr(int pos = 0, int len = -1) const;
static UString null;
#ifdef KJS_DEBUG_MEM
static void globalClear();
#endif
private:
UString(Rep *r) { attach(r); }
void attach(Rep *r);
void detach();
void release();
Rep *rep;
};
KJS_EXPORT inline bool operator==(const UChar &c1, const UChar &c2) {
return (c1.uc == c2.uc);
}
KJS_EXPORT inline bool operator!=(const UChar& c1, const UChar& c2) {
return !KJS::operator==(c1, c2);
}
KJS_EXPORT bool operator==(const UString& s1, const UString& s2);
inline bool operator!=(const UString& s1, const UString& s2) {
return !KJS::operator==(s1, s2);
}
KJS_EXPORT bool operator<(const UString& s1, const UString& s2);
KJS_EXPORT bool operator==(const UString& s1, const char *s2);
KJS_EXPORT inline bool operator!=(const UString& s1, const char *s2) {
return !KJS::operator==(s1, s2);
}
KJS_EXPORT inline bool operator==(const char *s1, const UString& s2) {
return operator==(s2, s1);
}
KJS_EXPORT inline bool operator!=(const char *s1, const UString& s2) {
return !KJS::operator==(s1, s2);
}
KJS_EXPORT bool operator==(const CString& s1, const CString& s2);
KJS_EXPORT inline bool operator!=(const CString& s1, const CString& s2) {
return !KJS::operator==(s1, s2);
}
KJS_EXPORT inline UString operator+(const UString& s1, const UString& s2) {
return UString(s1, s2);
}
KJS_EXPORT int compare(const UString &, const UString &);
} // namespace
#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:58
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::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:145
KJS::UChar::toLower
UChar toLower() const
Definition: ustring.cpp:135
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:69

KDE Home | KDE Accessibility Home | Description of Access Keys