NString Class Reference

NString class implements an easy to use, std::string based, string manipulation class. More...

List of all members.

Public Member Functions

 NString (void)
 Constructs an empty NString object.
 NString (const char *str)
 Constructs a NString object setting it to str.
 NString (const NString &str)
 Constructs a NString object setting it to str.
 ~NString (void)
 Destroys a NString object releasing the used memory.
NStringset (const char *str)
 Sets the string of the current object.
NStringset (const NString &str)
 Sets the string of the current object.
const char * toChar () const
 Converts the string stored by the current object to a char pointer.
unsigned int length () const
 The current lenght of the string.
bool isNull () const
 Checks whether the current string is null (empty).
NStringappend (const char *str, nuint32 bytes)
 Appends a string to the current object.
NStringappend (const char *str)
 Appends a string to the current object.
NStringappend (const NString &str)
 Appends a string to the current object.
NStringappend (char c)
 Appends a char to the current object.
NStringinsert (nuint32 pos, nuint32 size, const NString str)
 Inserts a string at a given position in the string.
NStringinsert (nuint32 pos, const NString str)
 Inserts a string at a given position in the string.
bool compare (nuint32 pos, nuint32 size, const NString &str) const
 Compare the string.
bool compare (nuint32 pos, const NString &str) const
 Compare the string.
bool compare (nuint32 pos, nuint32 size, const NString &str, nuint32 str_pos) const
 Compare the string.
NString substr (nuint32 pos, nuint32 size) const
 Gets a substring.
nint32 find (const NString &str, nuint32 pos, nuint32 ocur) const
 Finds a substring starting from a given position.
nint32 find (const NString &str, nuint32 pos) const
 Finds a substring starting from a given position.
nint32 find (const NString &str) const
 Finds a substring.
NStringreplace_first (const NString &src, const NString &dest)
 Replaces the first ocurrence of 'src' with 'dest'.
NStringreplace (const NString &src, const NString &dest)
 Replaces part of the string.
NStringreplace (const NString &src, const NString &dest, nuint32 ocur)
 Replaces part of the string.
NList< NStringsplit (const NString &substr)
 Splits the string.
NString operator+ (const char *str)
 Appends a string to the current object.
NString operator+ (const NString &str)
 Appends a string to the current object.
NString operator+ (char c)
 Appends a char to the current object.
NStringoperator+= (const char *str)
 Appends a string to the current object.
NStringoperator+= (const NString &str)
 Appends a string to the current object.
NStringoperator+= (char c)
 Appends a char to the current object.
char operator[] (unsigned int index) const
 Access the char at position index.
bool operator== (const NString &str) const
 Checks whether the current object is equals str.
bool operator!= (const NString &str) const
 Checks whether the current object is not equal to str.
bool operator> (const NString &str) const
 Checks whether the current object is lexically greater than str.
bool operator< (const NString &str) const
 Checks whether the current object is lexically less than str.
bool operator>= (const NString &str) const
 Checks whether the current object is lexically greater than or equals str.
bool operator<= (const NString &str) const
 Checks whether the current object is lexically less than or equals str.
NStringoperator= (const NString &str)
 Sets the string of the current object.
NStringarg (const char *fmt,...)
 Provides formatted output to a NString object.

Static Public Member Functions

static NString number (int num)
 Converts a given number to a NString.
static NString number (nint64 num)
 Converts a given number to a NString.

Static Public Attributes

static const nint32 NOT_FOUND = -1


Detailed Description

NString class implements an easy to use, std::string based, string manipulation class.
Examples:

clientapp.cpp, ex_ndatastream.cpp, ex_ndir.cpp, ex_nfileinfo.cpp, ex_ngetopt.cpp, ex_nregex.cpp, ex_nskiplist.cpp, ex_nstring.cpp, ex_nxmlwrite.cpp, ex_skip_vs_sorted.cpp, hashapp.cpp, nsqlapp.cpp, and xmlreader.h.

Definition at line 63 of file nstring.h.


Constructor & Destructor Documentation

NString ( const char *  str  ) 

Constructs a NString object setting it to str.

Parameters:
str A pointer to a NULL terminated C++ char string

Definition at line 40 of file nstring.cpp.

NString ( const NString str  ) 

Constructs a NString object setting it to str.

Parameters:
str A NString object with the string

