class EE::String¶
Overview¶
Utility string class that automatically handles conversions between types and encodings
EE::String is a utility string class defined mainly for convenience. More…
#include <string.hpp> class String { public: // typedefs typedef char32_t StringBaseType; typedef std::basic_string<StringBaseType> StringType; typedef StringType::iterator Iterator; typedef StringType::const_iterator ConstIterator; typedef StringType::reverse_iterator ReverseIterator; typedef StringType::const_reverse_iterator ConstReverseIterator; typedef Uint32 HashType; typedef std::basic_string_view<StringBaseType> View; // classes class BMH; // fields static const std::size_t InvalidPos; // construction String(); String(char ansiChar); String(wchar_t wideChar); String(StringBaseType utf32Char); String(const char* utf8String); String(const char* utf8String, const size_t& utf8StringSize); String(const std::string& utf8String); String(const std::string_view& utf8String); String(const wchar_t* wideString); String(const std::wstring& wideString); String(const StringBaseType* utf32String); String(const StringType& utf32String); String(const String& str); String(const String::View& str); // methods static constexpr HashType hash(const char* str); static constexpr String::HashType hash(const char* str, Int64 len); static String escape(const String& str); static String unescape(const String& str); static String::HashType hash(const std::string& str); static String::HashType hash(const String& str); static bool isCharacter(const int& value); static bool isNumber(const int& value, bool AllowDot = false); static bool isNumber(const std::string& value, bool AllowDot = false); static bool isLetter(const int& value); static bool isAlphaNum(const int& value); static bool isHexNotation(const std::string& value, const std::string& withPrefix = ""); static bool isWholeWord(const std::string& haystack, const std::string& needle, const Int64& startPos); static bool isWholeWord(const String& haystack, const String& needle, const Int64& startPos); static std::vector<String> split(const String& str, const StringBaseType& delim = '\n', const bool& pushEmptyString = false, const bool& keepDelim = false); static std::vector<std::string> split(const std::string& str, const Int8& delim = '\n', const bool& pushEmptyString = false, const bool& keepDelim = false); static std::vector<std::string_view> split(const std::string_view& str, const Int8& delim = '\n', const bool& pushEmptyString = false); static std::vector<std::string> split(const std::string& str, const std::string& delims, const std::string& delimsPreserve = "", const std::string& quote = "\"", const bool& removeQuotes = false); static void splitCb(std::function<bool(std::string_view)> fnCb, const std::string& str, const std::string& delims, const std::string& delimsPreserve = "", const std::string& quote = "\"", const bool& removeQuotes = false); static std::string join(const std::vector<std::string>& strArray, const Int8& joinchar = ' ', const bool& appendLastJoinChar = false); static String join(const std::vector<String>& strArray, const Int8& joinchar = ' ', const bool& appendLastJoinChar = false); static std::string lTrim(const std::string& str, char character = ' '); static std::string rTrim(const std::string& str, char character); static std::string trim(const std::string& str, char character = ' '); static std::string_view lTrim(const std::string_view& str, char character = ' '); static std::string_view rTrim(const std::string_view& str, char character); static std::string_view trim(const std::string_view& str, char character = ' '); static void trimInPlace(std::string& str, char character = ' '); static String lTrim(const String& str, char character = ' '); static String rTrim(const String& str, char character = ' '); static String trim(const String& str, char character = ' '); static void trimInPlace(String& str, char character = ' '); static void toUpperInPlace(std::string& str); static std::string toUpper(std::string str); static void toLowerInPlace(std::string& str); static void capitalizeInPlace(std::string& str); static std::string toLower(std::string str); static std::string capitalize(std::string str); static String toUpper(const String& str); static String toLower(const String& str); static String capitalize(const String& str); static std::vector<Uint8> stringToUint8(const std::string& str); static std::string Uint8ToString(const std::vector<Uint8>& v); static void insertChar(String& str, const unsigned int& pos, const StringBaseType& tchar); static void strCopy(char* Dst, const char* Src, unsigned int DstSize); static bool startsWith(const std::string& haystack, const std::string& needle); static bool startsWith(const String& haystack, const String& needle); static bool startsWith(const char* haystack, const char* needle); static bool startsWith(std::string_view haystack, std::string_view needle); static bool endsWith(const std::string& haystack, const std::string& needle); static bool endsWith(const String& haystack, const String& needle); static bool contains(const std::string& haystack, const std::string& needle); static bool contains(const String& haystack, const String& needle); static int fuzzyMatch(const std::string& string, const std::string& pattern, bool allowUneven = false, bool permissive = false); static void replaceAll(std::string& target, const std::string& that, const std::string& with); static void replaceAll(String& target, const String& that, const String& with); static void replace(std::string& target, const std::string& that, const std::string& with); static void replace(String& target, const String& that, const String& with); static std::string removeNumbersAtEnd(std::string txt); static std::string_view numberClean(std::string_view strNumber); static std::string numberClean(const std::string& strNumber); static void numberCleanInPlace(std::string& strNumber); static std::size_t findCloseBracket(const std::string& string, std::size_t startOffset, char openBracket, char closeBracket); static int valueIndex(const std::string& val, const std::string& strings, int defValue = -1, char delim = ';'); static std::string randString(size_t len, std::string dictionary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); static std::string toString(const Int8& i); static std::string toString(const Int16& i); static std::string toString(const Int32& i); static std::string toString(const Int64& i); static std::string toString(const Uint8& i); static std::string toString(const Uint16& i); static std::string toString(const Uint32& i); static std::string toString(const Uint64& i); static std::string toString(const float& i); static std::string toString(const double& i); static std::string fromFloat(const Float& value, const std::string& append = "", const std::string& prepend = "", size_t digitsAfterComma = 2); static std::string fromDouble(const double& value, const std::string& append = "", const std::string& prepend = "", size_t digitsAfterComma = 2); static bool fromString(Int8& t, const std::string& s, int base = 10); static bool fromString(Int16& t, const std::string& s, int base = 10); static bool fromString(Int32& t, const std::string& s, int base = 10); static bool fromString(Int64& t, const std::string& s, int base = 10); static bool fromString(Uint8& t, const std::string& s, int base = 10); static bool fromString(Uint16& t, const std::string& s, int base = 10); static bool fromString(Uint32& t, const std::string& s, int base = 10); static bool fromString(Uint64& t, const std::string& s, int base = 10); static bool fromString(float& t, const std::string& s); static bool fromString(double& t, const std::string& s); static bool fromString(Int8& t, const String& s, int base = 10); static bool fromString(Int16& t, const String& s, int base = 10); static bool fromString(Int32& t, const String& s, int base = 10); static bool fromString(Int64& t, const String& s, int base = 10); static bool fromString(Uint8& t, const String& s, int base = 10); static bool fromString(Uint16& t, const String& s, int base = 10); static bool fromString(Uint32& t, const String& s, int base = 10); static bool fromString(Uint64& t, const String& s, int base = 10); static bool fromString(float& t, const String& s); static bool fromString(double& t, const String& s); template <typename... Args> static std::string format(std::string_view format, Args&&... args); static void formatBuffer(char* Buffer, int BufferSize, const char* format, ...); static String fromUtf8(const std::string& utf8String); static size_t utf8Length(const std::string& utf8String); static String fromUtf8(const std::string_view& utf8String); static size_t utf8Length(const std::string_view& utf8String); static Uint32 utf8Next(char*& utf8String); static size_t toUtf32(std::string_view utf8str, String::StringBaseType* buffer, size_t bufferSize); static bool globMatch(const std::string_view& text, const std::string_view& glob, bool caseInsensitive = false); static bool globMatch(const std::string_view& text, const std::vector<std::string>& globs, bool caseInsensitive = false); static String fromWide(const wchar_t* wideString); static String fromUtf16(const char* utf16String, const size_t& utf16StringSize, bool isBigEndian = false); static String fromLatin1(const char* string, const size_t& stringSize); static std::string getFirstLine(const std::string& string); template <typename IntType, typename StrType> static const StrType* intToStrBuf(IntType value, StrType* buffer, size_t bufferSize, size_t padding, StrType padChar); operator std::string() const; std::wstring toWideString() const; std::string toUtf8() const; std::basic_string<char16_t> toUtf16() const; HashType getHash() const; String& operator=(const String& right); String& operator=(String&& right); String& operator=(const StringBaseType& right); String& operator+=(const String& right); String& operator+=(const StringBaseType& right); const StringBaseType& operator[](std::size_t index) const; StringBaseType& operator[](std::size_t index); const StringBaseType& at(std::size_t index) const; void clear(); std::size_t size() const; std::size_t length() const; bool empty() const; void erase(std::size_t position, std::size_t count = 1); String& insert(std::size_t position, const String& str); String& insert(size_t pos1, const char* s, size_t n); String& insert(std::size_t pos1, const String& str, std::size_t pos2, std::size_t n); String& insert(std::size_t pos1, const char* s); String& insert(std::size_t pos1, size_t n, const String::StringBaseType& c); Iterator insert(Iterator p, const String::StringBaseType& c); void insert(Iterator p, std::size_t n, const StringBaseType& c); template <class InputIterator> void insert(Iterator p, InputIterator first, InputIterator last); std::size_t find(const String& str, std::size_t start = 0) const; std::size_t find(const char* s, std::size_t pos, std::size_t n) const; std::size_t find(const char* s, std::size_t pos = 0) const; std::size_t find(const String::StringBaseType& c, std::size_t pos = 0) const; const StringBaseType* c_str() const; const StringBaseType* data() const; Iterator begin(); ConstIterator begin() const; Iterator end(); ConstIterator end() const; ReverseIterator rbegin(); ConstReverseIterator rbegin() const; ReverseIterator rend(); ConstReverseIterator rend() const; void resize(std::size_t n, StringBaseType c); void resize(std::size_t n); std::size_t max_size() const; void reserve(size_t res_arg = 0); std::size_t capacity() const; void push_back(StringBaseType c); void swap(String& str); String& assign(const String& str); String& assign(const String& str, std::size_t pos, std::size_t n); String& assign(const char* s); String& assign(std::size_t n, StringBaseType c); template <class InputIterator> String& assign(InputIterator first, InputIterator last); String& append(const String& str); String& append(const String& str, std::size_t pos, std::size_t n); String& append(const char* s); String& append(std::size_t n, char c); String& append(std::size_t n, StringBaseType c); template <class InputIterator> String& append(InputIterator first, InputIterator last); String& replace(std::size_t pos1, std::size_t n1, const String& str); String& replace(Iterator i1, Iterator i2, const String& str); String& replace(std::size_t pos1, std::size_t n1, const String& str, std::size_t pos2, std::size_t n2); String& replace(std::size_t pos1, std::size_t n1, const char* s, std::size_t n2); String& replace(Iterator i1, Iterator i2, const char* s, std::size_t n2); String& replace(std::size_t pos1, std::size_t n1, const char* s); String& replace(Iterator i1, Iterator i2, const char* s); String& replace(std::size_t pos1, std::size_t n1, std::size_t n2, StringBaseType c); String& replace(Iterator i1, Iterator i2, std::size_t n2, StringBaseType c); template <class InputIterator> String& replace(Iterator i1, Iterator i2, InputIterator j1, InputIterator j2); std::size_t rfind(const String& str, std::size_t pos = StringType::npos) const; std::size_t rfind(const char* s, std::size_t pos = StringType::npos) const; std::size_t rfind(const StringBaseType& c, std::size_t pos = StringType::npos) const; String substr(std::size_t pos = 0, std::size_t n = StringType::npos) const; std::size_t copy(StringBaseType* s, std::size_t n, std::size_t pos = 0) const; int compare(const String& str) const; int compare(const char* s) const; int compare(std::size_t pos1, std::size_t n1, const String& str) const; int compare(std::size_t pos1, std::size_t n1, const char* s) const; int compare(std::size_t pos1, std::size_t n1, const String& str, std::size_t pos2, std::size_t n2) const; int compare(std::size_t pos1, std::size_t n1, const char* s, std::size_t n2) const; std::size_t find_first_of(const String& str, std::size_t pos = 0) const; std::size_t find_first_of(const char* s, std::size_t pos = 0) const; std::size_t find_first_of(StringBaseType c, std::size_t pos = 0) const; std::size_t find_last_of(const String& str, std::size_t pos = StringType::npos) const; std::size_t find_last_of(const char* s, std::size_t pos = StringType::npos) const; std::size_t find_last_of(StringBaseType c, std::size_t pos = StringType::npos) const; std::size_t find_first_not_of(const String& str, std::size_t pos = 0) const; std::size_t find_first_not_of(const char* s, std::size_t pos = 0) const; std::size_t find_first_not_of(StringBaseType c, std::size_t pos = 0) const; std::size_t find_last_not_of(const String& str, std::size_t pos = StringType::npos) const; std::size_t find_last_not_of(const char* s, std::size_t pos = StringType::npos) const; std::size_t find_last_not_of(StringBaseType c, std::size_t pos = StringType::npos) const; size_t countChar(StringBaseType c) const; String& padLeft(unsigned int minDigits, StringBaseType padChar); String& toLower(); String& toUpper(); String& capitalize(); String& escape(); String& unescape(); StringBaseType lastChar() const; std::vector<String> split(const StringBaseType& delim = '\n', const bool& pushEmptyString = false, const bool& keepDelim = false) const; String getFirstLine(); void replaceAll(const String& that, const String& with); void pop_back(); const StringBaseType& front() const; const StringBaseType& back() const; String& trim(char character = ' '); String& lTrim(char character = ' '); String& rTrim(char character = ' '); bool contains(const String& needle) const; bool isAscii() const; String::View view() const; EE_API bool operator==(const String& left, const String& right); EE_API bool operator!=(const String& left, const String& right); EE_API bool operator<(const String& left, const String& right); EE_API bool operator>(const String& left, const String& right); EE_API bool operator<=(const String& left, const String& right); EE_API bool operator>=(const String& left, const String& right); EE_API String operator+(const String& left, const String& right); };
Detailed Documentation¶
Utility string class that automatically handles conversions between types and encodings
EE::String is a utility string class defined mainly for convenience. It is a Unicode string (implemented using UTF-32), thus it can store any character in the world (european, chinese, arabic, hebrew, etc.). It automatically handles conversions from/to UTF-8 and wide strings, so that you can work with standard string classes and still be compatible with functions taking a EE::String.
EE::String s; std::string s1 = s; // automatically converted to UTF-8 string String s2 = s; // automatically converted to wide string s = "hello"; // automatically converted from UTF-8 string s = L"hello"; // automatically converted from wide string s += 'a'; // automatically converted from UTF-8 string s += L'a'; // automatically converted from wide string
EE::String defines the most important functions of the standard std::string class: removing, random access, iterating, appending, comparing, etc. However it is a simple class provided for convenience, and you may have to consider using a more optimized class if your program requires complex string handling. The automatic conversion functions will then take care of converting your string to EE::String whenever EE requires it.
Please note that EE also defines a low-level, generic interface for Unicode handling, see the EE::Utf classes.
All credits to Laurent Gomila, i just modified and expanded a little bit the implementation.
Typedefs¶
typedef StringType::const_iterator ConstIterator
Iterator type.
typedef StringType::reverse_iterator ReverseIterator
Constant iterator type.
typedef StringType::const_reverse_iterator ConstReverseIterator
Reverse Iterator type.
typedef Uint32 HashType
Constant iterator type.
Fields¶
static const std::size_t InvalidPos
Represents an invalid position in the string.
Construction¶
String()
Default constructor This constructor creates an empty string.
String(char ansiChar)
Construct from a single ANSI character.
Parameters:
ansiChar |
ANSI character to convert |
String(wchar_t wideChar)
Construct from single wide character.
Parameters:
wideChar |
Wide character to convert |
String(StringBaseType utf32Char)
Construct from single UTF-32 character.
Parameters:
utf32Char |
UTF-32 character to convert |
String(const char* utf8String)
Construct from an from a null-terminated C-style UTF-8 string to UTF-32.
Parameters:
uf8String |
UTF-8 string to convert |
String(const char* utf8String, const size_t& utf8StringSize)
Construct from an from a sub-string C-style UTF-8 string to UTF-32.
Parameters:
uf8String |
UTF-8 string to convert |
String(const std::string& utf8String)
Construct from an UTF-8 string to UTF-32 according.
Parameters:
utf8String |
UTF-8 string to convert |
String(const std::string_view& utf8String)
Construct from an UTF-8 string to UTF-32 according.
Parameters:
utf8String |
UTF-8 string to convert |
String(const wchar_t* wideString)
Construct from null-terminated C-style wide string.
Parameters:
wideString |
Wide string to convert |
String(const std::wstring& wideString)
Construct from a wide string.
Parameters:
wideString |
Wide string to convert |
String(const StringBaseType* utf32String)
Construct from a null-terminated C-style UTF-32 string.
Parameters:
utf32String |
UTF-32 string to assign |
String(const StringType& utf32String)
Construct from an UTF-32 string.
Parameters:
utf32String |
UTF-32 string to assign |
String(const String& str)
Copy constructor.
Parameters:
str |
Instance to copy |
String(const String::View& str)
Copy constructor.
Parameters:
str |
Instance to copy |
Methods¶
static constexpr HashType hash(const char* str)
Returns:
string hash
static String escape(const String& str)
Escape string sequence
static String unescape(const String& str)
Unescape string sequence
static String::HashType hash(const std::string& str)
Returns:
string hash
static String::HashType hash(const String& str)
Returns:
string hash. Note: String::hash ( std::string( “text” ) ) is != to String::hash (String ( “text” ) )
static bool isCharacter(const int& value)
Returns:
If the value passed is a character
static bool isNumber(const int& value, bool AllowDot = false)
Returns:
If the value passed is a number
static bool isNumber(const std::string& value, bool AllowDot = false)
Returns:
If the string represents a number.
static bool isLetter(const int& value)
Returns:
If the value passed is a letter
static bool isAlphaNum(const int& value)
Returns:
If the value passed is a letter or a number
static bool isHexNotation(const std::string& value, const std::string& withPrefix = "")
Returns:
If the string is a representation of a hexa number
static bool isWholeWord(const std::string& haystack, const std::string& needle, const Int64& startPos)
Returns:
If the needle substring, found starting at startPos is a whole-word.
static bool isWholeWord(const String& haystack, const String& needle, const Int64& startPos)
Returns:
If the needle substring, found starting at startPos is a whole-word.
static std::vector<String> split(const String& str, const StringBaseType& delim = '\n', const bool& pushEmptyString = false, const bool& keepDelim = false)
Split a String and hold it on a vector
static std::vector<std::string> split(const std::string& str, const Int8& delim = '\n', const bool& pushEmptyString = false, const bool& keepDelim = false)
Split a string and hold it on a vector
static std::vector<std::string_view> split(const std::string_view& str, const Int8& delim = '\n', const bool& pushEmptyString = false)
Split a string and hold it on a vector
static std::vector<std::string> split(const std::string& str, const std::string& delims, const std::string& delimsPreserve = "", const std::string& quote = "\"", const bool& removeQuotes = false)
Split a string and hold it on a vector. This function is meant to be used for code splitting, detects functions, arrays, braces and quotes for the splitting.
static void splitCb(std::function<bool(std::string_view)> fnCb, const std::string& str, const std::string& delims, const std::string& delimsPreserve = "", const std::string& quote = "\"", const bool& removeQuotes = false)
Split a string and hold it on a vector. This function is meant to be used for code splitting, detects functions, arrays, braces and quotes for the splitting. It does not heap allocate.
static std::string join(const std::vector<std::string>& strArray, const Int8& joinchar = ' ', const bool& appendLastJoinChar = false)
Joins a string vector into a single string
static String join(const std::vector<String>& strArray, const Int8& joinchar = ' ', const bool& appendLastJoinChar = false)
Joins a string vector into a single string
static std::string lTrim(const std::string& str, char character = ' ')
Removes the trailing prefix.
static std::string rTrim(const std::string& str, char character)
Removes the trailing suffix.
static std::string trim(const std::string& str, char character = ' ')
Removes all spaces ( or the specified character ) on the string
static std::string_view lTrim(const std::string_view& str, char character = ' ')
Removes the trailing prefix.
static std::string_view rTrim(const std::string_view& str, char character)
Removes the trailing suffix.
static std::string_view trim(const std::string_view& str, char character = ' ')
Removes all spaces ( or the specified character ) on the string
static void trimInPlace(std::string& str, char character = ' ')
Removes all spaces ( or the specified character ) on the string
static String lTrim(const String& str, char character = ' ')
Removes the trailing prefix.
static String rTrim(const String& str, char character = ' ')
Removes the trailing suffix.
static String trim(const String& str, char character = ' ')
Removes all spaces ( or the specified character ) on the string
static void trimInPlace(String& str, char character = ' ')
Removes all spaces ( or the specified character ) on the string
static void toUpperInPlace(std::string& str)
Convert the string into upper case string
static std::string toUpper(std::string str)
Convert a string to lower case
static void toLowerInPlace(std::string& str)
Convert the reference of a string into lower case string
static void capitalizeInPlace(std::string& str)
Capitalizes the reference of a string
static std::string toLower(std::string str)
Convert a string to lower case
static std::string capitalize(std::string str)
Catitalize a string
static String toUpper(const String& str)
Convert a string to lower case
static String toLower(const String& str)
Convert a string to lower case
static String capitalize(const String& str)
Capitalizes a string
static std::vector<Uint8> stringToUint8(const std::string& str)
Convert the string to an std::vector<Uint8>
static std::string Uint8ToString(const std::vector<Uint8>& v)
Convert the std::vector<Uint8> to an string
static void insertChar(String& str, const unsigned int& pos, const StringBaseType& tchar)
Insert a char into String on pos (added this function to avoid a bug on String)
static void strCopy(char* Dst, const char* Src, unsigned int DstSize)
Copy a string to another
Parameters:
Dst |
Destination String |
Src |
Source String |
DstSize |
Destination Size |
static bool startsWith(const std::string& haystack, const std::string& needle)
Compare two strings from its beginning.
Parameters:
haystack |
The string to search in. |
needle |
The searched string. |
Returns:
true if string starts with the substring
static bool startsWith(const String& haystack, const String& needle)
Compare two strings from its beginning.
Parameters:
haystack |
The string to search in. |
needle |
The searched string. |
Returns:
true if string starts with the substring
static bool startsWith(const char* haystack, const char* needle)
Compare two strings from its beginning.
Parameters:
haystack |
The string to search in. |
needle |
The searched string. |
Returns:
true if string starts with the substring
static bool startsWith(std::string_view haystack, std::string_view needle)
Compare two strings from its beginning.
Parameters:
haystack |
The string to search in. |
needle |
The searched string. |
Returns:
true if string starts with the substring
static bool endsWith(const std::string& haystack, const std::string& needle)
Compare two strings from its end.
Parameters:
haystack |
The string to search in. |
needle |
The searched string. |
Returns:
true if string starts with the substring
static bool endsWith(const String& haystack, const String& needle)
Compare two strings from its end.
Parameters:
haystack |
The string to search in. |
needle |
The searched string. |
Returns:
true if string starts with the substring
static bool contains(const std::string& haystack, const std::string& needle)
Parameters:
haystack |
The string to search in. |
needle |
The searched string. |
Returns:
True if a string contains a substring.
static bool contains(const String& haystack, const String& needle)
Parameters:
haystack |
The string to search in. |
needle |
The searched string. |
Returns:
True if a string contains a substring.
static void replaceAll(std::string& target, const std::string& that, const std::string& with)
Replace all occurrences of the search string with the replacement string.
static void replaceAll(String& target, const String& that, const String& with)
Replace all occurrences of the search string with the replacement string.
static void replace(std::string& target, const std::string& that, const std::string& with)
Replace the first ocurrence of the search string with the replacement string.
static void replace(String& target, const String& that, const String& with)
Replace the first ocurrence of the search string with the replacement string.
static std::string removeNumbersAtEnd(std::string txt)
Removes the numbers at the end of the string
static std::string_view numberClean(std::string_view strNumber)
Removes the trailing 0 and . in a string number
static std::string numberClean(const std::string& strNumber)
Removes the trailing 0 and . in a string number
static void numberCleanInPlace(std::string& strNumber)
Removes the trailing 0 and . in a string number
static std::size_t findCloseBracket(const std::string& string, std::size_t startOffset, char openBracket, char closeBracket)
Searchs the position of the corresponding close bracket in a string.
static int valueIndex(const std::string& val, const std::string& strings, int defValue = -1, char delim = ';')
Having a string of values separated by a delimiter, returns the corresponding index of the searched value
static std::string randString(size_t len, std::string dictionary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
Creates a random string using the dictionary characters.
static std::string toString(const Int8& i)
Converts from any basic type to std::string
static bool fromString(Int8& t, const std::string& s, int base = 10)
Converts from a string to type
static bool fromString(Int8& t, const String& s, int base = 10)
Converts from a String to type
static void formatBuffer(char* Buffer, int BufferSize, const char* format, ...)
Format a char buffer
static String fromUtf8(const std::string& utf8String)
Construct from an UTF-8 string to UTF-32 according.
Parameters:
utf8String |
UTF-8 string to convert |
static size_t utf8Length(const std::string& utf8String)
Returns:
The number of codepoints of the utf8 string.
static String fromUtf8(const std::string_view& utf8String)
Construct from an UTF-8 string to UTF-32 according.
Parameters:
utf8String |
UTF-8 string to convert |
static size_t utf8Length(const std::string_view& utf8String)
Returns:
The number of codepoints of the utf8 string.
static Uint32 utf8Next(char*& utf8String)
Returns:
The next character in a utf8 null terminated string
static size_t toUtf32(std::string_view utf8str, String::StringBaseType* buffer, size_t bufferSize)
Converts an UTF-8 string view into an UTF-32 by using a currently allocated buffer (usefull for stack allocated buffers)
Returns:
The number of elements written into the buffer (the string length)
static bool globMatch(const std::string_view& text, const std::string_view& glob, bool caseInsensitive = false)
glob matches a string against a glob
Returns:
True if matches
static bool globMatch(const std::string_view& text, const std::vector<std::string>& globs, bool caseInsensitive = false)
glob matches a string against a set of globs
Returns:
True if matches
operator std::string() const
Implicit cast operator to std::string (ANSI string) The current global locale is used for conversion. If you want to explicitely specify a locale, see toAnsiString. Characters that do not fit in the target encoding are discarded from the returned string. This operator is defined for convenience, and is equivalent to calling toAnsiString().
Returns:
Converted ANSI string
See also:
toAnsiString, operator String
std::wstring toWideString() const
Convert the unicode string to a wide string Characters that do not fit in the target encoding are discarded from the returned string.
Returns:
Converted wide string
See also:
toAnsiString, operator String
std::string toUtf8() const
Convert the string to a UTF-8 string
std::basic_string<char16_t> toUtf16() const
Convert the string to a UTF-16 string
HashType getHash() const
Returns:
The hash code of the String
String& operator=(const String& right)
Overload of assignment operator.
Parameters:
right |
Instance to assign |
Returns:
Reference to self
String& operator+=(const String& right)
Overload of += operator to append an UTF-32 string.
Parameters:
right |
String to append |
Returns:
Reference to self
const StringBaseType& operator[](std::size_t index) const
Overload of [] operator to access a character by its position This function provides read-only access to characters. Note: this function doesn’t throw if index is out of range.
Parameters:
index |
Index of the character to get |
Returns:
Character at position index
StringBaseType& operator[](std::size_t index)
Overload of [] operator to access a character by its position This function provides read and write access to characters. Note: this function doesn’t throw if index is out of range.
Parameters:
index |
Index of the character to get |
Returns:
Reference to the character at position index
const StringBaseType& at(std::size_t index) const
Get character in string Performs a range check, throwing an exception of type out_of_range in case that pos is not an actual position in the string.
Returns:
The character at position pos in the string.
void clear()
clear the string This function removes all the characters from the string.
See also:
std::size_t size() const
Get the size of the string.
Returns:
Number of characters in the string
See also:
std::size_t length() const
See also:
bool empty() const
Check whether the string is empty or not.
Returns:
True if the string is empty (i.e. contains no character)
See also:
void erase(std::size_t position, std::size_t count = 1)
Erase one or more characters from the string This function removes a sequence of count characters starting from position.
Parameters:
position |
Position of the first character to erase |
count |
Number of characters to erase |
String& insert(std::size_t position, const String& str)
Insert one or more characters into the string This function inserts the characters of str into the string, starting from position.
Parameters:
position |
Position of insertion |
str |
Characters to insert |
std::size_t find(const String& str, std::size_t start = 0) const
Find a sequence of one or more characters in the string This function searches for the characters of str into the string, starting from start.
Parameters:
str |
Characters to find |
start |
Where to begin searching |
Returns:
Position of str in the string, or String::InvalidPos if not found
const StringBaseType* c_str() const
Get a pointer to the C-style array of characters This functions provides a read-only access to a null-terminated C-style representation of the string. The returned pointer is temporary and is meant only for immediate use, thus it is not recommended to store it.
Returns:
Read-only pointer to the array of characters
const StringBaseType* data() const
Get string data Notice that no terminating null character is appended (see member c_str for such a functionality). The returned array points to an internal location which should not be modified directly in the program. Its contents are guaranteed to remain unchanged only until the next call to a non-constant member function of the string object.
Returns:
Pointer to an internal array containing the same content as the string.
Iterator begin()
Return an iterator to the beginning of the string.
Returns:
Read-write iterator to the beginning of the string characters
See also:
ConstIterator begin() const
Return an iterator to the beginning of the string.
Returns:
Read-only iterator to the beginning of the string characters
See also:
Iterator end()
Return an iterator to the beginning of the string The end iterator refers to 1 position past the last character; thus it represents an invalid character and should never be accessed.
Returns:
Read-write iterator to the end of the string characters
See also:
ConstIterator end() const
Return an iterator to the beginning of the string The end iterator refers to 1 position past the last character; thus it represents an invalid character and should never be accessed.
Returns:
Read-only iterator to the end of the string characters
See also:
ReverseIterator rbegin()
Return an reverse iterator to the beginning of the string.
Returns:
Read-write reverse iterator to the beginning of the string characters
See also:
ConstReverseIterator rbegin() const
Return an reverse iterator to the beginning of the string.
Returns:
Read-only reverse iterator to the beginning of the string characters
See also:
ReverseIterator rend()
Return an reverse iterator to the beginning of the string The end reverse iterator refers to 1 position past the last character; thus it represents an invalid character and should never be accessed.
Returns:
Read-write reverse iterator to the end of the string characters
See also:
ConstReverseIterator rend() const
Return an reverse iterator to the beginning of the string The end reverse iterator refers to 1 position past the last character; thus it represents an invalid character and should never be accessed.
Returns:
Read-only reverse iterator to the end of the string characters
See also:
void resize(std::size_t n, StringBaseType c)
Resize String.
void resize(std::size_t n)
Resize String.
std::size_t max_size() const
Returns:
Maximum size of string
void reserve(size_t res_arg = 0)
Request a change in capacity.
std::size_t capacity() const
Returns:
Size of allocated storage
void push_back(StringBaseType c)
Append character to string.
void swap(String& str)
Swap contents with another string.
void replaceAll(const String& that, const String& with)
Replace all occurrences of the search string with the replacement string.
bool contains(const String& needle) const
Parameters:
needle |
The searched string. |
Returns:
True if a string contains a substring.
EE_API bool operator==(const String& left, const String& right)
Overload of == operator to compare two UTF-32 strings.
Parameters:
left |
Left operand (a string) |
right |
Right operand (a string) |
Returns:
True if both strings are equal
EE_API bool operator!=(const String& left, const String& right)
Overload of != operator to compare two UTF-32 strings.
Parameters:
left |
Left operand (a string) |
right |
Right operand (a string) |
Returns:
True if both strings are different
EE_API bool operator<(const String& left, const String& right)
Overload of < operator to compare two UTF-32 strings.
Parameters:
left |
Left operand (a string) |
right |
Right operand (a string) |
Returns:
True if left is alphabetically lesser than right
EE_API bool operator>(const String& left, const String& right)
Overload of > operator to compare two UTF-32 strings.
Parameters:
left |
Left operand (a string) |
right |
Right operand (a string) |
Returns:
True if left is alphabetically greater than right
EE_API bool operator<=(const String& left, const String& right)
Overload of <= operator to compare two UTF-32 strings.
Parameters:
left |
Left operand (a string) |
right |
Right operand (a string) |
Returns:
True if left is alphabetically lesser or equal than right
EE_API bool operator>=(const String& left, const String& right)
Overload of >= operator to compare two UTF-32 strings.
Parameters:
left |
Left operand (a string) |
right |
Right operand (a string) |
Returns:
True if left is alphabetically greater or equal than right
EE_API String operator+(const String& left, const String& right)
Overload of binary + operator to concatenate two strings.
Parameters:
left |
Left operand (a string) |
right |
Right operand (a string) |
Returns:
Concatenated string