BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
BALL::String Class Reference

#include <BALL/DATATYPE/string.h>

Public Types

typedef string::value_type valuetype
 
typedef string::traits_type traits_type
 
typedef string::allocator_type allocator_type
 
typedef string::reference reference
 
typedef string::const_reference const_reference
 
typedef string::pointer pointer
 
typedef string::const_pointer const_pointer
 
typedef string::iterator iterator
 
typedef string::const_iterator const_iterator
 
typedef string::reverse_iterator reverse_iterator
 
typedef
string::const_reverse_iterator 
const_reverse_iterator
 
typedef string::difference_type difference_type
 
typedef string::size_type size_type
 

Public Member Functions

virtual void * create (bool=true, bool empty=false) const
 
Constructors and Destructors
 String ()
 Default Constructor. More...
 
 String (const string &string)
 STL string copy constructor. More...
 
 String (const String &s)
 Copy constructor. More...
 
 String (const QString &string)
 QString copy constructor. More...
 
 String (const QByteArray &string)
 QByteArray copy constructor. More...
 
 String (const String &s, Index from, Size len=EndPos)
 
 String (const char *char_ptr, Index from=0, Size len=EndPos)
 
 String (Size buffer_size, const char *format,...)
 
 String (std::strstream &s)
 
 String (const char c, Size len=1)
 
 String (const unsigned char uc)
 Creates a string just containing an unsigned character. More...
 
 String (short s)
 Construct a String from a short. More...
 
 String (unsigned short us)
 Construct a String from an unsigned short. More...
 
 String (int i)
 Construct a String from an int. More...
 
 String (unsigned int ui)
 Construct a String from an unsigned int. More...
 
 String (long l)
 Construct a String from a long. More...
 
 String (unsigned long)
 Construct a String from an unsigned long. More...
 
 String (float f)
 Construct a String from a float value. More...
 
 String (double d)
 Construct a String from a double value. More...
 
 operator string & ()
 Cast the String to a std::string reference. More...
 
 operator string const & () const
 Cast the String to a std::string reference, const version. More...
 
virtual ~String ()
 Destructor. More...
 
void destroy ()
 Clear the string (reset to the empty string) More...
 
Assignment methods
void set (const String &s)
 
void set (const String &string, Index from, Size len=EndPos)
 
void set (const char *char_ptr, Index from=0, Size len=EndPos)
 
void set (Size buffer_size, const char *format,...)
 
void set (std::strstream &s)
 
void set (char c, Size len=1)
 Assign a String from the result of repeating c len times. More...
 
void set (unsigned char uc)
 Assign a String from an unsigned char. More...
 
void set (short s)
 Assign a String from a short. More...
 
void set (unsigned short us)
 Assign a String from an unsigned short. More...
 
void set (int i)
 Assign a String from an int. More...
 
void set (unsigned int ui)
 Assign a String from an unsigned int. More...
 
void set (long l)
 Assign a String from a long. More...
 
void set (unsigned long ul)
 Assign a String from an unsigned long. More...
 
void set (float f)
 Assign a String from a float value. More...
 
void set (double d)
 Assign a String from a double value. More...
 
void get (char *char_ptr, Index from=0, Size len=EndPos) const
 
const Stringoperator= (const String &s)
 Assign a String from another String. More...
 
const Stringoperator= (const char *pc)
 
const Stringoperator= (std::strstream &s)
 
const Stringoperator= (char c)
 Assign a String from a single char. More...
 
const Stringoperator= (unsigned char uc)
 Assign a String from an unsigned char. More...
 
const Stringoperator= (short s)
 Assign a String from a short. More...
 
const Stringoperator= (unsigned short us)
 Assign a String from an unsigned short. More...
 
const Stringoperator= (int i)
 Assign a String from an int. More...
 
const Stringoperator= (unsigned int ui)
 Assign a String from an unsigned int. More...
 
const Stringoperator= (long l)
 Assign a String from a long. More...
 
const Stringoperator= (unsigned long ul)
 Assign a String from an unsigned long. More...
 
