Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics
[Home] [Tutorials] [All Classes] [Grouped Classes]

vl::String Class Reference

The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine. More...

#include <String.hpp>

List of all members.

Classes

class  StringData

Public Member Functions

 String ()
 Constructor.
 String (const String &other)
 Constructor.
 String (const wchar_t *wstr)
 Constructor.
 String (const char *str)
 Constructor.
 String (wchar_t ch, int count=1)
 Constructor.
const wchar_t * ptr () const
 Returns the 0-terminated utf16 string.
wchar_t * ptr ()
 Returns the 0-terminated utf16 string.
int length () const
 Returns the length of the string.
bool empty () const
 Returns true if length() == 0.
bool null () const
 Returns true if the String has never been assigned or resized.
Stringclear ()
 Clears the string.
const wchar_t & operator[] (int i) const
 Returns the character at position i.
wchar_t & operator[] (int i)
 Returns the character at position i.
Stringreplace (wchar_t old_ch, wchar_t new_ch)
 Replaces the character 'old_ch' with 'new_ch'.
Stringreplace (int start, int count, wchar_t ch)
 Replaces count characters starting at position start with ch.
Stringreplace (int start, int count, const String &str)
 Equivalent to remove(start, count); insert(start, str);.
Stringreplace (const String &oldstr, const String &newstr, bool case_sensitive=true)
 Replaces all the occurrences of oldstr with newstr.
Stringremove (wchar_t ch, int start=0, int count=-1)
 Removes 'count' occurrences of the character 'ch' after position 'start'.
Stringremove (const String &str, int start=0, int count=-1)
 Removes 'count' occurrences of the string 'str' after position 'start'.
Stringremove (int start, int count)
 Removes 'count' characters starting at position 'start'.
Stringreverse ()
 Reverses the order of the characters in the string.
StringnormalizeSlashes ()
 Transform \ slashes in / slashes and removes duplicates.
int count (wchar_t ch, int start=0) const
 Returns the number of occurrences of the given character after position 'start'.
int count (const String &str, int start=0) const
 Returns the number of occurrences of the given string after position 'start'.
int compare (const String &other) const
 Performs a lexicographic comparison.
bool endsWith (const String &str) const
 Returns true if a String ends with the specified String str.
bool startsWith (const String &str) const
 Returns true if a String starts with the specified String str.
bool endsWith (wchar_t ch) const
 Returns true if a String ends with the specified character.
bool startsWith (wchar_t ch) const
 Returns true if a String starts with the specified character.
Stringinsert (int pos, const String &str)
 Inserts str at position pos.
Stringinsert (int pos, wchar_t ch, int count=1)
 Inserts count characters ch starting at position pos.
String left (int count) const
 Returns the count leftmost caracters of a String. If count is negative the function returns all but the abs(count) rightmost caracters.
String right (int count) const
 Returns the count rightmost caracters of a String. If count is negative the function returns all but the abs(count) leftmost caracters.
String extractPath () const
 If the String contains a file path the function returns the path with trailing slash, without the file name.
String extractFileName () const
 If the String contains a file path the function returns the file name without the path.
String extractFileExtension (bool require_dot=true) const
 If the String contains a file name or file path the function returns the extension of the file.
Stringresize (int character_count)
 Resizes the string to the specified character count.
String substring (int start, int count=-1) const
 Returns the count characters long substring starting a character index start. If count == -1 the returned substring will contain all the characters from start to the end of the String.
Stringfill (wchar_t ch)
 Fills the string with the specified character ch.
Stringtrim (wchar_t ch)
 Removes the specified character ch from the beginning and the end of the String.
Stringtrim (const String &chars)
 Removes the characters contained in chars from the beginning and the end of the String.
Stringtrim ()
 Equivalent to trim("\n\r\t\v "), that is, removes all the tabs, spaces and new-lines from the beginning and end of a String.
void split (wchar_t separator, std::vector< String > &fields, bool remove_empty_fields=false) const
 Splits a String into a set of fields. The fields are separated by the specified separator and are returned in fields.
void split (const String &separator_list, std::vector< String > &fields, bool remove_empty_fields=false) const
 Splits a String into a set of fields. The fields are separated by the specified separator_list and are returned in fields.
