# kjs Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# KJS::UString Class Reference

Unicode string class. More...

`#include <ustring.h>`

Collaboration diagram for KJS::UString:

[legend]
List of all members.

## Public Member Functions

| UString ()
| Constructs a null string.
| UString (char c)
| Constructs a string from the single character c.
| UString (const char *c)
| Constructs a string from a classical zero determined char string.
| UString (const UChar *c, int length)
| Constructs a string from an array of Unicode characters of the specified length.
| UString (UChar *c, int length, bool copy)
| If copy is false a shallow copy of the string will be created.
| UString (const UString &)
| Copy constructor.
| UString (const QString &)
| Convenience declaration only ! You'll be on your own to write the implementation for a construction from QString.
| UString (const DOM::DOMString &)
| Convenience declaration only ! See UString(const QString&).
| ~UString ()
| Destructor.
UString & | append (const UString &)
| Append another string.
CString | cstring () const
char * | ascii () const
| Convert the Unicode string to plain ASCII chars chopping of any higher bytes.
DOM::DOMString | string () const
QString | qstring () const
QConstString | qconststring () const
UString & | operator= (const char *c)
| Assignment operator.
UString & | operator= (const UString &)
| Assignment operator.
UString & | operator+= (const UString &s)
| Appends the specified string.
const UChar * | data () const
bool | isNull () const
bool | isEmpty () const
bool | is8Bit () const
| Use this if you want to make sure that this string is a plain ASCII string.
int | size () const
UChar | operator[] (int pos) const
| Const character at specified position.
UCharReference | operator[] (int pos)
| Writable reference to character at specified position.
double | toDouble (bool tolerant=false) const
| Attempts an conversion to a number.
unsigned long | toULong (bool *ok=0L) const
| Attempts an conversion to an unsigned long integer.
UString | toLower () const
| Returns this string converted to lower case characters.
UString | toUpper () const
| Returns this string converted to upper case characters.
int | find (const UString &f, int pos=0) const
int | rfind (const UString &f, int pos) const
UString | substr (int pos=0, int len=-1) const

## Static Public Member Functions

UString | from (int i)
| Constructs a string from an int.
UString | from (unsigned int u)
| Constructs a string from an unsigned int.
UString | from (double d)
| Constructs a string from a double.

## Static Public Attributes

UString | null
| Static instance of a null string.

## Friends

class | UCharReference
bool | operator== (const UString &, const UString &)

## Detailed Description

Unicode string class.

Definition at line 187 of file ustring.h.

## Constructor & Destructor Documentation

UString::UString | ( |  | ) |

| Constructs a null string. Definition at line 182 of file ustring.cpp. References null, and rep. Referenced by from(), and substr().

UString::UString | ( | char | c | ) |

| Constructs a string from the single character c. Definition at line 188 of file ustring.cpp.

UString::UString | ( | const char * | c | ) |

| Constructs a string from a classical zero determined char string. Definition at line 195 of file ustring.cpp. References operator=().

UString::UString | ( | const UChar * | c,
|  | int | length
| ) |

| Constructs a string from an array of Unicode characters of the specified length. Definition at line 201 of file ustring.cpp.

UString::UString | ( | UChar * | c,
|  | int | length,
|  | bool | copy
| ) |

| If copy is false a shallow copy of the string will be created. That means that the data will NOT be copied and you'll have to guarantee that it doesn't get deleted during the lifetime of the UString object. Behaviour defaults to a deep copy if copy is true. Definition at line 208 of file ustring.cpp. References KStdAccel::copy().

UString::UString | ( | const UString & |  | ) |

| Copy constructor. Makes a shallow copy only. Definition at line 219 of file ustring.cpp. References rep.

KJS::UString::UString | ( | const QString & |  | ) |

| Convenience declaration only ! You'll be on your own to write the implementation for a construction from QString. Note: feel free to contact me if you want to see a dummy header for your favourite FooString class here !

KJS::UString::UString | ( | const DOM::DOMString & |  | ) |

| Convenience declaration only ! See UString(const QString&).

UString::~UString | ( |  | ) |

| Destructor. If this handle was the only one holding a reference to the string the data will be freed. Definition at line 224 of file ustring.cpp.

## Member Function Documentation

UString UString::from | ( | int | i | ) | `[static]`

| Constructs a string from an int. Definition at line 229 of file ustring.cpp. References UString().

UString UString::from | ( | unsigned int | u | ) | `[static]`

| Constructs a string from an unsigned int. Definition at line 237 of file ustring.cpp. References UString().

UString UString::from | ( | double | d | ) | `[static]`

| Constructs a string from a double. Definition at line 245 of file ustring.cpp. References UString().

UString & UString::append | ( | const UString & |  | ) |

| Append another string. Definition at line 270 of file ustring.cpp. References data(), and size(). Referenced by operator+=().

CString UString::cstring | ( |  | ) | const

Returns:
  The string converted to the 8-bit string type CString().

Definition at line 282 of file ustring.cpp.

