Visualization Library 2.0.0-b3

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
vl::String Class Reference

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

#include <String.hpp>

Public Member Functions

 String ()
 Constructor. More...
 
 String (const String &other)
 Constructor. More...
 
 String (const wchar_t *wstr)
 Constructor. More...
 
 String (const char *str)
 Constructor. More...
 
 String (const std::string &str)
 Constructor. More...
 
 String (const std::wstring &str)
 Constructor. More...
 
 String (wchar_t ch, int count=1)
 Constructor. More...
 
const wchar_t * ptr () const
 Returns the 0-terminated utf16 string. More...
 
wchar_t * ptr ()
 Returns the 0-terminated utf16 string. More...
 
int length () const
 Returns the length of the string. More...
 
bool empty () const
 Returns true if length() == 0. More...
 
bool null () const
 Returns true if the String has never been assigned or resized. More...
 
Stringclear ()
 Clears the string. More...
 
const wchar_t & operator[] (int i) const
 Returns the character at position i. More...
 
wchar_t & operator[] (int i)
 Returns the character at position i. More...
 
Stringreplace (wchar_t old_ch, wchar_t new_ch)
 Replaces the character 'old_ch' with 'new_ch'. More...
 
Stringreplace (int start, int count, wchar_t ch)
 Replaces count characters starting at position start with ch. More...
 
Stringreplace (int start, int count, const String &str)
 Equivalent to remove(start, count); insert(start, str);. More...
 
Stringreplace (const String &oldstr, const String &newstr, bool case_sensitive=true)
 Replaces all the occurrences of oldstr with newstr. More...
 
Stringremove (wchar_t ch, int start=0, int count=-1)
 Removes 'count' occurrences of the character 'ch' after position 'start'. More...
 
Stringremove (const String &str, int start=0, int count=-1)
 Removes 'count' occurrences of the string 'str' after position 'start'. More...
 
Stringremove (int start, int count)
 Removes 'count' characters starting at position 'start'. More...
 
Stringreverse ()
 Reverses the order of the characters in the string. More...
 
StringnormalizeSlashes ()
 Transform \ slashes in / slashes and removes duplicates. More...
 
int count (wchar_t ch, int start=0) const
 Returns the number of occurrences of the given character after position 'start'. More...
 
int count (const String &str, int start=0) const
 Returns the number of occurrences of the given string after position 'start'. More...
 
int compare (const String &other) const
 Performs a lexicographic comparison. More...
 
bool endsWith (const String &str) const
 Returns true if a String ends with the specified String str. More...
 
bool startsWith (const String &str) const
 Returns true if a String starts with the specified String str. More...
 
bool endsWith (wchar_t ch) const
 Returns true if a String ends with the specified character. More...
 
bool startsWith (wchar_t ch) const
 Returns true if a String starts with the specified character. More...
 
Stringinsert (int pos, const String &str)
 Inserts str at position pos. More...
 
Stringinsert (int pos, wchar_t ch, int count=1)
 Inserts count characters ch starting at position pos. More...
 
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. More...
 
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. More...
 
String extractPath () const
 If the String contains a file path the function returns the path with trailing slash, without the file name. More...
 
String extractFileName () const
 If the String contains a file path the function returns the file name without the path. More...
 
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. More...
 
Stringresize (int character_count)
 Resizes the string to the specified character count. More...
 
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. More...
 
Stringfill (wchar_t ch)
 Fills the string with the specified character ch. More...
 
Stringtrim (wchar_t ch)
 Removes the specified character ch from the beginning and the end of the String. More...
 
Stringtrim (const String &chars)
 Removes the characters contained in chars from the beginning and the end of the String. More...
 
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. More...
 
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. More...
 
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. More...
 
void splitLines (std::vector< String > &lines) const
 Splits a String into a set of Strings each of which contains a line. More...
 
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. More...
 
Stringappend (const String &other)
 Appends the specified String to another String. More...
 
Stringappend (wchar_t ch, int count=1)
 Appends count characters ch to another String. More...
 
Stringprepend (const String &str)
 Prepends the specified String to another String. More...
 
Stringprepend (wchar_t ch, int count)
 Prepends count characters ch to another String. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
bool contains (wchar_t ch) const
 Returns true if a String contains the specified character. More...
 
bool contains (const String &str) const
 Returns true if a String contains the specified String. More...
 
void squeeze ()
 Minimizes the memory buffer used to store the String. More...
 
int toInt (bool hex=false) const
 Returns the int number represented by the string. The conversion is done using the standard atoi() function. More...
 
double toDouble () const
 Returns the double number represented by the string. The conversion is done using the standard atof() function. More...
 