const Stringoperator= (float f)
 Assign a String from a float. More...
 
const Stringoperator= (double d)
 Assign a String from a double. More...
 
Converters
bool toBool () const
 
char toChar () const
 Return the first character of the string. More...
 
unsigned char toUnsignedChar () const
 Return the first character of the string converted to an unsigned char. More...
 
short toShort () const
 
unsigned short toUnsignedShort () const
 
int toInt () const
 
unsigned int toUnsignedInt () const
 
long toLong () const
 
unsigned long toUnsignedLong () const
 
float toFloat () const
 
double toDouble () const
 
Case Conversion
void toLower (Index from=0, Size len=EndPos)
 
void toUpper (Index from=0, Size len=EndPos)
 
Substring Definition
Substring getSubstring (Index from=0, Size len=EndPos) const
 
Substring operator() (Index from, Size len=EndPos) const
 
Substring before (const String &s, Index from=0) const
 
Substring through (const String &s, Index from=0) const
 
Substring from (const String &s, Index from=0) const
 
Substring after (const String &s, Index from=0) const
 
AWK style field operations
Size countFields (const char *delimiters=CHARACTER_CLASS__WHITESPACE) const
 
Size countFieldsQuoted (const char *delimiters=CHARACTER_CLASS__WHITESPACE, const char *quotes=CHARACTER_CLASS__QUOTES) const
 
String getField (Index index, const char *delimiters=CHARACTER_CLASS__WHITESPACE, Index *from=0) const
 
String getFieldQuoted (Index index, const char *delimiters=CHARACTER_CLASS__WHITESPACE, const char *quotes=CHARACTER_CLASS__QUOTES, Index *from=0) const
 
Size split (String string_array[], Size array_size, const char *delimiters=CHARACTER_CLASS__WHITESPACE, Index from=0) const
 
Size split (std::vector< String > &strings, const char *delimiters=CHARACTER_CLASS__WHITESPACE, Index from=0) const
 
Size splitQuoted (std::vector< String > &strings, const char *delimiters=CHARACTER_CLASS__WHITESPACE, const char *quotes=CHARACTER_CLASS__QUOTES, Index from=0) const
 
BASIC style string operations
StringtrimLeft (const char *trimmed=CHARACTER_CLASS__WHITESPACE)
 
StringtrimRight (const char *trimmed=CHARACTER_CLASS__WHITESPACE)
 
Stringtrim (const char *trimmed=CHARACTER_CLASS__WHITESPACE)
 
String trim (const char *trimmed=CHARACTER_CLASS__WHITESPACE) const
 
Stringtruncate (Size size)
 Truncate the string to length size More...
 
Substring left (Size len) const
 Return a substring containing the len leftmost characters of the string. More...
 
Substring right (Size len) const
 Return a substring containing the len rightmost characters of the string. More...
 
Substring instr (const String &pattern, Index from=0) const
 
Base64 String methods
String encodeBase64 ()
 Convert a string to a base 64 string. More...
 
String decodeBase64 ()
 
Debugging and Diagnostics
bool isValid () const
 
void dump (std::ostream &s=std::cout, Size depth=0) const
 
Stream Operations
std::istream & getline (std::istream &s=std::cin, char delimiter= '\n')
 
Iterators
iterator begin () BALL_NOEXCEPT
 
const_iterator begin () const BALL_NOEXCEPT
 
iterator end () BALL_NOEXCEPT
 
const_iterator end () const BALL_NOEXCEPT
 
reverse_iterator rbegin () BALL_NOEXCEPT
 
const_reverse_iterator rbegin () const BALL_NOEXCEPT
 
reverse_iterator rend () BALL_NOEXCEPT
 
const_reverse_iterator rend () const BALL_NOEXCEPT
 
Capacity
size_t size () const BALL_NOEXCEPT
 
size_t length () const BALL_NOEXCEPT
 
size_t max_size () const BALL_NOEXCEPT
 
void resize (size_t n)
 