Definition at line 49 of file nstring.cpp.


Member Function Documentation

NString number ( int  num  )  [static]

Converts a given number to a NString.

Parameters:
num A 32 bit integer to be converted
Returns:
A string with the converted number
Examples:
ex_nskiplist.cpp, ex_nstring.cpp, and ex_skip_vs_sorted.cpp.

Definition at line 174 of file nstring.cpp.

References NString().

Referenced by NTcpSocket::connectToHost(), NTcpSocket::execListen(), NXmlError::getLastError(), NHostAddress::setAddress(), NHostAddress::toString(), and NTcpSocket::waitForConnected().

NString number ( nint64  num  )  [static]

Converts a given number to a NString.

Parameters:
num A 64 bit integer to be converted
Returns:
A string with the converted number

Definition at line 188 of file nstring.cpp.

References NString().

NString & set ( const char *  str  ) 

Sets the string of the current object.

Parameters:
str A pointer to a NULL terminated C++ char string
Returns:
A reference to this

Definition at line 131 of file nstring.cpp.

Referenced by NXmlWriter::dump(), and NDataStream::toString().

NString & set ( const NString str  ) 

Sets the string of the current object.

Parameters:
str A NString object with the string
Returns:
A reference to this

Definition at line 165 of file nstring.cpp.

References toChar().

const char * toChar ( void   )  const

Converts the string stored by the current object to a char pointer.

Returns:
A pointer to a null terminated char string.
Examples:
clientapp.cpp, ex_ngetopt.cpp, and nsqlapp.cpp.

Definition at line 169 of file nstring.cpp.

Referenced by NXmlNode::addProperty(), append(), NDataStream::append(), NShaHash::calculate(), NSha1Hash::calculate(), NMd5Hash::calculate(), NMd4Hash::calculate(), NMd2Hash::calculate(), compare(), NTcpSocket::connectToHost(), NMySql::connectToHost(), NMySql::execSql(), NFileInfo::exists(), NFile::exists(), NXmlNode::getProperty(), NFileInfo::groupExecute(), NFileInfo::groupRead(), NFileInfo::groupWrite(), NXmlNode::hasProperty(), NAbstractHash::init(), insert(), NFileInfo::isDevice(), NFileInfo::isDir(), NFileInfo::isFifo(), NFileInfo::isFile(), NFileInfo::isLink(), NRegex::match(), NDir::NDir(), NTime::now(), NRegex::NRegex(), NFile::open(), operator<(), operator<=(), operator>(), operator>=(), NFileInfo::othersExecute(), NFileInfo::othersRead(), NFileInfo::othersWrite(), NFileInfo::ownerExecute(), NFileInfo::ownerRead(), NFileInfo::ownerWrite(), NXmlSchemaParser::parse(), NXmlParser::parse(), NBaseOutput::print(), NBaseOutput::println(), NHostAddress::resolve(), set(), NDataStream::set(), NXmlNode::setData(), NXmlNode::setName(), and NDate::today().

unsigned int length ( void   )  const

The current lenght of the string.

Returns:
The lenght of the string
Examples:
ex_nstring.cpp.

Definition at line 202 of file nstring.cpp.

Referenced by NShaHash::calculate(), NSha1Hash::calculate(), NMd5Hash::calculate(), NMd4Hash::calculate(), NMd2Hash::calculate(), compare(), find(), insert(), NXmlSchemaParser::parse(), NXmlParser::parse(), replace_first(), and split().

bool isNull ( void   )  const

Checks whether the current string is null (empty).

Returns:
true if it is null or false otherwise
Examples:
ex_nstring.cpp.

Definition at line 207 of file nstring.cpp.

Referenced by compare(), NXmlParser::parse(), and NFile::setFileName().

NString & append ( const char *  str,
nuint32  bytes 
)

Appends a string to the current object.

Parameters:
str A pointer to a NULL terminated string to be appended
Returns:
A reference to this

Definition at line 216 of file nstring.cpp.

Referenced by append(), operator+(), and operator+=().

NString & append ( const char *  str  )  [inline]

Appends a string to the current object.

Parameters:
str A pointer to a NULL terminated string to be appended
Returns:
A reference to this

Definition at line 229 of file nstring.cpp.

References append().

NString & append ( const NString str  ) 

Appends a string to the current object.

Parameters:
str A NString object to be appended
Returns:
A reference to this