float toFloat () const
 Returns the float number represented by the string. The conversion is done using the standard atof() function. More...
 
std::string toStdString () const
 Returns a UTF8 encoded std::string. More...
 
std::wstring toStdWString () const
 Returns the std::wstring representation of a String. More...
 
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. More...
 
void toUTF8 (std::vector< unsigned char > &utf8, bool include_utf8_signature=true) const
 Encodes the String into a UTF8 encoded string. More...
 
void toUTF8 (std::string &utf8, bool include_utf8_signature=true) const
 Encodes the String into a UTF8 encoded std::string. More...
 
void toUTF16BE (std::vector< unsigned char > &utf16, bool include_utf16be_signature=true) const
 Encodes the String into a UTF16 big endian encoded string. More...
 
void toUTF16LE (std::vector< unsigned char > &utf16, bool include_utf16le_signature=true) const
 Encodes the String into a UTF16 little endian encoded string. More...
 
void toLatin1 (std::vector< unsigned char > &latin1) const
 Encodes the String into a Latin1 encoded string. More...
 
String toLowerCase () const
 Returns the lower-case version of a String. More...
 
String toUpperCase () const
 Returns the upper-case version of a String. More...
 
bool operator< (const String &other) const
 Lexicographic sorting, equivalent to "compare(other) < 0". More...
 
Stringoperator= (const char *str)
 Equivalent to '*this = fromUTF8(str);'. More...
 
Stringoperator= (const std::string &str)
 Equivalent to '*this = fromUTF8(str.c_str());'. More...
 
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. More...
 

Static Public Member Functions

static EStringEncoding detectEncoding (const void *str, int byte_count, EStringEncoding encoding=VL_PLATFORM_DEFAULT_ENCODING)
 Detects the encoding. More...
 
static String loadText (const String &path, EStringEncoding encoding=VL_PLATFORM_DEFAULT_ENCODING)
 Loads a String from the specified path. More...
 
static String loadText (const char *path, EStringEncoding encoding=VL_PLATFORM_DEFAULT_ENCODING)
 Loads a String from the specified path. More...
 
static String loadText (VirtualFile *file, EStringEncoding encoding=VL_PLATFORM_DEFAULT_ENCODING)
 Loads a String from the specified VirtualFile. More...
 
static String loadText (void *data, int bytes, EStringEncoding encoding=VL_PLATFORM_DEFAULT_ENCODING)
 Loads a String from the specified memory buffer. More...
 
static unsigned short getUpperCase (unsigned short ch)
 Returns the upper-case version of the specified character. More...
 
static unsigned short getLowerCase (unsigned short ch)
 Returns the lower-case version of the specified character. More...
 
static unsigned short getTitleCase (unsigned short ch)
 Returns the title-case version of the specified character. More...
 
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*". More...
 
static wchar_t platformSlash ()
 Returns '\' under windows and '/' under Linux and Mac. More...
 
static std::string trimStdString (const std::string &text)
 Remove the spaces before and after an std::string. More...
 
static String fromPointer (const void *value)
 Creates a string representing the given pointer. More...
 
static String fromInt (int value)
 Creates a string representing the given integer value. More...
 
static String fromUInt (unsigned int value)
 Creates a string representing the given unsigned integer value. More...
 
static String fromLongLong (long long value)
 Creates a string representing the given long long value. More...
 
static String fromULongLong (unsigned long long value)
 Creates a string representing the given unsigned long long value. More...
 
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. More...
 
static String fromStdString (const std::string &str, bool utf8=true)
 Initializes the string from a std::string using fromUTF() if utf8 == true (default) otherwise uses fromAscii(). More...
 
static String fromStdWString (const std::wstring &str)
 Initializes the string from a std::string using the fromAscii() function. More...
 
static String fromAscii (const char *str, int size=-1)
 Initializes the string from a 7 bit ascii string. More...
 
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. More...
 
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. More...
 
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. More...
 
static String fromUTF8 (const char *str, int byte_count=-1)
 Accepts strings with and without UTF8 signature. More...
 
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. More...
 
static String printf (const char *fmt,...)
 Returns a formatted string using the legacy printf syntax. The resulting string can be maximum 1024 + strlen(fmt) characters long. More...
 

Protected Member Functions

void createData () const
 

Detailed Description

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

The String class features:

Definition at line 62 of file String.hpp.

Constructor & Destructor Documentation

◆ String() [1/7]

String::String ( )

◆ String() [2/7]

String::String ( const String other)

Constructor.

Definition at line 54 of file String.cpp.

References operator=().

◆ String() [3/7]

String::String ( const wchar_t *  wstr)

