# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions

# 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.
String & | clear ()
| 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`.
String & | replace (wchar_t old_ch, wchar_t new_ch)
| Replaces the character 'old_ch' with 'new_ch'.
String & | replace (int start, int count, wchar_t ch)
| Replaces `count` characters starting at position `start` with `ch`.
String & | replace (int start, int count, const String &str)
| Equivalent to remove(start, count); insert(start, str);.
String & | replace (const String &oldstr, const String &newstr, bool case_sensitive=true)
| Replaces all the occurrences of oldstr with newstr.
String & | remove (wchar_t ch, int start=0, int count=-1)
| Removes 'count' occurrences of the character 'ch' after position 'start'.
String & | remove (const String &str, int start=0, int count=-1)
| Removes 'count' occurrences of the string 'str' after position 'start'.
String & | remove (int start, int count)
| Removes 'count' characters starting at position 'start'.
String & | reverse ()
| Reverses the order of the characters in the string.
String & | normalizeSlashes ()
| 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.
String & | insert (int pos, const String &str)
| Inserts `str` at position `pos`.
String & | insert (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.
String & | resize (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.
String & | fill (wchar_t ch)
| Fills the string with the specified character `ch`.
String & | trim (wchar_t ch)
| Removes the specified character `ch` from the beginning and the end of the String.
String & | trim (const String &chars)
| Removes the characters contained in `chars` from the beginning and the end of the 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 | 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`.
String & | append (const String &other)
| Appends the specified String to another String.
String & | append (wchar_t ch, int count=1)
| Appends `count` characters `ch` to another String.
String & | prepend (const String &str)
| Prepends the specified String to another String.
String & | prepend (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 occurrence or -1 if no occurrence was found.
int | find (const String &substr, int start=0) const
| Searches for the specified string `substr` starting at position `start` and returns the index of the first occurrence or -1 if no occurrence was found.
int | findInLargeText (const String &substr, int start=0) const
| Searches for the specified string `substr` starting at position `start` and returns the index of the first occurrence or -1 if no occurrence was found.
int | findBackwards (wchar_t ch) const
| Searches for the specified character chstarting from the end of the string and returns the index of the first occurrence or -1 if no occurrence was found.
int | findBackwards (const String &str) const
| Searches for the specified String chstr from the end of the string and returns the index of the first occurrence 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"`.
String & | operator= (const char *str)
| Equivalent to '*this = fromUTF8(str);'.
String & | operator= (const std::string &str)
| Equivalent to '*this = fromUTF8(str.c_str());'.
String & | operator= (const wchar_t *wstr)
String & | operator= (const std::wstring &str)
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
String & | operator+= (wchar_t ch)
String | operator+ (wchar_t ch) const
String & | operator+= (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:

- Lazy data copy on write that speeds up String manipulation, copy and comparison.
- Encoding and decoding functions for UTF8, UTF16 BE, UTF16 LE, Latin1 and Ascii, with and without signature.
- Interoperability to and from std::string, std::wstring, char* and wchar_t*.
- Unicode to Ascii character translation when possible.
- Extended character case manipulation for most UTF16/BMP codes.
- Advanced string manipulation routines like line/field splitting, comparison, search, replace, trimming, matching, counting, filling etc.
- Fast substring find function based on the Quick Find algorithm.
- Loads text from a variety of formats and sources.

Definition at line 62 of file String.hpp.

## Constructor & Destructor Documentation

String::String | ( | ) |

Constructor.

Definition at line 46 of file String.cpp.

References acquireData().

Referenced by extractFileExtension(), extractFileName(), extractPath(), loadText(), split(), splitLines(), substring(), toLowerCase(), and toUpperCase().

String::String | ( | const String & | other ) |

Constructor.

Definition at line 53 of file String.cpp.

References operator=().

String::String | ( | const wchar_t * | wstr ) |

Constructor.

Definition at line 58 of file String.cpp.

References acquireData().

String::String | ( | const char * | str ) |

Constructor.

Definition at line 67 of file String.cpp.

References acquireData().

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

Constructor.

Definition at line 76 of file String.cpp.

References acquireData(), and count().

## Member Function Documentation

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

Detects the encoding.

Definition at line 1362 of file String.cpp.

References vl::SE_UTF16_BE, vl::SE_UTF16_LE, vl::SE_UTF32_BE, vl::SE_UTF32_LE, and vl::SE_UTF8.

Referenced by loadText().

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

Loads a String from the specified path.

Definition at line 85 of file String.cpp.

References vl::defFileSystem(), vl::Log::error(), vl::ref< T >::get(), vl::FileSystem::locateFile(), and String().

Referenced by vl::Terrain::init(), loadText(), and vl::GLSLShader::setSource().

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

Loads a String from the specified path.

Definition at line 72 of file String.hpp.

References loadText().

Referenced by loadText().

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

Loads a String from the specified VirtualFile.

Definition at line 97 of file String.cpp.

References vl::VirtualFile::close(), vl::VirtualFile::load(), loadText(), and String().

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

Loads a String from the specified memory buffer.

Definition at line 113 of file String.cpp.

References detectEncoding(), vl::Log::error(), fromAscii(), fromLatin1(), fromUTF16BE(), fromUTF16LE(), fromUTF8(), vl::SE_ASCII, vl::SE_LATIN1, vl::SE_Unknown, vl::SE_UTF16_BE, vl::SE_UTF16_LE, vl::SE_UTF32_BE, vl::SE_UTF32_LE, vl::SE_UTF8, and String().

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

Returns the upper-case version of the specified character.

Definition at line 1379 of file String.cpp.

Referenced by toUpperCase().

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

Returns the lower-case version of the specified character.

Definition at line 1392 of file String.cpp.

Referenced by toLowerCase().

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

Returns the title-case version of the specified character.

Definition at line 1405 of file String.cpp.

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*"`.

Definition at line 1324 of file String.cpp.

References empty(), endsWith(), vl::Log::error(), find(), length(), remove(), and startsWith().

Referenced by vl::VirtualDirectory::listFilesRecursive().

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

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

Definition at line 93 of file String.hpp.

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

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

Definition at line 1418 of file String.cpp.

Referenced by vl::ObjLoader::loadOBJ().

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

Returns the 0-terminated utf16 string.

Definition at line 121 of file String.hpp.

Referenced by vl::DiskDirectory::exists(), vl::log_failed_check(), operator==(), and vlWin32::Win32Context::setWindowTitle().

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

Returns the 0-terminated utf16 string.

Definition at line 124 of file String.hpp.

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

Returns the length of the string.

Definition at line 127 of file String.hpp.

Referenced by append(), compare(), count(), vl::DiskDirectory::diskSubDir(), endsWith(), vl::Say::euronotation(), field(), fill(), filterStrings(), find(), findBackwards(), findInLargeText(), insert(), left(), normalizeSlashes(), operator==(), vl::Say::parse(), vl::Say::pipeline(), vl::Text::rawboundingRect(), vl::ReadPixels::readPixels(), remove(), vl::Text::renderText(), replace(), reverse(), right(), vl::ZippedDirectory::setPath(), vl::MemoryDirectory::setPath(), split(), splitLines(), startsWith(), substring(), toLatin1(), toLowerCase(), toStdWString(), toUpperCase(), toUTF16BE(), toUTF16LE(), toUTF8(), and trim().

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

Returns `true` if length() == 0.

Definition at line 130 of file String.hpp.

References vl::length().

Referenced by vl::GLSLShader::compile(), count(), vl::DiskDirectory::diskSubDir(), endsWith(), extractFileExtension(), extractFileName(), extractPath(), filterStrings(), find(), findBackwards(), findInLargeText(), vl::LoadWriterManager::findLoader(), vl::LoadWriterManager::findWriter(), vl::Terrain::init(), insert(), vl::GLSLProgram::linkProgram(), vl::loadImagesFromDir(), vl::ObjLoader::loadObjMaterials(), vl::FileSystem::locateFile(), operator==(), vl::StandardLog::printImplementation(), vl::GLSLProgram::programBinary(), vl::PlyLoader::readHeader(), vl::TextStream::readLineCR(), vl::TextStream::readLineLF(), vl::TextStream::readQuotedString(), vl::TextStream::readString(), vl::StandardLog::setLogFile(), vl::ZippedDirectory::setPath(), vl::VirtualDirectory::setPath(), vl::MemoryDirectory::setPath(), split(), splitLines(), squeeze(), startsWith(), substring(), toAscii(), toDouble(), toInt(), toLatin1(), toLowerCase(), toStdString(), toStdWString(), toUpperCase(), toUTF16BE(), toUTF16LE(), and toUTF8().

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

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

Definition at line 133 of file String.hpp.

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

Clears the string.

Definition at line 136 of file String.hpp.

Referenced by fromUTF16(), vl::TextStream::readLine(), vl::TextStream::readLineCR(), vl::TextStream::readLineLF(), vl::TextStream::readQuotedString(), vl::TextStream::readString(), and vl::Molecule::reset().

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

Returns the character at position `i`.

Definition at line 139 of file String.hpp.

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

Returns the character at position `i`.

Definition at line 142 of file String.hpp.

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

Replaces the character 'old_ch' with 'new_ch'.

Definition at line 614 of file String.cpp.

References acquireData(), and length().

Referenced by normalizeSlashes(), and replace().

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

Replaces `count` characters starting at position `start` with `ch`.

Definition at line 598 of file String.cpp.

References acquireData(), count(), and length().

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

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

Definition at line 574 of file String.cpp.

References count(), and insert().

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

Replaces all the occurrences of oldstr with newstr.

Definition at line 581 of file String.cpp.

References acquireData(), find(), length(), replace(), and toLowerCase().

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.

Definition at line 501 of file String.cpp.

References acquireData(), and length().

Referenced by filterStrings(), and vl::Say::pipeline().

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.

Definition at line 468 of file String.cpp.

References acquireData(), count(), find(), and length().

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

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

Definition at line 482 of file String.cpp.

References acquireData(), and length().

String & String::reverse | ( | ) |

Reverses the order of the characters in the string.

Definition at line 520 of file String.cpp.

References acquireData(), count(), and length().

String & String::normalizeSlashes | ( | ) |

Transform \ slashes in / slashes and removes duplicates.

Definition at line 533 of file String.cpp.

References length(), and replace().

Referenced by vl::MemoryDirectory::addFile(), extractPath(), vl::ZippedDirectory::init(), vl::ZippedDirectory::setPath(), vl::VirtualFile::setPath(), vl::VirtualDirectory::setPath(), vl::MemoryDirectory::setPath(), and vl::VirtualDirectory::translatePath().

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

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

Definition at line 624 of file String.cpp.

References empty(), and length().

Referenced by append(), insert(), remove(), replace(), reverse(), vl::GLSLShader::setSource(), and String().

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

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

Definition at line 637 of file String.cpp.

References empty(), find(), and length().

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.

Definition at line 649 of file String.cpp.

References createData(), length(), and vl::min().

bool String::endsWith | ( | const String & | str ) | const

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

Definition at line 663 of file String.cpp.

References empty(), and length().

Referenced by filterStrings(), vl::ZippedDirectory::init(), vl::isJPG(), vl::isTGA(), vl::ZippedDirectory::setPath(), vl::VirtualDirectory::setPath(), vl::MemoryDirectory::setPath(), and vl::VirtualDirectory::translatePath().

bool String::startsWith | ( | const String & | str ) | const

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

Definition at line 678 of file String.cpp.

References empty(), and length().

Referenced by vl::MemoryDirectory::addFile(), vl::DiskDirectory::diskSubDir(), filterStrings(), vl::ObjLoader::loadObjMaterials(), vl::PlyLoader::readHeader(), vl::ZippedDirectory::setPath(), vl::MemoryDirectory::setPath(), and vl::VirtualDirectory::translatePath().

bool String::endsWith | ( | wchar_t | ch ) | const

Returns `true` if a String ends with the specified character.

Definition at line 695 of file String.cpp.

References empty(), and length().

bool String::startsWith | ( | wchar_t | ch ) | const

Returns `true` if a String starts with the specified character.

Definition at line 704 of file String.cpp.

References empty(), and length().

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

Inserts `str` at position `pos`.

Definition at line 739 of file String.cpp.

References acquireData(), append(), empty(), and length().

Referenced by vl::Say::euronotation(), vl::Say::format(), vl::Say::pipeline(), prepend(), and replace().

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

Inserts `count` characters `ch` starting at position `pos`.

Definition at line 755 of file String.cpp.

References acquireData(), append(), count(), and length().

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.

Definition at line 772 of file String.cpp.

References length(), and substring().

Referenced by vl::ZippedDirectory::listSubDirs(), vl::MemoryDirectory::listSubDirs(), vl::ZippedDirectory::setPath(), vl::VirtualDirectory::setPath(), vl::MemoryDirectory::setPath(), and vl::VirtualDirectory::translatePath().

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.

Definition at line 780 of file String.cpp.

References length(), and substring().

Referenced by vl::DiskDirectory::diskSubDir(), vl::ZippedDirectory::listSubDirs(), vl::MemoryDirectory::listSubDirs(), vl::ZippedDirectory::setPath(), vl::MemoryDirectory::setPath(), and vl::VirtualDirectory::translatePath().

String String::extractPath | ( | ) | const

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

Definition at line 788 of file String.cpp.

References empty(), findBackwards(), normalizeSlashes(), String(), and substring().

Referenced by vl::isDAT(), vl::ZippedDirectory::listSubDirs(), vl::MemoryDirectory::listSubDirs(), vl::loadAC3D(), vl::loadDAT(), vl::ObjLoader::loadOBJ(), and vl::A3DSLoader::readMapChunk().

String String::extractFileName | ( | ) | const

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

Definition at line 803 of file String.cpp.

References empty(), findBackwards(), String(), and substring().

Referenced by vl::FileSystem::locateFile().

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.

Definition at line 815 of file String.cpp.

References empty(), findBackwards(), String(), and substring().

Referenced by vl::LoadWriterManager::findLoader(), and vl::LoadWriterManager::findWriter().

String & String::resize | ( | int | character_count ) |

Resizes the string to the specified character count.

Definition at line 145 of file String.cpp.

References acquireData().

Referenced by vl::ZippedDirectory::init(), and vl::Say::pipeline().

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.

Definition at line 152 of file String.cpp.

References acquireData(), empty(), length(), and String().

Referenced by extractFileExtension(), extractFileName(), extractPath(), left(), right(), and trim().

String & String::fill | ( | wchar_t | ch ) |

Fills the string with the specified character `ch`.

Definition at line 297 of file String.cpp.

References acquireData(), and length().

String & String::trim | ( | wchar_t | ch ) |

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

Definition at line 321 of file String.cpp.

References acquireData(), length(), and substring().

Referenced by vl::atomType(), vl::ObjLoader::loadObjMaterials(), vl::PlyLoader::readHeader(), vl::ZippedDirectory::setPath(), vl::VirtualDirectory::setPath(), and vl::MemoryDirectory::setPath().

String & String::trim | ( | const String & | chars ) |

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

Definition at line 306 of file String.cpp.

References acquireData(), length(), and trim().

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.

Definition at line 342 of file String.cpp.

References acquireData().

Referenced by vl::ObjLoader::loadOBJ(), and trim().

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`.

Definition at line 385 of file String.cpp.

References empty(), length(), and String().

Referenced by vl::ZippedDirectory::listSubDirs(), vl::MemoryDirectory::listSubDirs(), and vl::ObjTexture::parseLine().

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`.

Definition at line 351 of file String.cpp.

References contains(), empty(), length(), and String().

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

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

Definition at line 419 of file String.cpp.

References empty(), length(), and String().

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`.

Definition at line 452 of file String.cpp.

References length().

Referenced by vl::ObjLoader::loadObjMaterials(), and vl::PlyLoader::readHeader().

String & String::append | ( | const String & | other ) |

Appends the specified String to another String.

Definition at line 555 of file String.cpp.

References acquireData(), and length().

Referenced by insert(), operator+(), and vl::Say::pipeline().

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

Appends `count` characters `ch` to another String.

Definition at line 546 of file String.cpp.

References acquireData(), and count().

String & String::prepend | ( | const String & | str ) |

Prepends the specified String to another String.

Definition at line 564 of file String.cpp.

References insert().

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

Prepends `count` characters `ch` to another String.

Definition at line 569 of file String.cpp.

References insert().

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 occurrence or -1 if no occurrence was found.

Definition at line 216 of file String.cpp.

References empty(), and length().

Referenced by vl::ResourceLoadWriter::canLoad(), vl::ResourceLoadWriter::canWrite(), contains(), count(), filterStrings(), vl::Say::pipeline(), remove(), and replace().

int String::find | ( | const String & | substr,
|  | int | start = `0`
| ) |  | const

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

Definition at line 264 of file String.cpp.

References empty(), length(), and vl::max().

int String::findInLargeText | ( | const String & | substr,
|  | int | start = `0`
| ) |  | const

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

This function can be substantially quicker that find() when searching in large texts but it can be slower than find() for small ones.

Definition at line 250 of file String.cpp.

References empty(), and length().

int String::findBackwards | ( | wchar_t | ch ) | const

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

Definition at line 176 of file String.cpp.

References empty(), and length().

Referenced by extractFileExtension(), extractFileName(), and extractPath().

int String::findBackwards | ( | const String & | str ) | const

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

Definition at line 188 of file String.cpp.

References empty(), and length().

bool String::contains | ( | wchar_t | ch ) | const

Returns true if a String contains the specified character.

Definition at line 211 of file String.cpp.

References find().

Referenced by vl::Say::euronotation(), vl::Say::pipeline(), and split().

bool String::contains | ( | const String & | str ) | const

Returns true if a String contains the specified String.

Definition at line 228 of file String.cpp.

References find().

void String::squeeze | ( | ) |

Minimizes the memory buffer used to store the String.

Definition at line 289 of file String.cpp.

References empty().

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

Creates a string representing the given integer value.

Definition at line 1027 of file String.cpp.

References fromAscii().

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

Creates a string representing the given unsigned integer value.

Definition at line 1035 of file String.cpp.

References fromAscii().

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

Creates a string representing the given long long value.

Definition at line 1043 of file String.cpp.

References fromAscii().

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

Creates a string representing the given unsigned long long value.

Definition at line 1051 of file String.cpp.

References fromAscii().

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.

Definition at line 1059 of file String.cpp.

References fromAscii().

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

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

Definition at line 839 of file String.cpp.

References fromAscii().

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

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

Definition at line 828 of file String.cpp.

References acquireData().

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

Initializes the string from a 7 bit ascii string.

Definition at line 844 of file String.cpp.

References acquireData().

Referenced by fromDouble(), fromInt(), fromLongLong(), fromStdString(), fromUInt(), fromULongLong(), and loadText().

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.

Definition at line 865 of file String.cpp.

References acquireData(), and VL_COMPILE_TIME_CHECK.

Referenced by fromUTF16(), and loadText().

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.

Definition at line 901 of file String.cpp.

References acquireData(), and VL_COMPILE_TIME_CHECK.

Referenced by fromUTF16(), and loadText().

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.

Definition at line 937 of file String.cpp.

References acquireData(), clear(), vl::Log::error(), fromUTF16BE(), and fromUTF16LE().

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

Accepts strings with and without UTF8 signature.

Definition at line 955 of file String.cpp.

References acquireData().

Referenced by vl::ZippedDirectory::init(), loadText(), vl::TextStream::readLine(), vl::TextStream::readLineCR(), and vl::TextStream::readLineLF().

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.

Definition at line 1012 of file String.cpp.

References acquireData().

Referenced by loadText().

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

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

Definition at line 1299 of file String.cpp.

References empty(), and toStdString().

Referenced by vl::Image::contrastHounsfieldAuto(), vl::ObjLoader::loadObjMaterials(), and vl::PlyLoader::readHeader().

double String::toDouble | ( | ) | const

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

Definition at line 1315 of file String.cpp.

References empty(), and toStdString().

Referenced by vl::ObjLoader::loadObjMaterials().

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

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

Definition at line 339 of file String.hpp.

Referenced by vl::Image::contrastHounsfieldAuto(), and vl::ObjLoader::loadObjMaterials().

std::string String::toStdString | ( | ) | const

Returns a UTF8 encoded std::string.

Definition at line 1103 of file String.cpp.

References empty(), and toUTF8().

Referenced by vl::atomType(), vl::Image::Image(), vl::ZippedDirectory::init(), vlGLUT::GLUTWindow::initGLUTWindow(), vl::load3DS(), vl::loadBMP(), vl::loadDDS(), vl::loadDICOM(), vl::loadImage(), vl::loadJPG(), vl::ObjLoader::loadOBJ(), vl::ObjLoader::loadObjMaterials(), vl::loadPNG(), vl::loadTGA(), vl::ObjTexture::print(), vl::StandardLog::printImplementation(), vl::StandardLog::setLogFile(), vl::GLSLShader::setSource(), vlWX::WXGLCanvas::setWindowTitle(), vlSDL::SDLWindow::setWindowTitle(), vlQt4::Qt4Widget::setWindowTitle(), vlGLUT::GLUTWindow::setWindowTitle(), toDouble(), and toInt().

std::wstring String::toStdWString | ( | ) | const

Returns the std::wstring representation of a String.

Definition at line 1091 of file String.cpp.

References empty(), and length().

Referenced by vlWX::WXGLCanvas::setWindowTitle().

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.

Definition at line 1121 of file String.cpp.

References empty().

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

Encodes the String into a UTF8 encoded string.

Definition at line 1165 of file String.cpp.

References empty(), and length().

Referenced by vl::DiskFile::exists(), vl::DiskDirectory::exists(), vl::DiskFile::open(), vl::DiskFile::size(), toStdString(), and toUTF8().

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

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

Definition at line 1153 of file String.cpp.

References toUTF8().

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

Encodes the String into a UTF16 big endian encoded string.

Definition at line 1213 of file String.cpp.

References empty(), and length().

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

Encodes the String into a UTF16 little endian encoded string.

Definition at line 1239 of file String.cpp.

References empty(), and length().

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

Encodes the String into a Latin1 encoded string.

Definition at line 1265 of file String.cpp.

References empty(), and length().

String String::toLowerCase | ( | ) | const

Returns the lower-case version of a String.

Definition at line 713 of file String.cpp.

References acquireData(), empty(), getLowerCase(), length(), and String().

Referenced by vl::ResourceLoadWriter::canLoad(), vl::ResourceLoadWriter::canWrite(), vl::LoadWriterManager::findLoader(), vl::LoadWriterManager::findWriter(), vl::isJPG(), vl::isTGA(), vl::loadImagesFromDir(), replace(), vl::ResourceLoadWriter::setLoadExtensions(), and vl::ResourceLoadWriter::setWriteExtensions().

String String::toUpperCase | ( | ) | const

Returns the upper-case version of a String.

Definition at line 726 of file String.cpp.

References acquireData(), empty(), getUpperCase(), length(), and String().

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

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

Definition at line 372 of file String.hpp.

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

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

Definition at line 378 of file String.hpp.

Referenced by String().

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

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

Definition at line 385 of file String.hpp.

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

Definition at line 391 of file String.hpp.

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

Definition at line 404 of file String.hpp.

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

Definition at line 418 of file String.hpp.

References empty(), vl::length(), length(), and ptr().

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

Definition at line 440 of file String.hpp.

References vl::length().

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

Definition at line 455 of file String.hpp.

References vl::length().

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

Definition at line 470 of file String.hpp.

References vl::length().

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

Definition at line 481 of file String.hpp.

References vl::length().

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

Definition at line 492 of file String.hpp.

References vl::operator==().

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

Definition at line 497 of file String.hpp.

References vl::operator==().

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

Definition at line 502 of file String.hpp.

References vl::operator==().

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

Definition at line 507 of file String.hpp.

References vl::operator==().

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

Definition at line 512 of file String.hpp.

References vl::operator==().

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

Definition at line 517 of file String.hpp.

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

Definition at line 524 of file String.hpp.

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

Definition at line 531 of file String.hpp.

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

Definition at line 536 of file String.hpp.

References append().

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

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

Definition at line 544 of file String.hpp.

Referenced by append(), fill(), fromAscii(), fromLatin1(), fromStdWString(), fromUTF16(), fromUTF16BE(), fromUTF16LE(), fromUTF8(), insert(), remove(), replace(), resize(), reverse(), String(), substring(), toLowerCase(), toUpperCase(), and trim().

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

Definition at line 553 of file String.hpp.

Referenced by compare().

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

- D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlCore/String.hpp
- D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlCore/String.cpp

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:36.
Permission is granted to use this page to write and publish articles regarding Visualization Library.