Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Namespace Members   Compound Members  

PLMString Class Reference

Simple string class. More...

#include <PLMString.hpp>

List of all members.

Public Methods

 PLMString (const char *txt=0)
 PLMString (u32 size, const char *txt=0)
 PLMString (const PLMString &cp)
PLMString & operator= (const PLMString &str)
PLMString & operator= (const char *str)
void Allocate (u32 size, bool keep=true)
u32 Length () const
u32 Size () const
bool IsEmpty () const
void Fill (char c, u32 start=0, u32 nb=PLM::INDEX_ERROR)
const char * Text () const
void ChangeText (const char *newtext, u32 start=0, u32 nb=PLM::INDEX_ERROR)
PLMString & Format (const char *format,...)
void Insert (char c, u32 index)
void Insert (const char *str, u32 index)
void Insert (const PLMString &str, u32 index)
void Append (char c)
void Append (const char *str)
void Append (const PLMString &str)
PLMString & operator+= (char c)
PLMString & operator+= (const PLMString &str)
PLMString & operator+= (const char *str)
char Char (u32 index) const
bool SetChar (u32 index, char c)
char operator[] (u32 index) const
u32 Find (char c, u32 start=0, bool case_s=true) const
u32 Find (const char *str, u32 start=0, bool case_s=true) const
u32 Find (const PLMString &str, u32 start=0, bool case_s=true) const
u32 RFind (char c, u32 start=PLM::INDEX_ERROR, bool case_s=true) const
u32 RFind (const char *str, u32 start=PLM::INDEX_ERROR, bool case_s=true) const
u32 RFind (const PLMString &str, u32 start=PLM::INDEX_ERROR, bool case_s=true) const
int Replace (char a, char b)
void LowerCase ()
void UpperCase ()
void Obfuscate ()
void MakeFilename ()
int Compare (const char *s2, bool case_s=true, u32 nb=PLM::INDEX_ERROR, u32 start=0) const
int Compare (const PLMString &s2, bool case_s=true, u32 nb=PLM::INDEX_ERROR, u32 start=0) const
bool operator== (const char *str)
bool operator!= (const char *str)
void Delete (u32 index, u32 nb=1)
void Truncate (u32 index)
u32 KillWord (u32 start)
void Clear ()
void PrintInfo () const

Static Public Methods

char * StringCopy (const char *str, u32 start=0, u32 nb=PLM::INDEX_ERROR)

Friends

PLMDLL ostream & operator<< (ostream &os, const PLMString &str)
PLMString operator+ (const PLMString &s1, const PLMString &s2)
PLMString operator+ (const PLMString &s1, const char *s2)
PLMString operator+ (const char *s1, const PLMString &s2)
PLMString operator+ (const PLMString &s1, char c)
PLMString operator+ (char c, const PLMString &s1)


Detailed Description

Simple string class.


Constructor & Destructor Documentation

PLMString::PLMString const char *    txt = 0
 

Create an empty string or initialize it with txt.

PLMString::PLMString u32    size,
const char *    txt = 0
 

Pre-allocate size chars and initialize it with txt (txt is truncated if longer than size chars).

PLMString::PLMString const PLMString &    cp
 

Create a copy of the string cp.


Member Function Documentation

PLMString& PLMString::operator= const PLMString &    str
 

Modify current string, copy str content.

PLMString& PLMString::operator= const char *    str
 

Modify current string, copy str content.

void PLMString::Allocate u32    size,
bool    keep = true
 

Make sure the string can contain at least size characters (Size() > size).

The content is not lost unless keep is false (Length() == 0). If size is smaller than the current size nothing is modified.

u32 PLMString::Length   [inline]
 

Return the number of characters in the string (without last '\0') (< Size()).

u32 PLMString::Size   [inline]
 

Return the current number of allocated characters (> Length()).

bool PLMString::IsEmpty   [inline]
 

Check if the string is empty (Length() == 0).

void PLMString::Fill char    c,
u32    start = 0,
u32    nb = PLM::INDEX_ERROR
 

Replace nb characters by the same value c, from index start.