Constructor.

Definition at line 59 of file String.cpp.

References acquireData().

◆ String() [4/7]

String::String ( const char *  str)

Constructor.

Definition at line 68 of file String.cpp.

References acquireData().

◆ String() [5/7]

vl::String::String ( const std::string &  str)
inline

Constructor.

Definition at line 118 of file String.hpp.

◆ String() [6/7]

vl::String::String ( const std::wstring &  str)
inline

Constructor.

Definition at line 121 of file String.hpp.

◆ String() [7/7]

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

Constructor.

Definition at line 77 of file String.cpp.

References acquireData(), and count().

Member Function Documentation

◆ acquireData()

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 556 of file String.hpp.

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

◆ append() [1/2]

String & String::append ( const String other)

Appends the specified String to another String.

Definition at line 597 of file String.cpp.

References acquireData(), and length().

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

◆ append() [2/2]

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

Appends count characters ch to another String.

Definition at line 588 of file String.cpp.

References acquireData(), and count().

◆ clear()

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

◆ compare()

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 691 of file String.cpp.

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

◆ contains() [1/2]

bool String::contains ( wchar_t  ch) const

Returns true if a String contains the specified character.

Definition at line 212 of file String.cpp.

References find().

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

◆ contains() [2/2]

bool String::contains ( const String str) const

Returns true if a String contains the specified String.

Definition at line 229 of file String.cpp.

References find().

◆ count() [1/2]

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 666 of file String.cpp.

References empty(), and length().

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

◆ count() [2/2]

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 679 of file String.cpp.

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

◆ createData()

void vl::String::createData ( ) const
inlineprotected

Definition at line 565 of file String.hpp.

References vl::length(), and resize().

Referenced by compare().

◆ detectEncoding()

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

Detects the encoding.

Definition at line 1415 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().

◆ empty()

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

◆ endsWith() [1/2]

bool String::endsWith ( const String str) const

◆ endsWith() [2/2]

bool String::endsWith ( wchar_t  ch) const

Returns true if a String ends with the specified character.

Definition at line 737 of file String.cpp.

References empty(), and length().

◆ extractFileExtension()

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 857 of file String.cpp.

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

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

◆ extractFileName()

String String::extractFileName ( ) const

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

Definition at line 845 of file String.cpp.

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

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

◆ extractPath()

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 830 of file String.cpp.

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

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

◆ field()

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 453 of file String.cpp.

References length().

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

◆ fill()

String & String::fill ( wchar_t  ch)

Fills the string with the specified character ch.

Definition at line 298 of file String.cpp.

References acquireData(), and length().

◆ filterStrings()

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 1377 of file String.cpp.

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

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

◆ find() [1/2]

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 217 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().

◆ find() [2/2]

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 265 of file String.cpp.

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

◆ findBackwards() [1/2]

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 177 of file String.cpp.

References empty(), and length().

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

◆ findBackwards() [2/2]

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 189 of file String.cpp.

References empty(), and length().

◆ findInLargeText()

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 251 of file String.cpp.

References empty(), and length().

◆ fromAscii()

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

Initializes the string from a 7 bit ascii string.

Definition at line 889 of file String.cpp.

References acquireData().

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

◆ fromDouble()

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 1112 of file String.cpp.

References fromAscii().

Referenced by vl::Log::operator<<().

◆ fromInt()

String String::fromInt ( int  value)
static

Creates a string representing the given integer value.

Definition at line 1080 of file String.cpp.

References fromAscii().

Referenced by vl::Log::operator<<().

◆ fromLatin1()

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 1057 of file String.cpp.

References acquireData().

Referenced by loadText().

◆ fromLongLong()

String String::fromLongLong ( long long  value)
static

Creates a string representing the given long long value.

Definition at line 1096 of file String.cpp.

References fromAscii().

Referenced by vl::Log::operator<<().

◆ fromPointer()

String String::fromPointer ( const void *  value)
static

Creates a string representing the given pointer.

Definition at line 1072 of file String.cpp.

References fromAscii().

Referenced by vl::Log::operator<<().

◆ fromStdString()

String String::fromStdString ( const std::string &  str,
bool  utf8 = true 
)
static

Initializes the string from a std::string using fromUTF() if utf8 == true (default) otherwise uses fromAscii().

Definition at line 881 of file String.cpp.

References fromAscii(), and fromUTF8().

Referenced by vl::QtDirectory::listFiles(), vl::QtDirectory::listSubDirs(), vl::Log::operator<<(), and vl::VLXSerializer::resolvePath().

◆ fromStdWString()

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

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

Definition at line 870 of file String.cpp.

References acquireData().