void splitLines (std::vector< String > &lines) const
 Splits a String into a set of Strings each of which contains a line.
String field (wchar_t separator, int field_index) const
 Splits a String into a set of fields based on the specified separator and returns the filed at position field_index.
Stringappend (const String &other)
 Appends the specified String to another String.
Stringappend (wchar_t ch, int count=1)
 Appends count characters ch to another String.
Stringprepend (const String &str)
 Prepends the specified String to another String.
Stringprepend (wchar_t ch, int count)
 Prepends count characters ch to another String.
int find (wchar_t ch, int start=0) const
 Searches for the specified character ch starting at position start and returns the index of the first occurence or -1 if no occurrence was found.
int find (const String &str, int start=0) const
 Searches for the specified String substr starting at position start and returns the index of the first occurence or -1 if no occurrence was found.
int findBackwards (wchar_t ch) const
 Searches for the specified character starting from the end of the string and returns the index of the first occurence or -1 if no occurrence was found.
int findBackwards (const String &str) const
 Searches for the specified String str from the end of the string and returns the index of the first occurence or -1 if no occurrence was found.
bool contains (wchar_t ch) const
 Returns true if a String contains the specified character.
bool contains (const String &str) const
 Returns true if a String contains the specified String.
void squeeze ()
 Minimizes the memory buffer used to store the String.
int toInt (bool hex=false) const
 Returns the int number represented by the string. The conversion is done using the standard atoi() function.
double toDouble () const
 Returns the double number represented by the string. The conversion is done using the standard atof() function.
float toFloat () const
 Returns the float number represented by the string. The conversion is done using the standard atof() function.
std::string toStdString () const
 Returns a UTF8 encoded std::string.
std::wstring toStdWString () const
 Returns the std::wstring representation of a String.
void toAscii (std::string &ascii, bool translate_non_ascii_chars=true) const
 Provides some basic character translation of code points outside of the ASCII range.
void toUTF8 (std::vector< unsigned char > &utf8, bool include_utf8_signature=true) const
 Encodes the String into a UTF8 encoded string.
void toUTF8 (std::string &utf8, bool include_utf8_signature=true) const
 Encodes the String into a UTF8 encoded std::string.
void toUTF16BE (std::vector< unsigned char > &utf16, bool include_utf16be_signature=true) const
 Encodes the String into a UTF16 big endian encoded string.
void toUTF16LE (std::vector< unsigned char > &utf16, bool include_utf16le_signature=true) const
 Encodes the String into a UTF16 little endian encoded string.
void toLatin1 (std::vector< unsigned char > &latin1) const
 Encodes the String into a Latin1 encoded string.
String toLowerCase () const
 Returns the lower-case version of a String.
String toUpperCase () const
 Returns the upper-case version of a String.
bool operator< (const String &other) const
 Lexicographic sorting, equivalent to "compare(other) < 0".
Stringoperator= (const char *str)
 Equivalent to '*this = fromUTF8(str);'.
Stringoperator= (const std::string &str)
 Equivalent to '*this = fromUTF8(str.c_str());'.
Stringoperator= (const wchar_t *wstr)
Stringoperator= (const std::wstring &str)
Stringoperator= (const String &other)
bool operator== (const String &other) const
bool operator== (const std::string &other) const
bool operator== (const std::wstring &other) const
bool operator== (const char *other) const
bool operator== (const wchar_t *other) const
bool operator!= (const String &other) const
bool operator!= (const std::string &other) const
bool operator!= (const std::wstring &other) const
bool operator!= (const char *other) const
bool operator!= (const wchar_t *other) const
Stringoperator+= (wchar_t ch)
String operator+ (wchar_t ch) const
Stringoperator+= (const String &other)
String operator+ (const String &other) const
void acquireData () const
 Acquires a private copy of the data if the string has been copied from another one.

Static Public Member Functions

static EStringEncoding detectEncoding (const void *str, int byte_count, EStringEncoding encoding=VL_PLATFORM_DEFAULT_ENCODING)
 Detects the encoding.
static String loadText (const String &path, EStringEncoding encoding=VL_PLATFORM_DEFAULT_ENCODING)
 Loads a String from the specified path.