Definition at line 235 of file nstring.cpp.

References append(), and toChar().

NString & append ( char  c  ) 

Appends a char to the current object.

Parameters:
c An ASCII char
Returns:
A reference to this

Definition at line 241 of file nstring.cpp.

References append().

NString & insert ( nuint32  pos,
nuint32  size,
const NString  str 
)

Inserts a string at a given position in the string.

Parameters:
pos Position where to insert
bytes Number of bytes, from str, to be inserted into the string
str The string to be inserted
Returns:
A referece to this
Examples:
ex_nstring.cpp, and ex_skip_vs_sorted.cpp.

Definition at line 245 of file nstring.cpp.

References length(), and toChar().

Referenced by insert().

NString & insert ( nuint32  pos,
const NString  str 
)

Inserts a string at a given position in the string.

Parameters:
pos Position where to insert
str The string to be inserted
Returns:
A referece to this

Definition at line 269 of file nstring.cpp.

References insert(), and length().

bool compare ( nuint32  pos,
nuint32  size,
const NString str 
) const

Compare the string.

Parameters:
pos Initial position (start from 0)
size Number of bytes to compare
str The string to be compared
Returns:
true if it's equal or false otherwise
Note:
If given incorrect values, the method will return false
Examples:
ex_nstring.cpp.

Definition at line 274 of file nstring.cpp.

References isNull(), length(), and toChar().

Referenced by compare(), find(), operator!=(), and operator==().

bool compare ( nuint32  pos,
const NString str 
) const

Compare the string.

Parameters:
pos Initial position (start from 0)
str The string to be compared
Returns:
true if it's equal or false otherwise
Note:
If given incorrect values, the method will return false

Definition at line 301 of file nstring.cpp.

References compare().

bool compare ( nuint32  pos,
nuint32  size,
const NString str,
nuint32  str_pos 
) const

Compare the string.

Parameters:
pos Initial position (start from 0)
size Number of bytes to compare
str The string to be compared
str_pos Initial position on string 'str'
Returns:
true if it's equal or false otherwise
Note:
If given incorrect values, the method will return false

Definition at line 306 of file nstring.cpp.

References length(), and toChar().

NString substr ( nuint32  pos,
nuint32  size 
) const

Gets a substring.

Parameters:
pos Initial position (start from 0)
size Number of bytes to get
Note:
Returns a default constructed value if pos and size are not valid
Returns:
A NString object with the substring
Examples:
ex_nstring.cpp.

Definition at line 322 of file nstring.cpp.

Referenced by replace_first(), and split().

nint32 find ( const NString str,
nuint32  pos,
nuint32  ocur 
) const

Finds a substring starting from a given position.

Parameters:
str Substring to find
pos The initial position
ocur The Nth occurrence of the substring to find
Returns:
The position of the substring or -1 if not found
Examples:
ex_nstring.cpp.

Definition at line 338 of file nstring.cpp.

References NOT_FOUND.

Referenced by NSqlQuery::addBindValue(), NSqlQuery::bindValue(), find(), replace_first(), and split().

nint32 find ( const NString str,
nuint32  pos 
) const

Finds a substring starting from a given position.

Parameters:
str Substring to find
pos The initial position
Returns:
The position of the substring or -1 if not found

Definition at line 351 of file nstring.cpp.

References compare(), length(), and NOT_FOUND.

nint32 find ( const NString str  )  const

Finds a substring.

Parameters:
str Substring to find
Returns:
The position of the substring or -1 if not found

Definition at line 365 of file nstring.cpp.

References find().

NString & replace_first ( const NString src,
const NString dest 
)

Replaces the first ocurrence of 'src' with 'dest'.

Parameters:
src String to find
dest String to replace with
Returns:
A reference to this
Note:
This method is case sensitive
Examples:
ex_nstring.cpp.

Definition at line 370 of file nstring.cpp.

References find(), length(), NOT_FOUND, and substr().

Referenced by NSqlQuery::addBindValue(), NSqlQuery::bindValue(), and replace().

NString & replace ( const NString src,
const NString dest 
)

Replaces part of the string.

Parameters:
src String to find
dest String to replace with
Returns:
A reference to this
Note:
This method is case sensitive
Examples:
ex_nstring.cpp.

Definition at line 392 of file nstring.cpp.