void resize (size_t n, char c)
 
size_t capacity () const BALL_NOEXCEPT
 
void reserve (size_t n=0)
 
void clear () BALL_NOEXCEPT
 
bool empty () const BALL_NOEXCEPT
 
Element Access
char & operator[] (size_t pos)
 
const char & operator[] (size_t pos) const
 
char & at (size_t pos)
 
const char & at (size_t pos) const
 
Modifiers
Stringoperator+= (const String &str)
 
Stringoperator+= (const string &str)
 
Stringoperator+= (const char *s)
 
Stringoperator+= (char c)
 
Stringappend (const String &str)
 
Stringappend (const string &str)
 
Stringappend (const string &str, size_t subpos, size_t sublen)
 
Stringappend (const char *s)
 
Stringappend (const char *s, size_t n)
 
Stringappend (size_t n, char c)
 
template<class InputIterator >
Stringappend (InputIterator first, InputIterator last)
 
void push_back (char c)
 
Stringassign (const String &str)
 
Stringassign (const string &str)
 
Stringassign (const string &str, size_t subpos, size_t sublen)
 
Stringassign (const char *s)
 
Stringassign (const char *s, size_t n)
 
Stringassign (size_t n, char c)
 
template<class InputIterator >
Stringassign (InputIterator first, InputIterator last)
 
Stringinsert (size_t pos, const string &str)
 
Stringinsert (size_t pos, const string &str, size_t subpos, size_t sublen)
 
Stringinsert (size_t pos, const char *s)
 
Stringinsert (size_t pos, const char *s, size_t n)
 
Stringinsert (size_t pos, size_t n, char c)
 
void insert (iterator p, size_t n, char c)
 
iterator insert (iterator p, char c)
 
template<class InputIterator >
iterator insert (iterator p, InputIterator first, InputIterator last)
 
Stringerase (size_t pos=0, size_t len=npos)
 
iterator erase (iterator p)
 
iterator erase (iterator first, iterator last)
 
Stringreplace (size_t pos, size_t len, const string &str)
 
Stringreplace (size_t pos, size_t len, const string &str, size_t subpos, size_t sublen)
 
Stringreplace (size_t pos, size_t len, const char *s)
 
Stringreplace (size_t pos, size_t len, const char *s, size_t n)
 
Stringreplace (size_t pos, size_t len, size_t n, char c)
 
Stringreplace (iterator i1, iterator i2, const string &str)
 
Stringreplace (iterator i1, iterator i2, const char *s)
 
Stringreplace (iterator i1, iterator i2, const char *s, size_t n)
 
Stringreplace (iterator i1, iterator i2, size_t n, char c)
 
template<class InputIterator >
Stringreplace (iterator i1, iterator i2, InputIterator first, InputIterator last)
 
void swap (string &str)
 

Static Public Member Functions

Compare mode-related methods.

All string comparisons can be made case-sensitive or case insensitive. The behavior can be toggled globally for all strings.

static void setCompareMode (CompareMode compare_mode)
 Set the compareison mode for all string comparisons. More...
 
static CompareMode getCompareMode ()
 Return the current comparison mode. More...
 

Static Public Attributes

static const String EMPTY
 Constant empty string. More...
 
Predefined character classes

There exist several predefined character classes, that may be used in several functions (e.g. trim methods) to represent a set of characters.

static const char * CHARACTER_CLASS__ASCII_ALPHA
 Character class containing all letters (lower and upper case) More...
 
static const char * CHARACTER_CLASS__ASCII_ALPHANUMERIC
 Character class containing all letters and digits. More...
 
static const char * CHARACTER_CLASS__ASCII_LOWER
 Character class containing all lower case letters. More...
 
static const char * CHARACTER_CLASS__ASCII_UPPER
 Character class containing all upper case letters. More...
 
static const char * CHARACTER_CLASS__ASCII_NUMERIC
 Character class containing the digits from 0 to 9. More...
 