static String loadText (const char *path, EStringEncoding encoding=VL_PLATFORM_DEFAULT_ENCODING)
 Loads a String from the specified path.
static String loadText (VirtualFile *file, EStringEncoding encoding=VL_PLATFORM_DEFAULT_ENCODING)
 Loads a String from the specified VirtualFile.
static String loadText (void *data, int bytes, EStringEncoding encoding=VL_PLATFORM_DEFAULT_ENCODING)
 Loads a String from the specified memory buffer.
static unsigned short getUpperCase (unsigned short ch)
 Returns the upper-case version of the specified character.
static unsigned short getLowerCase (unsigned short ch)
 Returns the lower-case version of the specified character.
static unsigned short getTitleCase (unsigned short ch)
 Returns the title-case version of the specified character.
static void filterStrings (std::vector< String > &strings, const String &filter)
 Filters the specified Strings using the given filter. The filter must be of the type "*abc", "abc*" and "*abc*".
static wchar_t platformSlash ()
 Returns '\' under windows and '/' under Linux and Mac.
static std::string trimStdString (const std::string &text)
 Remove the spaces before and after an std::string.
static String fromInt (int value)
 Creates a string representing the given integer value.
static String fromUInt (unsigned int value)
 Creates a string representing the given unsigned integer value.
static String fromLongLong (long long value)
 Creates a string representing the given long long value.
static String fromULongLong (unsigned long long value)
 Creates a string representing the given unsigned long long value.
static String fromDouble (double value, int decimals=6)
 Creates a string representing the given double value The value of 'decimals' can be between 0 and 20.
static String fromStdString (const std::string &str)
 Initializes the string from a std::string using the fromAscii() function.
static String fromStdWString (const std::wstring &str)
 Initializes the string from a std::string using the fromAscii() function.
static String fromAscii (const char *str, int size=-1)
 Initializes the string from a 7 bit ascii string.
static String fromUTF16BE (const unsigned short *str, int byte_count=-1)
 Accepts strings with and without UTF16 BE signature Supports natively the characters from the BMP, the other characters are substituted with '?' The size of the buffer pointed by 'str' must be at least 'byte_count' bytes large or null terminated.
static String fromUTF16LE (const unsigned short *str, int byte_count=-1)
 Accepts strings with and without UTF16 LE signature Supports natively the characters from the BMP, the other characters are substituted with '?' The size of the buffer pointed by 'str' must be at least 'byte_count' bytes large or null terminated.
static String fromUTF16 (const unsigned short *str, int byte_count=-1)
 str must have UTF16 LE or UTF16 BE signature The size of the buffer pointed by 'str' must be at least 'byte_count' bytes large or null terminated.
static String fromUTF8 (const char *str, int byte_count=-1)
 Accepts strings with and without UTF8 signature.
static String fromLatin1 (const char *str, int character_count=-1)
 The size of the buffer pointed by 'str' must be at least 'character_count' bytes large or null terminated.

Protected Member Functions

void createData () const


Detailed Description

The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.

The String class features:


Constructor & Destructor Documentation

String::String (  ) 

Constructor.

String::String ( const String other  ) 

Constructor.

String::String ( const wchar_t *  wstr  ) 

Constructor.

String::String ( const char *  str  ) 

Constructor.

String::String ( wchar_t  ch,
int  count = 1 
) [explicit]

Constructor.


Member Function Documentation

EStringEncoding String::detectEncoding ( const void *  str,
int  byte_count,
EStringEncoding  encoding = VL_PLATFORM_DEFAULT_ENCODING 
) [static]

Detects the encoding.

String String::loadText ( const String path,
EStringEncoding  encoding = VL_PLATFORM_DEFAULT_ENCODING 
) [static]

Loads a String from the specified path.

static String vl::String::loadText ( const char *  path,
EStringEncoding  encoding = VL_PLATFORM_DEFAULT_ENCODING 
) [inline, static]

Loads a String from the specified path.

String String::loadText ( VirtualFile file,
EStringEncoding  encoding = VL_PLATFORM_DEFAULT_ENCODING 
) [static]

Loads a String from the specified VirtualFile.

String String::loadText ( void *  data,
int  bytes,
EStringEncoding  encoding = VL_PLATFORM_DEFAULT_ENCODING 
) [static]

