Faith::String Class Reference

#include <faith/string.h>

List of all members.

Public Member Functions

 String ()
 String (const String &s)
 String (const std::string &s)
 String (const char *s)
 ~String ()
bool isNull () const
bool isEmpty () const
bool operator== (const String &other) const
int compare (const String &text) const
bool operator< (const ::Faith::String &b) const
bool operator> (const ::Faith::String &b) const
Stringoperator= (const String &set)
Stringoperator= (const Char &set)
Stringoperator+= (const String &append)
Stringoperator+= (char c)
Stringoperator+= (const Char &c)
Faith::String operator+ (const char *b)
Char operator[] (int at) const
CharRef operator[] (int at)
int find (const String &other, int start=0) const
int find (const Char &other, int start=0) const
int find (char other, int start=0) const
int find (bool(Char::*test)() const, int start=0) const
int find (bool uninverted, bool(Char::*test)() const, int start=0) const
String mid (int start, int length=-1) const
void insert (int offset, const String &str)
void replace (int start, int len, const String &str)
void replace (const String &other, const String &replace, int start=0)
void replace (const Char &other, const String &replace, int start=0)
void replace (char other, const String &replace, int start=0)
int length () const
void setLocal8Bit (const CString &str)
void setLocal8Bit (const char *str)
void setUtf8 (const CString &str)
void setUtf8 (const char *str)
void setLatin1 (const CString &str)
void setLatin1 (const char *str)
CString exportTo (const CString &codepage) const
CString local8Bit () const
CString latin1 () const
Faith::String left (int n) const
void setCharAt (int offset, const Char &ch)
int toInt (int base=10) const
bool beginsWith (const String &str) const
String simplifiedWhiteSpace () const
String removedWhiteSpace () const

Static Public Member Functions

static String fromLocal8Bit (const char *str)
static String fromLocal8Bit (const CString &)
static String fromLatin1 (const char *)
static String fromLatin1 (const CString &)
static String fromUtf8 (const char *str)
static String number (int n, int base=10)
static String number (long n, int base=10)
static String number (double n, char format='g', int precision=6)


Detailed Description

String represents a Unicode string. Internally, there's copy-on-write, so copying this object is fast

Internally, this class stores the string in UTF-16, which permits storing 32-bit unicode values. That means that sometimes a single character may occupy more than one byte. You might thing I'm getting UTF 8 and UTF-16 confused, but I'm not, this paragraph is accurate.

Since no other component of OSes these days support 32 Bit unicode characters, this feature may be completely ignored, safely.


Constructor & Destructor Documentation

Faith::String::String (  ) 

construct a null string

Faith::String::String ( const String s  ) 

copy this other string

Faith::String::String ( const std::string &  s  ) 

copy this other string

Faith::String::String ( const char *  s  ) 

copy this other string, latin1 encoded. Be aware that it's latin1, so you can't store unicode characters in it

Faith::String::~String (  ) 


Member Function Documentation

bool Faith::String::beginsWith ( const String str  )  const

Returns:
true if this begins with str.
same as: find(str) == 0

int Faith::String::compare ( const String text  )  const

Returns:
-1 if text is less than this string, bitwise

+1 if text is more than this string, bitwise

0 if text is the same as this string

CString Faith::String::exportTo ( const CString codepage  )  const

convert this string to a string with the codepage of codepage.

Codepage may equal something like utf8 or local8Bit

int Faith::String::find ( bool  uninverted,
bool(Char::*)() const   test,
int  start = 0 
) const

the same as the above function, except that if uninverted is false, the behavior of the test is inverted (therefor, if the test function fails, a match is made at that point)

int Faith::String::find ( bool(Char::*)() const   test,
int  start = 0 
) const [inline]

locate the first occurance of a character for which test returns true.

This function exists because I needed to use Regular Expressions before implementing them :)

The next function also permits inverting the behavior of the test.

  find(&Char::isSpace)
 

Returns:
the position of it, or -1 if not found

int Faith::String::find ( char  other,
int  start = 0 
) const

locate the first occurance of other in the string, starting at the position of start.

Returns:
the position of it, or -1 if not found

int Faith::String::find ( const Char other,
int  start = 0 
) const

locate the first occurance of other in the string, starting at the position of start.

Returns:
the position of it, or -1 if not found

int Faith::String::find ( const String other,
int  start = 0 
) const

locate the first occurance of other in the string, starting at the position of start.

Returns:
the position of it, or -1 if not found

static String Faith::String::fromLatin1 ( const CString  )  [static]

static String Faith::String::fromLatin1 ( const char *   )  [static]