Example: Fill ('X', 3, 4) on "abcdefghij" will give "abcXXXXhij", and on "abcd" will give "abcXXXX", but "ab" is not modified.

Parameters:
c  the character to write,
start  starting index (should be < Length())
nb  number of characters to replace by c, PLM::INDEX_ERROR means current length (then start must be < length).

const char * PLMString::Text   [inline]
 

Get current string content. Not modifiable.

void PLMString::ChangeText const char *    newtext,
u32    start = 0,
u32    nb = PLM::INDEX_ERROR
 

Replace current content.

Parameters:
newtext  the source string, if NULL the current string is cleared,
start  starting index in newtext,
nb  number of characters to copy from newtext starting from start, PLM::INDEX_ERROR means all remaining characters.

PLMString& PLMString::Format const char *    format,
...   
 

Replace current content by a formatted string using printf format.

void PLMString::Insert char    c,
u32    index
 

Insert the character c at index (size is modified if necessary).

void PLMString::Insert const char *    str,
u32    index
 

Insert the string str at index (size is modified if necessary).

void PLMString::Insert const PLMString &    str,
u32    index
[inline]
 

Insert the string str at index (size is modified if necessary).

void PLMString::Append char    c [inline]
 

Add the character c at the end of the string.

void PLMString::Append const char *    str [inline]
 

Add the string str at the end of the string.

void PLMString::Append const PLMString &    str [inline]
 

Add the string str at the end of the string.

PLMString& PLMString::operator+= char    c
 

Add the character c at the end of the string.

PLMString& PLMString::operator+= const PLMString &    str
 

Add the string str at the end of the string.

PLMString& PLMString::operator+= const char *    str
 

Add the string str at the end of the string.

char PLMString::Char u32    index const [inline]
 

Get character at index index, or 0 if index is invalid.

See also:
operator[].

bool PLMString::SetChar u32    index,
char    c
[inline]
 

Replace the character at index index by c.

Return false if index is not valid.

char PLMString::operator[] u32    index const [inline]
 

Get character at index index, or 0 if index is invalid.

See also:
Char().

u32 PLMString::Find char    c,
u32    start = 0,
bool    case_s = true
const
 

Find the first occurence of character c starting at index start.

Parameters:
c  the character to find,
start  the starting index in the string (first character to be checked),
case_s  true means that comparisons are case sensitive (a != A).
Returns:
found index on success, PLM::INDEX_ERROR if not found.

u32 PLMString::Find const char *    str,
u32    start = 0,
bool    case_s = true
const
 

Find the first occurence of string str starting at index start.

u32 PLMString::Find const PLMString &    str,
u32    start = 0,
bool    case_s = true
const
 

Find the first occurence of string str starting at index start.

u32 PLMString::RFind char    c,
u32    start = PLM::INDEX_ERROR,
bool    case_s = true
const
 

Reverse find function (read from end to start) (= find last occurence).

Parameters:
c  the character to find,
start  the starting index in the string (PLM::INDEX_ERROR means the end),
case_s  true means that comparisons are case sensitive (a != A).
Returns:
found index on success, PLM::INDEX_ERROR if not found.

u32 PLMString::RFind const char *    str,
u32    start = PLM::INDEX_ERROR,
bool    case_s = true
const
 

Find the last occurence of string str starting at index start.

u32 PLMString::RFind const PLMString &    str,
u32    start = PLM::INDEX_ERROR,
bool    case_s = true
const
 

Find the last occurence of string str starting at index start.

int PLMString::Replace char    a,
char    b
 

Replace all occurrences of a by b.