Loads a String from the specified memory buffer.

unsigned short String::getUpperCase ( unsigned short  ch  )  [static]

Returns the upper-case version of the specified character.

unsigned short String::getLowerCase ( unsigned short  ch  )  [static]

Returns the lower-case version of the specified character.

unsigned short String::getTitleCase ( unsigned short  ch  )  [static]

Returns the title-case version of the specified character.

void String::filterStrings ( std::vector< String > &  strings,
const String filter 
) [static]

Filters the specified Strings using the given filter. The filter must be of the type "*abc", "abc*" and "*abc*".

static wchar_t vl::String::platformSlash (  )  [inline, static]

Returns '\' under windows and '/' under Linux and Mac.

std::string String::trimStdString ( const std::string &  text  )  [static]

Remove the spaces before and after an std::string.

const wchar_t* vl::String::ptr (  )  const [inline]

Returns the 0-terminated utf16 string.

wchar_t* vl::String::ptr (  )  [inline]

Returns the 0-terminated utf16 string.

int vl::String::length (  )  const [inline]

Returns the length of the string.

bool vl::String::empty (  )  const [inline]

Returns true if length() == 0.

bool vl::String::null (  )  const [inline]

Returns true if the String has never been assigned or resized.

String& vl::String::clear (  )  [inline]

Clears the string.

const wchar_t& vl::String::operator[] ( int  i  )  const [inline]

Returns the character at position i.

wchar_t& vl::String::operator[] ( int  i  )  [inline]

Returns the character at position i.

String & String::replace ( wchar_t  old_ch,
wchar_t  new_ch 
)

Replaces the character 'old_ch' with 'new_ch'.

String & String::replace ( int  start,
int  count,
wchar_t  ch 
)

Replaces count characters starting at position start with ch.

String & String::replace ( int  start,
int  count,
const String str 
)

Equivalent to remove(start, count); insert(start, str);.

String & String::replace ( const String oldstr,
const String newstr,
bool  case_sensitive = true 
)

Replaces all the occurrences of oldstr with newstr.

String & String::remove ( wchar_t  ch,
int  start = 0,
int  count = -1 
)

Removes 'count' occurrences of the character 'ch' after position 'start'.

If 'count' is set -1 there is no limit to the number of occurrences removed.

String & String::remove ( const String str,
int  start = 0,
int  count = -1 
)

Removes 'count' occurrences of the string 'str' after position 'start'.

If 'count' is set -1 there is no limit to the number of occurrences removed.

String & String::remove ( int  start,
int  count 
)

Removes 'count' characters starting at position 'start'.

String & String::reverse (  ) 

Reverses the order of the characters in the string.

String & String::normalizeSlashes (  ) 

Transform \ slashes in / slashes and removes duplicates.

int String::count ( wchar_t  ch,
int  start = 0 
) const

Returns the number of occurrences of the given character after position 'start'.

int String::count ( const String str,
int  start = 0 
) const

Returns the number of occurrences of the given string after position 'start'.

int String::compare ( const String other  )  const

Performs a lexicographic comparison.

Returns < 0 if this string comes before 'other'. Returns > 0 if 'other' comes before this string. Returns 0 if the two strings are equal.

bool String::endsWith ( const String str  )  const

Returns true if a String ends with the specified String str.

bool String::startsWith ( const String str  )  const

Returns true if a String starts with the specified String str.

bool String::endsWith ( wchar_t  ch  )  const

Returns true if a String ends with the specified character.

bool String::startsWith ( wchar_t  ch  )  const

Returns true if a String starts with the specified character.

String & String::insert ( int  pos,
const String str 
)

Inserts str at position pos.

String & String::insert ( int  pos,
wchar_t  ch,
int  count = 1 
)

Inserts count characters ch starting at position pos.

String String::left ( int  count  )  const

Returns the count leftmost caracters of a String. If count is negative the function returns all but the abs(count) rightmost caracters.

String String::right ( int  count  )  const

Returns the count rightmost caracters of a String. If count is negative the function returns all but the abs(count) leftmost caracters.

String String::extractPath (  )  const

If the String contains a file path the function returns the path with trailing slash, without the file name.

String String::extractFileName (  )  const