◆ fromUInt()

String String::fromUInt ( unsigned int  value)
static

Creates a string representing the given unsigned integer value.

Definition at line 1088 of file String.cpp.

References fromAscii().

Referenced by vl::Log::operator<<().

◆ fromULongLong()

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

Creates a string representing the given unsigned long long value.

Definition at line 1104 of file String.cpp.

References fromAscii().

Referenced by vl::Log::operator<<().

◆ fromUTF16()

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 982 of file String.cpp.

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

◆ fromUTF16BE()

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 910 of file String.cpp.

References acquireData(), and vl::VL_COMPILE_TIME_CHECK().

Referenced by fromUTF16(), and loadText().

◆ fromUTF16LE()

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 946 of file String.cpp.

References acquireData(), and vl::VL_COMPILE_TIME_CHECK().

Referenced by fromUTF16(), and loadText().

◆ fromUTF8()

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

Accepts strings with and without UTF8 signature.

Definition at line 1000 of file String.cpp.

References acquireData().

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

◆ getLowerCase()

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

Returns the lower-case version of the specified character.

Definition at line 1445 of file String.cpp.

Referenced by toLowerCase().

◆ getTitleCase()

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

Returns the title-case version of the specified character.

Definition at line 1458 of file String.cpp.

◆ getUpperCase()

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

Returns the upper-case version of the specified character.

Definition at line 1432 of file String.cpp.

Referenced by toUpperCase().

◆ insert() [1/2]

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

Inserts str at position pos.

Definition at line 781 of file String.cpp.

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

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

◆ insert() [2/2]

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

Inserts count characters ch starting at position pos.

Definition at line 797 of file String.cpp.

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

◆ left()

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 814 of file String.cpp.

References length(), and substring().

Referenced by vl::MemoryDirectory::listSubDirs(), vl::ZippedDirectory::listSubDirs(), and vl::LoadWriterManager::loadResource().

◆ length()

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

◆ loadText() [1/4]

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

◆ loadText() [2/4]

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

Loads a String from the specified path.

Definition at line 72 of file String.hpp.

References loadText(), and VL_PLATFORM_DEFAULT_ENCODING.

Referenced by loadText().

◆ loadText() [3/4]

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

Loads a String from the specified VirtualFile.

Definition at line 98 of file String.cpp.

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

◆ loadText() [4/4]

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

◆ normalizeSlashes()

String & String::normalizeSlashes ( )

◆ null()

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

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

Definition at line 139 of file String.hpp.

◆ operator!=() [1/5]

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

Definition at line 504 of file String.hpp.

References vl::operator==().

◆ operator!=() [2/5]

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

Definition at line 509 of file String.hpp.

References vl::operator==().

◆ operator!=() [3/5]

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

Definition at line 514 of file String.hpp.

References vl::operator==().

◆ operator!=() [4/5]

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

Definition at line 519 of file String.hpp.

References vl::operator==().

◆ operator!=() [5/5]

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

Definition at line 524 of file String.hpp.

References vl::operator==().

◆ operator+() [1/2]

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

Definition at line 536 of file String.hpp.

◆ operator+() [2/2]

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

Definition at line 548 of file String.hpp.

References append().

◆ operator+=() [1/2]

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

Definition at line 529 of file String.hpp.

◆ operator+=() [2/2]

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

Definition at line 543 of file String.hpp.

◆ operator<()

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

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

Definition at line 384 of file String.hpp.

◆ operator=() [1/5]

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

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

Definition at line 390 of file String.hpp.

Referenced by String().

◆ operator=() [2/5]

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

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

Definition at line 397 of file String.hpp.

◆ operator=() [3/5]

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

Definition at line 403 of file String.hpp.

◆ operator=() [4/5]

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

Definition at line 416 of file String.hpp.

◆ operator=() [5/5]

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

Definition at line 422 of file String.hpp.

References acquireData().

◆ operator==() [1/5]

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

Definition at line 430 of file String.hpp.

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

◆ operator==() [2/5]

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

Definition at line 452 of file String.hpp.

References vl::length().

◆ operator==() [3/5]

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

Definition at line 467 of file String.hpp.

References vl::length().

◆ operator==() [4/5]

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

Definition at line 482 of file String.hpp.

References vl::length().

◆ operator==() [5/5]

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

Definition at line 493 of file String.hpp.

References vl::length().

◆ operator[]() [1/2]

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

Returns the character at position i.

Definition at line 145 of file String.hpp.

◆ operator[]() [2/2]

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

Returns the character at position i.

Definition at line 148 of file String.hpp.

◆ platformSlash()