References ascii().

Referenced by toDouble().

char * UString::ascii | ( |  | ) | const

Convert the Unicode string to plain ASCII chars chopping of any higher bytes.

This method should only be used for *debugging* purposes as it is neither Unicode safe nor free from side effects. In order not to waste any memory the char buffer is static and *shared* by all UString instances.

Definition at line 287 of file ustring.cpp.

References data(), KJS::UChar::low(), and size().

Referenced by cstring().

DOM::DOMString KJS::UString::string | ( |  | ) | const

See also:
  UString(const QString&).

QString KJS::UString::qstring | ( |  | ) | const

See also:
  UString(const QString&).

QConstString KJS::UString::qconststring | ( |  | ) | const

See also:
  UString(const QString&).

UString & UString::operator= | ( | const char * | c | ) |

| Assignment operator. Definition at line 308 of file ustring.cpp. References KJS::UChar::uc. Referenced by UString().

UString & UString::operator= | ( | const UString & |  | ) |

| Assignment operator. Definition at line 320 of file ustring.cpp. References rep.

UString & UString::operator+= | ( | const UString & | s | ) |

| Appends the specified string. Definition at line 329 of file ustring.cpp. References append().

const UChar* KJS::UString::data | ( |  | ) | const`[inline]`

Returns:
  A pointer to the internal Unicode data.

Definition at line 315 of file ustring.h.

Referenced by append(), ascii(), find(), KJS::Lookup::find(), KJS::Lookup::findEntry(), is8Bit(), operator[](), rfind(), and substr().

bool KJS::UString::isNull | ( |  | ) | const`[inline]`

Returns:
  True if null.

Definition at line 319 of file ustring.h.

Referenced by find(), rfind(), and substr().

bool KJS::UString::isEmpty | ( |  | ) | const`[inline]`

Returns:
  True if null or zero length.

Definition at line 323 of file ustring.h.

Referenced by KJS::LabelStack::contains(), and KJS::LabelStack::push().

bool UString::is8Bit | ( |  | ) | const

Use this if you want to make sure that this string is a plain ASCII string.

For example, if you don't want to lose any information when using cstring() or ascii().

Returns:
  True if the string doesn't contain any non-ASCII characters.

Definition at line 334 of file ustring.cpp.

References data(), size(), and KJS::UChar::uc.

Referenced by toDouble().

int KJS::UString::size | ( |  | ) | const`[inline]`

Returns:
  The length of the string.

Definition at line 335 of file ustring.h.

Referenced by append(), ascii(), find(), KJS::Lookup::find(), KJS::Lookup::findEntry(), is8Bit(), operator[](), rfind(), substr(), toLower(), and toUpper().

UChar UString::operator[] | ( | int | pos | ) | const

| Const character at specified position. Definition at line 344 of file ustring.cpp. References data(), and size().

UCharReference UString::operator[] | ( | int | pos | ) |

| Writable reference to character at specified position. Definition at line 352 of file ustring.cpp.

double UString::toDouble | ( | bool | tolerant = false | ) | const

Attempts an conversion to a number.

Apart from floating point numbers, the algorithm will recognize hexadecimal representations (as indicated by a 0x or 0X prefix) and +/- Infinity. Returns NaN if the conversion failed.

Parameters:

  tolerant | if true, toDouble can tolerate garbage after the number.

Definition at line 358 of file ustring.cpp.

References KJS::CString::c_str(), cstring(), KStdAccel::end(), and is8Bit().

Referenced by toULong().

unsigned long UString::toULong | ( | bool * | ok = 0L | ) | const

| Attempts an conversion to an unsigned long integer. ok will be set according to the success. Definition at line 420 of file ustring.cpp. References toDouble().

UString UString::toLower | ( |  | ) | const

| Returns this string converted to lower case characters. Definition at line 436 of file ustring.cpp. References size().

UString UString::toUpper | ( |  | ) | const

| Returns this string converted to upper case characters. Definition at line 444 of file ustring.cpp. References size().

int UString::find | ( | const UString & | f,
|  | int | pos = 0
| ) | const

Returns:
  Position of first occurence of f starting at position pos. -1 if the search was not successful.

Definition at line 452 of file ustring.cpp.

References data(), KStdAccel::end(), isNull(), and size().

int UString::rfind | ( | const UString & | f,
|  | int | pos
| ) | const

Returns:
  Position of first occurence of f searching backwards from position pos. -1 if the search was not successful.

Definition at line 467 of file ustring.cpp.

References data(), isNull(), and size().

UString UString::substr | ( | int | pos = 0,
|  | int | len = -1
| ) | const

Returns:
  The sub string starting at position pos and length len.

Definition at line 482 of file ustring.cpp.

References data(), isNull(), size(), and UString().

## Member Data Documentation

UString UString::null `[static]`

| Static instance of a null string. Definition at line 123 of file ustring.cpp. Referenced by UString().

The documentation for this class was generated from the following files:

- ustring.h
- ustring.cpp

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:09:36 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001