If the String contains a file path the function returns the file name without the path.

String String::extractFileExtension ( bool  require_dot = true  )  const

If the String contains a file name or file path the function returns the extension of the file.

String & String::resize ( int  character_count  ) 

Resizes the string to the specified character count.

String String::substring ( int  start,
int  count = -1 
) const

Returns the count characters long substring starting a character index start. If count == -1 the returned substring will contain all the characters from start to the end of the String.

String & String::fill ( wchar_t  ch  ) 

Fills the string with the specified character ch.

String & String::trim ( wchar_t  ch  ) 

Removes the specified character ch from the beginning and the end of the String.

String & String::trim ( const String chars  ) 

Removes the characters contained in chars from the beginning and the end of the String.

String & String::trim (  ) 

Equivalent to trim("\n\r\t\v "), that is, removes all the tabs, spaces and new-lines from the beginning and end of a String.

void String::split ( wchar_t  separator,
std::vector< String > &  fields,
bool  remove_empty_fields = false 
) const

Splits a String into a set of fields. The fields are separated by the specified separator and are returned in fields.

void String::split ( const String separator_list,
std::vector< String > &  fields,
bool  remove_empty_fields = false 
) const

Splits a String into a set of fields. The fields are separated by the specified separator_list and are returned in fields.

void String::splitLines ( std::vector< String > &  lines  )  const

Splits a String into a set of Strings each of which contains a line.

String String::field ( wchar_t  separator,
int  field_index 
) const

Splits a String into a set of fields based on the specified separator and returns the filed at position field_index.

String & String::append ( const String other  ) 

Appends the specified String to another String.

String & String::append ( wchar_t  ch,
int  count = 1 
)

Appends count characters ch to another String.

String & String::prepend ( const String str  ) 

Prepends the specified String to another String.

String & String::prepend ( wchar_t  ch,
int  count 
)

Prepends count characters ch to another String.

int String::find ( wchar_t  ch,
int  start = 0 
) const

Searches for the specified character ch starting at position start and returns the index of the first occurence or -1 if no occurrence was found.

int String::find ( const String str,
int  start = 0 
) const

Searches for the specified String substr starting at position start and returns the index of the first occurence or -1 if no occurrence was found.

int String::findBackwards ( wchar_t  ch  )  const

Searches for the specified character starting from the end of the string and returns the index of the first occurence or -1 if no occurrence was found.

int String::findBackwards ( const String str  )  const

Searches for the specified String str from the end of the string and returns the index of the first occurence or -1 if no occurrence was found.

bool String::contains ( wchar_t  ch  )  const

Returns true if a String contains the specified character.

bool String::contains ( const String str  )  const

Returns true if a String contains the specified String.

void String::squeeze (  ) 

Minimizes the memory buffer used to store the String.

String String::fromInt ( int  value  )  [static]

Creates a string representing the given integer value.

String String::fromUInt ( unsigned int  value  )  [static]

Creates a string representing the given unsigned integer value.

String String::fromLongLong ( long long  value  )  [static]

Creates a string representing the given long long value.

String String::fromULongLong ( unsigned long long  value  )  [static]

Creates a string representing the given unsigned long long value.

String String::fromDouble ( double  value,
int  decimals = 6 
) [static]

Creates a string representing the given double value The value of 'decimals' can be between 0 and 20.

String String::fromStdString ( const std::string &  str  )  [static]

Initializes the string from a std::string using the fromAscii() function.

String String::fromStdWString ( const std::wstring &  str  )  [static]

Initializes the string from a std::string using the fromAscii() function.

String String::fromAscii ( const char *  str,
int  size = -1 
) [static]

Initializes the string from a 7 bit ascii string.

String String::fromUTF16BE ( const unsigned short *  str,
int  byte_count = -1 
) [static]

Accepts strings with and without UTF16 BE signature Supports natively the characters from the BMP, the other characters are substituted with '?' The size of the buffer pointed by 'str' must be at least 'byte_count' bytes large or null terminated.

String String::fromUTF16LE ( const unsigned short *  str,
int  byte_count = -1 
) [static]

Accepts strings with and without UTF16 LE signature Supports natively the characters from the BMP, the other characters are substituted with '?' The size of the buffer pointed by 'str' must be at least 'byte_count' bytes large or null terminated.