References replace_first().

NString & replace ( const NString src,
const NString dest,
nuint32  ocur 
)

Replaces part of the string.

Parameters:
src String to find
dest String to replace with
ocur The Nth occurrence to replace
Returns:
A reference to this
Note:
This method is case sensitive

Definition at line 409 of file nstring.cpp.

References replace_first().

NList< NString > split ( const NString substr  ) 

Splits the string.

Parameters:
substr The substring to split at
Returns:
A NList<NString> object containing the substrings splitted at substr

Definition at line 431 of file nstring.cpp.

References NList::append(), find(), length(), NOT_FOUND, and substr().

NString operator+ ( const char *  str  ) 

Appends a string to the current object.

Parameters:
str A pointer to a NULL terminated string to be appended
Returns:
A copy of this

Definition at line 464 of file nstring.cpp.

References append().

NString operator+ ( const NString str  ) 

Appends a string to the current object.

Parameters:
str A NString object to be appended
Returns:
A copy of this

Definition at line 474 of file nstring.cpp.

References append().

NString operator+ ( char  c  ) 

Appends a char to the current object.

Parameters:
c An ASCII char
Returns:
A reference to this

Definition at line 469 of file nstring.cpp.

References append().

NString & operator+= ( const char *  str  ) 

Appends a string to the current object.

Parameters:
str A pointer to a NULL terminated string to be appended
Returns:
A reference to this

Definition at line 479 of file nstring.cpp.

References append().

NString & operator+= ( const NString str  ) 

Appends a string to the current object.

Parameters:
str A NString object to be appended
Returns:
A reference to this

Definition at line 484 of file nstring.cpp.

References append().

NString & operator+= ( char  c  ) 

Appends a char to the current object.

Parameters:
c An ASCII char
Returns:
A reference to this

Definition at line 489 of file nstring.cpp.

References append().

char operator[] ( unsigned int  index  )  const

Access the char at position index.

Parameters:
index The position of the char in the string
Returns:
The char at position index

Definition at line 494 of file nstring.cpp.

bool operator== ( const NString str  )  const

Checks whether the current object is equals str.

Parameters:
str String to be checked against
Returns:
true if it is equal or false otherwise

Definition at line 499 of file nstring.cpp.

References compare().

bool operator!= ( const NString str  )  const

Checks whether the current object is not equal to str.

Parameters:
str String to be checked against
Returns:
true if it is not equal or false otherwise

Definition at line 504 of file nstring.cpp.

References compare().

bool operator> ( const NString str  )  const

Checks whether the current object is lexically greater than str.

Parameters:
str String to be checked against
Returns:
true if it is lexically greater or false otherwise

Definition at line 510 of file nstring.cpp.

References toChar().

bool operator< ( const NString str  )  const

Checks whether the current object is lexically less than str.

Parameters:
str String to be checked against
Returns:
true if it is lexically less or false otherwise

Definition at line 522 of file nstring.cpp.

References toChar().

bool operator>= ( const NString str  )  const

Checks whether the current object is lexically greater than or equals str.

Parameters:
str String to be checked against
Returns:
true if it is lexically greater than or equals str or false otherwise

Definition at line 534 of file nstring.cpp.

References toChar().

bool operator<= ( const NString str  )  const

Checks whether the current object is lexically less than or equals str.

Parameters:
str String to be checked against
Returns:
true if it is lexically less or equals str or false otherwise

Definition at line 546 of file nstring.cpp.

References toChar().

NString & operator= ( const NString str  ) 

Sets the string of the current object.

Parameters:
str A NString object with the string
Returns:
A reference to this

Definition at line 558 of file nstring.cpp.

NString & arg ( const char *  fmt,
  ... 
)

Provides formatted output to a NString object.

Parameters:
fmt Output format
Note:
The acceptable format is that used by printf.
Examples:
ex_nstring.cpp.

Definition at line 563 of file nstring.cpp.


Member Data Documentation

const nint32 NOT_FOUND = -1 [static]

Substring not found identified

Definition at line 400 of file nstring.h.

Referenced by NSqlQuery::addBindValue(), NSqlQuery::bindValue(), find(), replace_first(), and split().


The documentation for this class was generated from the following files:
Generated on Wed Mar 5 23:10:37 2008 for NemesisUtilitiesSystem by  doxygen 1.5.4