static wchar_t vl::String::platformSlash ( )
inlinestatic

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

Definition at line 93 of file String.hpp.

◆ prepend() [1/2]

String & String::prepend ( const String str)

Prepends the specified String to another String.

Definition at line 606 of file String.cpp.

References insert().

◆ prepend() [2/2]

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

Prepends count characters ch to another String.

Definition at line 611 of file String.cpp.

References insert().

◆ printf()

String String::printf ( const char *  fmt,
  ... 
)
static

Returns a formatted string using the legacy printf syntax. The resulting string can be maximum 1024 + strlen(fmt) characters long.

Definition at line 1510 of file String.cpp.

Referenced by vl::VLXClassWrapper_Geometry::exportGeometry(), vl::GLSLShader::getShaderSource(), and vl::RaycastVolume::updateUniforms().

◆ ptr() [1/2]

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

◆ ptr() [2/2]

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

Returns the 0-terminated utf16 string.

Definition at line 130 of file String.hpp.

◆ remove() [1/3]

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 502 of file String.cpp.

References acquireData(), and length().

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

◆ remove() [2/3]

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 469 of file String.cpp.

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

◆ remove() [3/3]

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

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

Definition at line 483 of file String.cpp.

References acquireData(), and length().

◆ replace() [1/4]

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

Replaces the character 'old_ch' with 'new_ch'.

Definition at line 656 of file String.cpp.

References acquireData(), and length().

Referenced by normalizeSlashes(), and replace().

◆ replace() [2/4]

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

Replaces count characters starting at position start with ch.

Definition at line 640 of file String.cpp.

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

◆ replace() [3/4]

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

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

Definition at line 616 of file String.cpp.

References count(), and insert().

◆ replace() [4/4]

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

Replaces all the occurrences of oldstr with newstr.

Definition at line 623 of file String.cpp.

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

◆ resize()

String & String::resize ( int  character_count)

Resizes the string to the specified character count.

Definition at line 146 of file String.cpp.

References acquireData().

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

◆ reverse()

String & String::reverse ( )

Reverses the order of the characters in the string.

Definition at line 521 of file String.cpp.

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

◆ right()

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 822 of file String.cpp.

References length(), and substring().

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

◆ split() [1/2]

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 386 of file String.cpp.

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

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

◆ split() [2/2]

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 352 of file String.cpp.

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

◆ splitLines()

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 420 of file String.cpp.

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

Referenced by vl::GLSLShader::getShaderSource().

◆ squeeze()

void String::squeeze ( )

Minimizes the memory buffer used to store the String.

Definition at line 290 of file String.cpp.

References empty().

◆ startsWith() [1/2]

bool String::startsWith ( const String str) const

◆ startsWith() [2/2]

bool String::startsWith ( wchar_t  ch) const

Returns true if a String starts with the specified character.

Definition at line 746 of file String.cpp.

References empty(), and length().

◆ substring()

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 153 of file String.cpp.

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

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

◆ toAscii()

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 1174 of file String.cpp.

References empty().

◆ toDouble()

double String::toDouble ( ) const

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

Definition at line 1368 of file String.cpp.

References empty(), and toStdString().

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

◆ toFloat()

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 348 of file String.hpp.

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

◆ toInt()

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 1352 of file String.cpp.

References empty(), and toStdString().

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

◆ toLatin1()

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

Encodes the String into a Latin1 encoded string.

Definition at line 1318 of file String.cpp.

References empty(), and length().

◆ toLowerCase()

String String::toLowerCase ( ) const

◆ toStdString()

std::string String::toStdString ( ) const

◆ toStdWString()

std::wstring String::toStdWString ( ) const

Returns the std::wstring representation of a String.

Definition at line 1144 of file String.cpp.

References empty(), and length().

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

◆ toUpperCase()

String String::toUpperCase ( ) const

Returns the upper-case version of a String.

Definition at line 768 of file String.cpp.

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

◆ toUTF16BE()

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 1266 of file String.cpp.

References empty(), and length().

◆ toUTF16LE()

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 1292 of file String.cpp.

References empty(), and length().

◆ toUTF8() [1/2]

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

◆ toUTF8() [2/2]

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

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

Definition at line 1206 of file String.cpp.

References toUTF8().

◆ trim() [1/3]

String & String::trim ( wchar_t  ch)

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

Definition at line 322 of file String.cpp.

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

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

◆ trim() [2/3]

String & String::trim ( const String chars)

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

Definition at line 307 of file String.cpp.

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

◆ trim() [3/3]

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 343 of file String.cpp.

References acquireData().

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

◆ trimStdString()

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

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

Definition at line 1471 of file String.cpp.

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


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