static const char * CHARACTER_CLASS__ASCII_FLOAT
 Character class containing the digits from 0 to 9 and a dot. More...
 
static const char * CHARACTER_CLASS__WHITESPACE
 
static const char * CHARACTER_CLASS__QUOTES
 

Protected Member Functions

void validateIndex_ (Index &index) const
 
void validateRange_ (Index &from, Size &len) const
 

Static Protected Member Functions

static void validateCharPtrRange_ (Index &from, Size &len, const char *char_ptr)
 
static void valudateCharPtrIndex_ (Index &index)
 

Friends

class Substring
 

Enums and Constants

enum  CompareMode { CASE_SENSITIVE = 0, CASE_INSENSITIVE = 1 }
 
static const Size EndPos
 
static const size_t npos = -1
 

String Operations

BALL_EXPORT friend String operator+ (const String &s1, const string &s2)
 Concatenates two strings. More...
 
BALL_EXPORT friend String operator+ (const string &s1, const String &s2)
 Concatenates two strings. More...
 
BALL_EXPORT friend String operator+ (const String &s1, const String &s2)
 Concatenates two strings. More...
 
BALL_EXPORT friend String operator+ (const String &s1, const char *char_ptr)
 Concatenates a string and a C type string. More...
 
BALL_EXPORT friend String operator+ (const char *char_ptr, const String &s)
 Concatenates a C type string and a string. More...
 
BALL_EXPORT friend String operator+ (const String &s, char c)
 Concatenates a string and a character. More...
 
BALL_EXPORT friend String operator+ (char c, const String &s)
 Concatenates a character and a string. More...
 
void swap (String &s)
 Swaps the contents with another String. More...
 
Stringreverse (Index from=0, Size len=EndPos)
 
Size substitute (const String &to_replace, const String &replacing)
 
void substituteAll (const String &to_replace, const String &replacing)
 
const char * c_str () const BALL_NOEXCEPT
 
const char * data () const BALL_NOEXCEPT
 
allocator_type get_allocator () const BALL_NOEXCEPT
 
size_t copy (char *s, size_t len, size_t pos=0) const
 
size_t find (const string &str, size_t pos=0) const BALL_NOEXCEPT
 
size_t find (const char *s, size_t pos=0) const
 
size_t find (const char *s, size_t pos, size_t n) const
 
size_t find (char c, size_t pos=0) const BALL_NOEXCEPT
 
size_t rfind (const string &str, size_t pos=npos) const BALL_NOEXCEPT
 
size_t rfind (const char *s, size_t pos=npos) const
 
size_t rfind (const char *s, size_t pos, size_t n) const
 
size_t rfind (char c, size_t pos=npos) const BALL_NOEXCEPT
 
size_t find_first_of (const string &str, size_t pos=0) const BALL_NOEXCEPT
 
size_t find_first_of (const char *s, size_t pos=0) const
 
size_t find_first_of (const char *s, size_t pos, size_t n) const
 
size_t find_first_of (char c, size_t pos=0) const BALL_NOEXCEPT
 
size_t find_last_of (const string &str, size_t pos=npos) const BALL_NOEXCEPT
 
size_t find_last_of (const char *s, size_t pos=npos) const
 
size_t find_last_of (const char *s, size_t pos, size_t n) const
 
size_t find_last_of (char c, size_t pos=npos) const BALL_NOEXCEPT
 
size_t find_first_not_of (const string &str, size_t pos=0) const BALL_NOEXCEPT
 
size_t find_first_not_of (const char *s, size_t pos=0) const
 
size_t find_first_not_of (const char *s, size_t pos, size_t n) const
 
size_t find_first_not_of (char c, size_t pos=0) const BALL_NOEXCEPT
 
size_t find_last_not_of (const string &str, size_t pos=npos) const BALL_NOEXCEPT
 
size_t find_last_not_of (const char *s, size_t pos=npos) const
 
size_t find_last_not_of (const char *s, size_t pos, size_t n) const
 
size_t find_last_not_of (char c, size_t pos=npos) const BALL_NOEXCEPT
 