Returns:
the Unicode string as a result of converting the given argument to unicode, assuming the argument is encoded as latin1, which is probable.

static String Faith::String::fromLocal8Bit ( const CString  )  [static]

same as above

static String Faith::String::fromLocal8Bit ( const char *  str  )  [inline, static]

Returns:
the Unicode string as a result of converting the given argument to unicode, using the local system's 8 bit format. This is usually the same as fromLatin1, but it might be the same as fromUtf8

static String Faith::String::fromUtf8 ( const char *  str  )  [inline, static]

void Faith::String::insert ( int  offset,
const String str 
)

inserts string into the string at offset, if offset is larger than possible, it appends it

bool Faith::String::isEmpty (  )  const [inline]

Returns:
true the length of the string is zero
See also:
isNull

bool Faith::String::isNull (  )  const

Returns:
if the string is considered null.
an empty string is not necessarily null, but a null string is always empty

CString Faith::String::latin1 (  )  const

same as exportTo("ISO8859-1")

Faith::String Faith::String::left ( int  n  )  const

Returns:
the first n characters from the string

int Faith::String::length (  )  const

Returns:
the number of characters in this string

CString Faith::String::local8Bit (  )  const

same as latin1() usually

String Faith::String::mid ( int  start,
int  length = -1 
) const

Returns:
the part of this string starting at start, and having a length of length. If length is negative,

the rest of the string. If this string is Null,

a null string.

static String Faith::String::number ( double  n,
char  format = 'g',
int  precision = 6 
) [static]

creates a string of the given number, the format and precision parameters are exactly the same as printf

static String Faith::String::number ( long  n,
int  base = 10 
) [inline, static]

static String Faith::String::number ( int  n,
int  base = 10 
) [static]

Faith::String Faith::String::operator+ ( const char *  b  )  [inline]

String& Faith::String::operator+= ( const Char c  ) 

append the given character to me

appending a null char to a null string results in a null string

String& Faith::String::operator+= ( char  c  ) 

append the given character to me

appending a null char to a null string results in a null string

String& Faith::String::operator+= ( const String append  ) 

append the given string to me

appending a null string to a null string results in a null string

bool Faith::String::operator< ( const ::Faith::String b  )  const [inline]

String& Faith::String::operator= ( const Char set  ) 

String& Faith::String::operator= ( const String set  ) 

bool Faith::String::operator== ( const String other  )  const

Compare this string with other, whether they are the same.

Note:
This will return true if one string is null, while the other has zero length. This is different than with Qt.

bool Faith::String::operator> ( const ::Faith::String b  )  const [inline]

CharRef Faith::String::operator[] ( int  at  ) 

returns the character at the given offset.

Has undefined behavior if there isn't a character there.

Note:
this is the non-const version of this function to permit changing of the character like so: { string[x] = 'f'; }, changing the character after changing the string has undefined behavior.

Char Faith::String::operator[] ( int  at  )  const

returns the character at the given offset.

Has undefined behavior if there isn't a character there

String Faith::String::removedWhiteSpace (  )  const

Returns:
the string with all whitespace removed

void Faith::String::replace ( char  other,
const String replace,
int  start = 0 
)

locate all occurances of other in the string, starting at the position of start, replace it with replace

Returns:
the position of it, or -1 if not found

void Faith::String::replace ( const Char other,
const String replace,
int  start = 0 
)

locate all occurances of other in the string, starting at the position of start, replace it with replace

Returns:
the position of it, or -1 if not found

void Faith::String::replace ( const String other,
const String replace,
int  start = 0 
)

locate all occurances of other in the string, starting at the position of start, replace it with replace

Returns:
the position of it, or -1 if not found

void Faith::String::replace ( int  start,
int  len,
const String str 
)

removes the text from start and len characters forward, replacing it with the text str

void Faith::String::setCharAt ( int  offset,
const Char ch 
)

void Faith::String::setLatin1 ( const char *  str  ) 

void Faith::String::setLatin1 ( const CString str  ) 

void Faith::String::setLocal8Bit ( const char *  str  ) 

void Faith::String::setLocal8Bit ( const CString str  ) 

void Faith::String::setUtf8 ( const char *  str  ) 

void Faith::String::setUtf8 ( const CString str  ) 

String Faith::String::simplifiedWhiteSpace (  )  const

Returns:
the string with the leading and ending white space removed, and all adjacent sets of whitespace reduced to one space

int Faith::String::toInt ( int  base = 10  )  const


The documentation for this class was generated from the following file:
Generated on Fri Sep 1 00:23:09 2006 for Faith by  doxygen 1.4.7