String String::fromUTF16 ( const unsigned short *  str,
int  byte_count = -1 
) [static]

str must have UTF16 LE or UTF16 BE signature The size of the buffer pointed by 'str' must be at least 'byte_count' bytes large or null terminated.

String String::fromUTF8 ( const char *  str,
int  byte_count = -1 
) [static]

Accepts strings with and without UTF8 signature.

String String::fromLatin1 ( const char *  str,
int  character_count = -1 
) [static]

The size of the buffer pointed by 'str' must be at least 'character_count' bytes large or null terminated.

int String::toInt ( bool  hex = false  )  const

Returns the int number represented by the string. The conversion is done using the standard atoi() function.

double String::toDouble (  )  const

Returns the double number represented by the string. The conversion is done using the standard atof() function.

float vl::String::toFloat (  )  const [inline]

Returns the float number represented by the string. The conversion is done using the standard atof() function.

std::string String::toStdString (  )  const

Returns a UTF8 encoded std::string.

std::wstring String::toStdWString (  )  const

Returns the std::wstring representation of a String.

void String::toAscii ( std::string &  ascii,
bool  translate_non_ascii_chars = true 
) const

Provides some basic character translation of code points outside of the ASCII range.

void String::toUTF8 ( std::vector< unsigned char > &  utf8,
bool  include_utf8_signature = true 
) const

Encodes the String into a UTF8 encoded string.

void String::toUTF8 ( std::string &  utf8,
bool  include_utf8_signature = true 
) const

Encodes the String into a UTF8 encoded std::string.

void String::toUTF16BE ( std::vector< unsigned char > &  utf16,
bool  include_utf16be_signature = true 
) const

Encodes the String into a UTF16 big endian encoded string.

void String::toUTF16LE ( std::vector< unsigned char > &  utf16,
bool  include_utf16le_signature = true 
) const

Encodes the String into a UTF16 little endian encoded string.

void String::toLatin1 ( std::vector< unsigned char > &  latin1  )  const

Encodes the String into a Latin1 encoded string.

String String::toLowerCase (  )  const

Returns the lower-case version of a String.

String String::toUpperCase (  )  const

Returns the upper-case version of a String.

bool vl::String::operator< ( const String other  )  const [inline]

Lexicographic sorting, equivalent to "compare(other) < 0".

String& vl::String::operator= ( const char *  str  )  [inline]

Equivalent to '*this = fromUTF8(str);'.

String& vl::String::operator= ( const std::string &  str  )  [inline]

Equivalent to '*this = fromUTF8(str.c_str());'.

String& vl::String::operator= ( const wchar_t *  wstr  )  [inline]

String& vl::String::operator= ( const std::wstring &  str  )  [inline]

String& vl::String::operator= ( const String other  )  [inline]

bool vl::String::operator== ( const String other  )  const [inline]

bool vl::String::operator== ( const std::string &  other  )  const [inline]

bool vl::String::operator== ( const std::wstring &  other  )  const [inline]

bool vl::String::operator== ( const char *  other  )  const [inline]

bool vl::String::operator== ( const wchar_t *  other  )  const [inline]

bool vl::String::operator!= ( const String other  )  const [inline]

bool vl::String::operator!= ( const std::string &  other  )  const [inline]

bool vl::String::operator!= ( const std::wstring &  other  )  const [inline]

bool vl::String::operator!= ( const char *  other  )  const [inline]

bool vl::String::operator!= ( const wchar_t *  other  )  const [inline]

String& vl::String::operator+= ( wchar_t  ch  )  [inline]

String vl::String::operator+ ( wchar_t  ch  )  const [inline]

String& vl::String::operator+= ( const String other  )  [inline]

String vl::String::operator+ ( const String other  )  const [inline]

void vl::String::acquireData (  )  const [inline]

Acquires a private copy of the data if the string has been copied from another one.

void vl::String::createData (  )  const [inline, protected]


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

Visualization Library v2010.06 Reference Documentation
Copyright 2005-2009 Michele Bosi. All rights reserved.
Updated on Tue Jun 1 00:57:28 2010.
Permission is granted to use this page to write and publish articles regarding Visualization Library.