string substr (size_t pos=0, size_t len=npos) const
 
int compare (const string &str) const BALL_NOEXCEPT
 
int compare (size_t pos, size_t len, const string &str) const
 
int compare (size_t pos, size_t len, const string &str, size_t subpos, size_t sublen) const
 
int compare (size_t pos, size_t len, const char *s) const
 
int compare (size_t pos, size_t len, const char *s, size_t n) const
 

Predicates

bool has (char c) const
 True, if the string contains character c More...
 
bool hasSubstring (const String &s, Index from=0) const
 True, if the string contains the substring s after index from More...
 
bool hasPrefix (const String &s) const
 True, if the string starts with s More...
 
bool hasSuffix (const String &s) const
 True, if the string ends with s More...
 
bool isEmpty () const
 True, if the string has size 0. More...
 
bool isAlpha () const
 
bool isAlnum () const
 
bool isDigit () const
 
bool isFloat () const
 
bool isSpace () const
 
bool isWhitespace () const
 
static bool isAlpha (char c)
 True, if the character is a letter (any case) More...
 
static bool isAlnum (char c)
 True, if the character is a letter or a digit. More...
 
static bool isDigit (char c)
 True, if the character is a digit. More...
 
static bool isSpace (char c)
 True, if the character is a space. More...
 
static bool isWhitespace (char c)
 

Comparators

BALL_EXPORT friend bool operator== (const String &s1, const String &s2)
 
BALL_EXPORT friend bool operator!= (const String &s1, const String &s2)
 
BALL_EXPORT friend bool operator< (const String &s1, const String &s2)
 
BALL_EXPORT friend bool operator<= (const String &s1, const String &s2)
 
BALL_EXPORT friend bool operator> (const String &s1, const String &s2)
 
BALL_EXPORT friend bool operator>= (const String &s1, const String &s2)
 
BALL_EXPORT friend bool operator== (const char *char_ptr, const String &string)
 
BALL_EXPORT friend bool operator!= (const char *char_ptr, const String &string)
 
BALL_EXPORT friend bool operator< (const char *char_ptr, const String &string)
 
BALL_EXPORT friend bool operator<= (const char *char_ptr, const String &string)
 
BALL_EXPORT friend bool operator> (const char *char_ptr, const String &string)
 
BALL_EXPORT friend bool operator>= (const char *char_ptr, const String &string)
 
BALL_EXPORT friend bool operator== (char c, const String &string)
 
BALL_EXPORT friend bool operator!= (char c, const String &string)
 
BALL_EXPORT friend bool operator< (char c, const String &string)
 
BALL_EXPORT friend bool operator<= (char c, const String &string)
 
BALL_EXPORT friend bool operator> (char c, const String &string)
 
bool operator>= (char c, const String &string)
 
int compare (const String &string, Index from=0) const
 
int compare (const String &string, Index from, Size len) const
 
int compare (const char *char_ptr, Index from=0) const
 
int compare (const char *char_ptr, Index from, Size len) const
 
int compare (char c, Index from=0) const
 
bool operator== (const char *char_ptr) const
 
bool operator!= (const char *char_ptr) const
 
bool operator< (const char *char_ptr) const
 
bool operator<= (const char *char_ptr) const
 
bool operator> (const char *char_ptr) const
 
bool operator>= (const char *char_ptr) const
 
bool operator== (char c) const
 
bool operator!= (char c) const
 
bool operator< (char c) const
 
bool operator<= (char c) const
 
bool operator> (char c) const
 
bool operator>= (char c) const
 

Detailed Description

Extended String class.

Definition at line 61 of file string.h.

Member Function Documentation

static void BALL::String::validateCharPtrRange_ ( Index from,
Size len,
const char *  char_ptr 
)
staticprotected
void BALL::String::validateIndex_ ( Index index) const
protected
void BALL::String::validateRange_ ( Index from,
Size len 
) const
protected
static void BALL::String::valudateCharPtrIndex_ ( Index index)
staticprotected