Return number of occurrences. Example: Replace ('\', '/') on "dir1\dir2\file.ext" will give "dir/dir2/file.ext". Return immediately 0 if or is 0.

void PLMString::LowerCase  
 

Change all characters to lower case (A->a, B->b).

void PLMString::UpperCase  
 

Change all characters to upper case (a->A, b->B).

void PLMString::Obfuscate  
 

Modify all characters to make them unreadable.

In fact, the characters are just inverted (bitwise NOT), so a second call to Obfuscate() restores the initial string.

void PLMString::MakeFilename  
 

Parse the current string and convert/remove all characters that are not allowed in a "standard" file name.

Even spaces are replaced by "_". Only [a-zA-Z0-9] and '_', '-' and '.' are kept.

Example: "dir/$$file() n[am]e g*?<>.ext" is turned into "dir_file_name_g.ext".

Note that the resulting string may be empty if all characters are invalid. Warning: do not call this on a string containing a leading path, since path_separator ("/" or "\") will be converted ("_").

int PLMString::Compare const char *    s2,
bool    case_s = true,
u32    nb = PLM::INDEX_ERROR,
u32    start = 0
const
 

Compare current string (s1) with s2.

Parameters:
s2  the string to compare with,
case_s  compare case sensitively if true,
nb  only compare nb characters, PLM::INDEX_ERROR means all characters,
start  start at index start (only in s1).
Returns:
0 if s1 == s2, 1 if s1 > s2, -1 if s1 < s2 (alpha order)

int PLMString::Compare const PLMString &    s2,
bool    case_s = true,
u32    nb = PLM::INDEX_ERROR,
u32    start = 0
const [inline]
 

Compare current string (s1) with s2.

Parameters:
s2  the string to compare with,
case_s  compare case sensitively if true,
nb  only compare nb characters, PLM::INDEX_ERROR means all characters,
start  start at index start (only in s1).
Returns:
0 if s1 == s2, 1 if s1 > s2, -1 if s1 < s2 (alpha order)

bool PLMString::operator== const char *    str [inline]
 

Compare current content with string str.

Comparison is case sensitive. Return true if the contents are the same.

bool PLMString::operator!= const char *    str [inline]
 

Compare current content with string str.

Comparison is case sensitive. Return true if the contents are different.

void PLMString::Delete u32    index,
u32    nb = 1
 

Remove nb characters starting at position index (from 0).

Example: Delete (3, 2) on "abcDEfgh" will give "abcfgh".

void PLMString::Truncate u32    index [inline]
 

Remove all the characters after index index (inclusive, from 0).

Example: Truncate (3) on "abcdefgh" will give "abc". Then length = index. Allocated size is not modified.

u32 PLMString::KillWord u32    start
 

Remove characters starting from index start until a non alphabetical character is read (anything but [a-zA-Z0-9]).

First characters are skipped until an alphabetical character is found.

Example: KillWord (5) on "01234;;-*+abcde +.;(aaa)" will give "01234 +.;(aaa)". Anything from the first ';' to the space is deleted (but not the space).

Returns:
the number of chars removed.

void PLMString::Clear   [inline]
 

Remove all characters, the string is then empty. Allocated size is not modified.

void PLMString::PrintInfo  
 

Print some information on current log.

char* PLMString::StringCopy const char *    str,
u32    start = 0,
u32    nb = PLM::INDEX_ERROR
[static]
 

Create a copy (allocate memory) of the string str, starting at index start (from 0) and copying at most nb characters.

Parameters:
str  the source string (not modified).
start  the starting index in str (this[0] = str[start]).
nb  the maximum number of characters to copy, PLM::INDEX_ERROR means all available. The length of the returned string is MAX (length(str), nb).
Returns:
a new allocated string containing some (or all) characters from str. If str is not valid, nb is 0 or \start is too large, NULL is returned.


Friends And Related Function Documentation

PLMDLL ostream& operator<< ostream &    os,
const PLMString &    str
[friend]
 

Write the current contents of string str to the output stream os.

PLMString operator+ const PLMString &    s1,
const PLMString &    s2
[friend]
 

Concatenate two strings.

PLMString operator+ const PLMString &    s1,
const char *    s2
[friend]
 

Concatenate two strings. Append a c-string.

PLMString operator+ const char *    s1,
const PLMString &    s2
[friend]
 

Concatenate two strings. Prepend a c-string.

PLMString operator+ const PLMString &    s1,
char    c
[friend]
 

Concatenate with single character (append).

PLMString operator+ char    c,
const PLMString &    s1
[friend]
 

Concatenate with single character (prepend).


The documentation for this class was generated from the following file:
  • PLMString.hpp

Generated by Doxygen 1.2.18 on Tue Oct 26 12:07:39 2004.