Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode characters.
The native format for this string is UTF-8 encoded values, but the CYIString type can convert to and from other string formats such as UTF-16 and UTF-32. Unicode is an international standard employed by operating systems across the globe for managing writing systems used by most languages.
All constructor make a copy of the provided object or data array. For constructors that take in a data array, it is the responsability of the caller to delete the array when it is no longer needed.
The char constructors assume that the incoming data is encoded in UTF-8 already. For performance reasons, this assumption is not checked during the constructor. If invalid data (or non-UTF-8) data is provided in one of the constructors, usage of some functions may result in undefined behaviour.
Some of the functions in this class accept a parameter to enable case-insensitive searching and comparing. However, there is no Unicode Normalization performed (and thus two strings that should be equal can be reported as not equal).
For platforms that support C++/CX, the CYIStringCXUtilities class contains utilities for converting to and from WinRT string classes.
#include <utility/YiString.h>
Classes | |
class | ConstIterator |
Public Types | |
enum | CaseMode { CaseMode::CaseSensitive, CaseMode::CaseInsensitiveASCII } |
typedef std::reverse_iterator< ConstIterator > | ConstReverseIterator |
typedef ConstIterator | Iterator |
typedef std::reverse_iterator< Iterator > | ReverseIterator |
Public Member Functions | |
CYIString () | |
CYIString (const CYIString &s) | |
CYIString (CYIString &&s) noexcept | |
CYIString (CYIStringView stringView) | |
CYIString (std::string &&string) noexcept | |
CYIString (const std::string &s) | |
CYIString (char32_t character) | |
CYIString (const ConstIterator &begin, const ConstIterator &end) | |
CYIString (const std::wstring &s) | |
CYIString (const NSString *pString) | |
CYIString (const CFStringRef string) | |
CYIString (const char *pUTF8) | |
CYIString (const char *pUTF8, size_t sizeBytes) | |
CYIString (const char16_t *pUTF16, size_t size=NPos) | |
CYIString (const char32_t *pUTF32, size_t size=NPos) | |
CYIString (const wchar_t *pWideChars, size_t size=NPos) | |
CYIString (const std::vector< char > &vector) | |
CYIString (const std::vector< uint8_t > &vector) | |
operator CYIStringView () const noexcept | |
CYIString & | operator= (const CYIString &s) |
CYIString & | operator= (const char *pUTF8) |
CYIString & | operator= (CYIString &&s) noexcept |
CYIString & | operator= (std::string &&s) noexcept |
bool | operator< (const char *pOther) const |
bool | operator> (const char *pOther) const |
bool | operator<= (const char *pOther) const |
bool | operator>= (const char *pOther) const |
char32_t | operator[] (size_t pos) const |
void | Reserve (size_t bytes) |
CYIString & | operator+= (CYIStringView view) |
CYIString & | operator+= (const char *pUTF8) |
template<class T , class = std::enable_if_t<!std::is_convertible<const T &, CYIStringView>::value >> | |
CYIString | operator+ (const T &arg) const |
CYIString | operator+ (const char *pUTF8) const |
bool | IsEmpty () const |
bool | IsNotEmpty () const |
size_t | GetLength () const |
size_t | GetSizeInBytes () const |
bool | ContainsNonASCII () const |
char32_t | At (size_t pos) const |
char | ByteAt (size_t byteOffset) const |
bool | Contains (CYIStringView s, CaseMode caseSensitivity=CaseMode::CaseSensitive) const |
bool | Contains (const char *pString, CaseMode caseSensitivity=CaseMode::CaseSensitive) const |
bool | StartsWith (CYIStringView s, CaseMode caseSensitivity=CaseMode::CaseSensitive) const |
bool | StartsWith (const char *pString, CaseMode caseSensitivity=CaseMode::CaseSensitive) const |
bool | EndsWith (CYIStringView s, CaseMode caseSensitivity=CaseMode::CaseSensitive) const |
bool | EndsWith (const char *pString, CaseMode caseSensitivity=CaseMode::CaseSensitive) const |
int32_t | Compare (CYIStringView s, CaseMode caseSensitivity=CaseMode::CaseSensitive) const |
int32_t | Compare (const char *pString, CaseMode caseSensitivity=CaseMode::CaseSensitive) const |
bool | Equals (CYIStringView other, CaseMode caseSensitivity=CaseMode::CaseSensitive) const noexcept |
bool | EqualsCaseInsensitiveASCII (CYIStringView other) const noexcept |
std::vector< CYIString > | Split (CYIStringView delimiter, bool ignoreEmptySubstrings=true, size_t maximumParts=NPos) const |
CYIString | SubStr (size_t pos=0, size_t len=NPos) const |
CYIString | SubStr (const ConstIterator &begin, const ConstIterator &end) const |
CYIString | Left (size_t len) const |
CYIString | Right (size_t len) const |
CYIString | ToUpperASCII () const |
CYIString | ToLowerASCII () const |
bool | IsNumeric () const |
size_t | IndexOf (CYIStringView view, size_t pos=0) const |
size_t | IndexOf (const char *pString, size_t pos=0) const |
size_t | LastIndexOf (CYIStringView view, size_t pos=NPos) const |
size_t | LastIndexOf (const char *pString, size_t pos=NPos) const |
ConstIterator | Find (CYIStringView view, const ConstIterator &begin) const |
ConstIterator | Find (const char *pString, const ConstIterator &begin) const |
ConstReverseIterator | ReverseFind (CYIStringView view, const ConstReverseIterator &begin) const |
ConstReverseIterator | ReverseFind (const char *pString, const ConstReverseIterator &begin) const |
CYIString | Arg (CYIStringView text) const |
const char * | GetData () const |
ConstIterator | begin () const |
ConstIterator | end () const |
ConstReverseIterator | rbegin () const |
ConstReverseIterator | rend () const |
void | Clear () |
CYIString & | Append (CYIStringView view) |
CYIString & | Append (const char *pUTF8, size_t sizeBytes=NPos) |
ConstIterator | Append (const ConstIterator &begin, const ConstIterator &end) |
CYIString & | Prepend (CYIStringView view) |
CYIString & | Prepend (const char *pUTF8, size_t sizeBytes=NPos) |
ConstIterator | Prepend (const ConstIterator &begin, const ConstIterator &end) |
CYIString & | Insert (CYIStringView view, size_t pos, size_t len=NPos) |
CYIString & | Insert (const char *pString, size_t pos, size_t len=NPos) |
ConstIterator | Insert (CYIStringView view, const ConstIterator &insertPosition) |
ConstIterator | Insert (const char *pString, const ConstIterator &insertPosition) |
ConstIterator | Insert (const ConstIterator &begin, const ConstIterator &end, const ConstIterator &insertPosition) |
CYIString & | Erase (size_t pos=0, size_t len=NPos) |
ConstIterator | Erase (const ConstIterator &begin, const ConstIterator &end) |
CYIString & | Replace (CYIStringView view, size_t pos, size_t len) |
CYIString & | Replace (const char *pString, size_t pos, size_t len) |
ConstIterator | Replace (CYIStringView view, const ConstIterator &begin, const ConstIterator &end) |
ConstIterator | Replace (const char *pString, const ConstIterator &begin, const ConstIterator &end) |
CYIString & | Replace (CYIStringView oldSubstring, CYIStringView newSubstring, size_t maximumReplacements=NPos) |
CYIString & | Replace (const char *pOldSubstring, const char *pNewSubstring, size_t maximumReplacements=NPos) |
void | Remove (CYIStringView text) |
void | Remove (const char *pString) |
void | Swap (CYIString &s) |
void | Trim () |
void | TrimLeft (size_t len=NPos) |
void | TrimRight (size_t len=NPos) |
void | RemovePrefix (size_t len) |
bool | RemovePrefix (CYIStringView prefix, CaseMode caseSensitivity=CaseMode::CaseSensitive) |
void | RemoveSuffix (size_t len) |
bool | RemoveSuffix (CYIStringView prefix, CaseMode caseSensitivity=CaseMode::CaseSensitive) |
std::unique_ptr< char[]> | ToUTF8 (size_t *pElementsCount=nullptr) const |
std::unique_ptr< char16_t[]> | ToUTF16 (size_t *pElementsCount=nullptr) const |
std::unique_ptr< char32_t[]> | ToUTF32 (size_t *pElementsCount=nullptr) const |
std::unique_ptr< wchar_t[]> | ToWideChars (size_t *pElementsCount=nullptr) const |
const std::string & | ToStdString () const |
std::wstring | ToStdWString () const |
NSString * | ToNSString () const |
CFStringRef | ToCFStringRef () const |
std::string | TakeStdString () |
template<class T > | |
T | To (bool *pError=nullptr) const |
template<class T > | |
T | ToValue (bool *pError=nullptr) const |
float | ToFloat (bool *pError=nullptr) const |
double | ToDouble (bool *pError=nullptr) const |
bool | ToBool (bool *pError=nullptr) const |
CYIString | ToHexadecimal () const |
Static Public Member Functions | |
static const CYIString & | EmptyString () |
template<class T , class O = std::ostringstream> | |
static CYIString | FromValue (const T &arg, bool *pError=nullptr) |
static CYIString | FromValue (bool arg, bool *pError=nullptr) |
static CYIString | FromFloat (float value, uint32_t decimalPlaces=6, bool trailingZeroes=false, bool useSignificantDigits=false) |
static CYIString | FromDouble (double value, uint32_t decimalPlaces=6, bool trailingZeroes=false, bool useSignificantDigits=false) |
static const CYIString & | FromBool (bool value) |
template<typename Container , typename Printer = bool> | |
static CYIString | Join (Container &&container, CYIStringView separator, bool includeEmptyElements=true, Printer &&toStringFunction=false) |
Static Public Attributes | |
static constexpr size_t | NPos = ~size_t(0) |
Friends | |
class | CYIStringView |
std::istream & | operator>> (std::istream &stream, CYIString &val) |
typedef std::reverse_iterator<ConstIterator> CYIString::ConstReverseIterator |
typedef ConstIterator CYIString::Iterator |
typedef std::reverse_iterator<Iterator> CYIString::ReverseIterator |
|
strong |
An enum used to specify a case-sensitivity handling mode.
CYIString::CYIString | ( | ) |
Creates an empty string.
CYIString::CYIString | ( | const CYIString & | s | ) |
Constructs a string from another CYIString type s. The resulting string will be a copy of the original.
|
noexcept |
Constructs a string from another CYIString type s using move semantics.
CYIString::CYIString | ( | CYIStringView | stringView | ) |
Constructs a string from a CYIStringView. The data referenced by the string view is copied into the new string instance.
|
noexcept |
Constructs a string from another std::string type string using move semantics.
CYIString::CYIString | ( | const std::string & | s | ) |
Constructs a string from a std::string type s. The resulting string will be a copy of the original.
|
explicit |
Constructs a string from a single Unicode character.
CYIString::CYIString | ( | const ConstIterator & | begin, |
const ConstIterator & | end | ||
) |
Constructs a string from a pair of CYIString iterators.
CYIString::CYIString | ( | const std::wstring & | s | ) |
Constructs a string from a std::wstring type s. The resulting string will be a copy of the original.
CYIString::CYIString | ( | const NSString * | pString | ) |
Constructs a string from an NSString Objective-C object. Passing nil to this constructor will result in an empty string being created.
CYIString::CYIString | ( | const CFStringRef | string | ) |
Constructs a string from a CFString reference. Passing nil to this constructor will result in an empty string being created.
CYIString::CYIString | ( | const char * | pUTF8 | ) |
Constructs a string from a UTF-8 encoded array pUTF8, which must be null terminated; providing nullptr instead results in an empty string.
CYIString::CYIString | ( | const char * | pUTF8, |
size_t | sizeBytes | ||
) |
Constructs a string from a UTF-8 encoded array pUTF8; providing nullptr instead results in an empty string. The sizeBytes parameter determines the number of bytes to read from the array.
Constructs a string from a UTF-16 encoded array pUTF16; providing nullptr instead results in an empty string.
By default, this constructor expects a null-terminated array. The size parameter can be used to instead provide a number of char16_t elements to read from the array.
Constructs a string from a UTF-32 encoded array pUTF32; providing nullptr instead results in an empty string.
By default, this constructor expects a null-terminated array. The size parameter can be used to instead provide a number of char32_t elements to read from the array.
Constructs a string from a null-terminated wide character array pWideChars; providing nullptr instead results in an empty string.
By default, this constructor expects a null-terminated array. The size parameter can be used to instead provide a number of wchar_t elements to read from the array.
CYIString::CYIString | ( | const std::vector< char > & | vector | ) |
Constructs a string from a UTF-8 encoded vector of char's vector.
CYIString::CYIString | ( | const std::vector< uint8_t > & | vector | ) |
Constructs a string from a UTF-8 encoded vector of uint8_t's vector.
CYIString& CYIString::Append | ( | CYIStringView | view | ) |
Appends the incoming string view view to the current string.
Appends the incoming string pUTF8 to the current string.
By default, this function expects a null-terminated array. The size parameter can be used to instead provide a number of bytes to read from the array. If pUTF8 is nullptr, this function does nothing.
ConstIterator CYIString::Append | ( | const ConstIterator & | begin, |
const ConstIterator & | end | ||
) |
Appends the string defined by the pair of iterators begin and end to this string. The provided iterators do not have to be from this string, but they both have to have been created from the same string.
The returned iterator points to the end of the string.
CYIString CYIString::Arg | ( | CYIStringView | text | ) | const |
Returns a new instance of the CYIString with the lowest-numbered 'marker' replaced with the string view text.
Markers are expected to be in the format xx, with xx being a number between 1 and 99 inclusively. Out-of-range values will result in undefined behaviour. Markers are not required to occur in order in the string. The same marker can be used multiple times within the string, which will result in all of those markers being replaced by the same argument.
Example: CYIString("%2, %1! %2!").Arg("World").Arg("Hello") would return "Hello, World! Hello!"
char32_t CYIString::At | ( | size_t | pos | ) | const |
Returns the 32-bit Unicode value at that character position specified by pos. The position must be a valid index position in the string; otherwise, a value of 0 is returned.
ConstIterator CYIString::begin | ( | ) | const |
Returns the iterator to the beginning of the string. This iterator iterates over Unicode characters rather than over bytes.
char CYIString::ByteAt | ( | size_t | byteOffset | ) | const |
Returns the byte value at the position byteOffset. If byteOffset is larger than the size (in bytes) of the string, 0 is returned.
void CYIString::Clear | ( | ) |
Empties the string and resets the length to 0.
int32_t CYIString::Compare | ( | CYIStringView | s, |
CaseMode | caseSensitivity = CaseMode::CaseSensitive |
||
) | const |
Compares this string with s. Returns a negative value if this string is less than s, zero if the two strings are equal and a positive value if this string is greater than s.
If a case-insenstive compare is needed, pass CaseMode::CaseInsensitiveASCII to the caseSensitivity parameter.
int32_t CYIString::Compare | ( | const char * | pString, |
CaseMode | caseSensitivity = CaseMode::CaseSensitive |
||
) | const |
Compares this string with pString. Returns a negative value if this string is less than pString, zero if the two strings are equal and a positive value if this character is greater than pString.
If a case-insenstive compare is needed, pass CaseMode::CaseInsensitiveASCII to the caseSensitivity parameter.
bool CYIString::Contains | ( | CYIStringView | s, |
CaseMode | caseSensitivity = CaseMode::CaseSensitive |
||
) | const |
Returns true if the string contains s as a sub-string. An empty string will be contained in any other string.
If a case-insensitive compare is needed, pass CaseMode::CaseInsensitiveASCII to the caseSensitivity parameter.
bool CYIString::Contains | ( | const char * | pString, |
CaseMode | caseSensitivity = CaseMode::CaseSensitive |
||
) | const |
Returns true if the string contains the sub-string pString. An empty string will be contained in any other string.
If a case-insensitive compare is needed, pass CaseMode::CaseInsensitiveASCII to the caseSensitivity parameter.
bool CYIString::ContainsNonASCII | ( | ) | const |
Returns true if the string contains non-ASCII characters.
|
static |
Returns an instance of an empty string. Useful for functions that return references.
ConstIterator CYIString::end | ( | ) | const |
Returns the iterator to the end of the string. This iterator iterates over Unicode characters rather than over bytes.
bool CYIString::EndsWith | ( | CYIStringView | s, |
CaseMode | caseSensitivity = CaseMode::CaseSensitive |
||
) | const |
Returns true if the string ends with the sub-string s.
If a case-insensitive compare is needed, pass CaseMode::CaseInsensitiveASCII to the caseSensitivity parameter.
bool CYIString::EndsWith | ( | const char * | pString, |
CaseMode | caseSensitivity = CaseMode::CaseSensitive |
||
) | const |
Returns true if the string ends with the sub-string pString.
If a case-insensitive compare is needed, pass CaseMode::CaseInsensitiveASCII to the caseSensitivity parameter.
|
noexcept |
Returns true if this string is equal to other.
If a case-insenstive compare is needed, pass CYIString::CaseMode::CaseInsensitiveASCII to the caseSensitivity parameter.
|
noexcept |
Returns true if this string is equal to other, ignoring case differences on ASCII characters.
Removes a portion of the string from character position pos for len characters.
ConstIterator CYIString::Erase | ( | const ConstIterator & | begin, |
const ConstIterator & | end | ||
) |
Removes a portion of the string from iterator begin to iterator end.
The returned iterator points to the character following the last erased character.
ConstIterator CYIString::Find | ( | CYIStringView | view, |
const ConstIterator & | begin | ||
) | const |
Returns the iterator pointing to the next occurrence of view within this string, starting at position begin. Returns End() if view is not found.
ConstIterator CYIString::Find | ( | const char * | pString, |
const ConstIterator & | begin | ||
) | const |
Returns the iterator pointing to the next occurrence of pString within this string, starting at position begin. Returns End() if sub-string pString is not found.
|
static |
Returns the string 'true' if value is true; returns the string 'false' otherwise.
|
static |
Converts the double value value to a string.
The maximum number of decimal places to display can be configured using the decimalPlaces parameter. By default, up to 6 digits are displayed. Use std::numeric_limits<double>::digits10 to display as many digits as can be represented in a floating point value.
By default, trailing zeroes (such as in 1.50000) are omitted (with the exception of the zero after the decimal point). The trailing zeroes can be displayed by setting trailingZeroes to true.
If the useSignificantDigits parameter is set to true, the 'decimal places' parameter is instead interpreted to mean the number of significant digits to be displayed.
|
static |
Converts the float value value to a string.
The maximum number of decimal places to display can be configured using the decimalPlaces parameter. By default, up to 6 digits are displayed. Use std::numeric_limits<float>::digits10 to display as many digits as can be represented in a floating point value.
By default, trailing zeroes (such as in 1.50000) are omitted (with the exception of the zero after the decimal point). The trailing zeroes can be displayed by setting trailingZeroes to true.
If the useSignificantDigits parameter is set to true, the 'decimal places' parameter is instead interpreted to mean the number of significant digits to be displayed.
|
static |
Converts the templated value arg to a string. Custom types are supported so long as they have an implementation of operator<< .
If a conversion error occurs, an empty string is returned. A pointer to a boolean, pError, can optionally be provided – if a conversion error occurs, its pointed-to boolean will be set to true. If no conversion error occurs, the pointed-to boolean will be set to false.
sstream
header must be included.Sample usage:
|
static |
Converts the value arg to a string.
An optional pError pointer is provided for compatibility with generic CYIString::FromValue(const T&, bool*) call; if provided, a value of false will be assigned to the pointed variable since this call cannot fail.
const char* CYIString::GetData | ( | ) | const |
Returns the raw bytes that back this string. While internally the string is encoded in UTF-8, for forward compatibility this should not be relied upon.
size_t CYIString::GetLength | ( | ) | const |
Returns the number of Unicode characters present in the string.
size_t CYIString::GetSizeInBytes | ( | ) | const |
Returns the size of the string in bytes. This does not include the terminating null character – that is, an empty string has a bytes count of 0.
size_t CYIString::IndexOf | ( | CYIStringView | view, |
size_t | pos = 0 |
||
) | const |
Returns the character index of the sub-string view within this string; the function returns CYIString::NPos if the sub-string was not found.
If pos is provided, the search will start at the provided character index.
Returns the character index of the sub-string pString within this string; the function returns CYIString::NPos if the sub-string was not found.
If pos is provided, the search will start at the provided character index.
CYIString& CYIString::Insert | ( | CYIStringView | view, |
size_t | pos, | ||
size_t | len = NPos |
||
) |
Inserts the incoming string view view into the current string at character position pos.
If a value is provided for len, only len characters of view will be inserted into this string.
If pos is larger than the number of characters in this string, the provided string view is appended to this one.
Inserts the incoming string pString into the current string at character position pos. If a value is provided for len, only len characters of pString will be inserted into this string. If pos is larger than the number of characters in this string, the provided string is appended to this one.
ConstIterator CYIString::Insert | ( | CYIStringView | view, |
const ConstIterator & | insertPosition | ||
) |
Inserts the incoming string view view into the current string at the position represented by the iterator insertPosition. The returned iterator points to the position after the last inserted character.
ConstIterator CYIString::Insert | ( | const char * | pString, |
const ConstIterator & | insertPosition | ||
) |
Inserts the incoming string pString into the current string at the position represented by the iterator insertPosition. The returned iterator points to the position after the last inserted character.
ConstIterator CYIString::Insert | ( | const ConstIterator & | begin, |
const ConstIterator & | end, | ||
const ConstIterator & | insertPosition | ||
) |
Inserts the string defined by the pair of iterators begin and end into the current string at the position represented by the iterator insertPosition. The start and end iterators may not be created from this string, and must both be created from teh same string. The returned iterator points to the position after the last inserted character.
bool CYIString::IsEmpty | ( | ) | const |
Returns true if the string's length is 0, false otherwise.
bool CYIString::IsNotEmpty | ( | ) | const |
Returns true if the string's length is greater than 0, false otherwise.
bool CYIString::IsNumeric | ( | ) | const |
Returns true if all characters in this string are ASCII digits. Returns false if this string is empty.
|
static |
Joins all elements of container, separating them by separator.
By default, empty container values are included in the output. Pass false to includeEmptyElements to skip empty values.
By default, elements are converted to CYIString using CYIString::FromValue(). For unsupported types (or to further process the values), a callable object can be passed in to toStringFunction. The callable object must take the value as parameter, and return a CYIString (or an object convertible to CYIStringView).
sstream
header must be included.Sample usage:
size_t CYIString::LastIndexOf | ( | CYIStringView | view, |
size_t | pos = NPos |
||
) | const |
Returns the character index of the sub-string view within this string, starting at the end and searching in reverse; the function returns CYIString::NPos if the sub-string was not found.
If pos is provided, the search will start at the provided character index instead of at the end of the string. In that case, pos would be the position of the last character that would be considered for the beginning of the string view.
Returns the character index of the sub-string pString within this string, starting at the end and searching in reverse; the function returns CYIString::NPos if the sub-string was not found.
If pos is provided, the search will start at the provided character index instead of at the end of the string. In that case, pos would be the position of the last character that would be considered for the beginning of the string pString.
Returns a string containg the first len characters of this string. If len is larger than the length of this string, the full string is returned.
|
noexcept |
Overloaded operator to convert to a CYIStringView. The returned string view is valid only as long as this CYIString remains valid and unmodified.
CYIString CYIString::operator+ | ( | const T & | arg | ) | const |
Concatenates a type to the string. This operator makes use of FromValue() to convert arg to a string, and is equivalent to calling this->Append(CYIString::FromValue(arg));
sstream
header must be included. CYIString CYIString::operator+ | ( | const char * | pUTF8 | ) | const |
Concatenates the null-terminated string pUTF8 to the string.
CYIString& CYIString::operator+= | ( | CYIStringView | view | ) |
Appends the string view view to the current string.
CYIString& CYIString::operator+= | ( | const char * | pUTF8 | ) |
Appends the null-terminatd string pUTF8 to the current string.
bool CYIString::operator< | ( | const char * | pOther | ) | const |
Returns true if this string is 'less' than the provided string. This function performs a lexicographical comparison. An empty string is considered to be 'smaller' than any other non-empty string.
bool CYIString::operator<= | ( | const char * | pOther | ) | const |
Returns true if this string is 'less' than or equal to the provided string. This function performs a lexicographical comparison. An empty string is considered to be 'smaller' than any other non-empty string.
CYIString& CYIString::operator= | ( | const char * | pUTF8 | ) |
Assigns a copy of the UTF-8 encoded array to this string; the array must be null terminated. Providing a nullptr value results in an empty string object.
Moves the string data from s into this string. The string s is left empty.
|
noexcept |
Moves the string data from s into this string. The string s is left empty.
bool CYIString::operator> | ( | const char * | pOther | ) | const |
Returns true if this string is 'greater' than the provided string. This function performs a lexicographical comparison. An empty string is considered to be 'smaller' than any other non-empty string.
bool CYIString::operator>= | ( | const char * | pOther | ) | const |
Returns true if this string is 'greater' than or equal to the provided string. This function performs a lexicographical comparison. An empty string is considered to be 'smaller' than any other non-empty string.
char32_t CYIString::operator[] | ( | size_t | pos | ) | const |
Returns the 32-bit Unicode value at that character position specified by pos. Cannot be modified. The position must be a valid index position in the string; otherwise, a value of 0 is returned.
CYIString& CYIString::Prepend | ( | CYIStringView | view | ) |
Prepends the incoming string view view to the current string.
Prepends the incoming string pUTF8 to the current string.
By default, this function expects a null-terminated array. The size parameter can be used to instead provide a number of bytes to read from the array. If pUTF8 is nullptr, this function does nothing.
ConstIterator CYIString::Prepend | ( | const ConstIterator & | begin, |
const ConstIterator & | end | ||
) |
Prepends the string defined by the pair of iterators begin and end to this string. The provided iterators do not have to be from this string, but they both have to have been created from the same string.
The returned iterator points to the character following the last prepended character.
ConstReverseIterator CYIString::rbegin | ( | ) | const |
Returns the reverse iterator to the end of the string. This iterator iterates over Unicode characters rather than over bytes.
void CYIString::Remove | ( | CYIStringView | text | ) |
Remove all occurences of text from the current string.
void CYIString::Remove | ( | const char * | pString | ) |
Remove all occurences of pString from the current string.
void CYIString::RemovePrefix | ( | size_t | len | ) |
Removes the first len characters from this string. If there are fewer than len characters in the string, the string becomes empty.
bool CYIString::RemovePrefix | ( | CYIStringView | prefix, |
CaseMode | caseSensitivity = CaseMode::CaseSensitive |
||
) |
Removes prefix from the beginning of this string if this string begins with prefix. Otherwise, this function does nothing. Returns true if prefix was found.
If a case-insensitive compare is needed, pass CaseMode::CaseInsensitiveASCII to the caseSensitivity parameter.
void CYIString::RemoveSuffix | ( | size_t | len | ) |
Removes the last len characters from this string. If there are fewer than len characters in the string, the string becomes empty.
bool CYIString::RemoveSuffix | ( | CYIStringView | prefix, |
CaseMode | caseSensitivity = CaseMode::CaseSensitive |
||
) |
Removes suffix from the end of this string if this string ends with suffix. Otherwise, this function does nothing. Returns true if suffix was found.
If a case-insensitive compare is needed, pass CaseMode::CaseInsensitiveASCII to the caseSensitivity parameter.
ConstReverseIterator CYIString::rend | ( | ) | const |
Returns the reverse iterator to the beginning of the string. This iterator iterates over Unicode characters rather than over bytes.
CYIString& CYIString::Replace | ( | CYIStringView | view, |
size_t | pos, | ||
size_t | len | ||
) |
Replaces a portion of the string from character position pos for len characters with the view string view.
If pos is larger than the length of this string, the provided string view is appended to this one. If len is longer than this string, the whole string is replaced by view.
Replaces a portion of the string from character position pos for len characters with the pString string.
If pos is larger than the length of this string, the provided string is appended to this one. If len is longer than this string, the whole string is replaced by pString.
ConstIterator CYIString::Replace | ( | CYIStringView | view, |
const ConstIterator & | begin, | ||
const ConstIterator & | end | ||
) |
Replaces a portion of the string from iterator begin to iterator end with the string view view.
The returned iterator points to the character after the last replacement character.
ConstIterator CYIString::Replace | ( | const char * | pString, |
const ConstIterator & | begin, | ||
const ConstIterator & | end | ||
) |
Replaces a portion of the string from iterator begin to iterator end with the string pString.
The returned iterator points to the character after the last replacement character.
CYIString& CYIString::Replace | ( | CYIStringView | oldSubstring, |
CYIStringView | newSubstring, | ||
size_t | maximumReplacements = NPos |
||
) |
Replaces all occurences of the sub-string oldSubstring within this string with the sub-string newSubstring.
If value is specified for maximumReplacements, only up to maximumReplacements replacements will be performed.
CYIString& CYIString::Replace | ( | const char * | pOldSubstring, |
const char * | pNewSubstring, | ||
size_t | maximumReplacements = NPos |
||
) |
Replaces all occurences of the sub-string oldSubstring within this string with the sub-string newSubstring.
If value is specified for maximumReplacements, only up to maximumReplacements replacements will be performed.
void CYIString::Reserve | ( | size_t | bytes | ) |
Pre-allocates enough storage to store bytes bytes of data.
ConstReverseIterator CYIString::ReverseFind | ( | CYIStringView | view, |
const ConstReverseIterator & | begin | ||
) | const |
Returns the iterator pointing to the 'next' occurrence of view within this string, starting at position begin. Since this function works on reverse iterators, the 'next' occurrence is really the previous occurrence within the string. Returns REnd() if view is not found.
ConstReverseIterator CYIString::ReverseFind | ( | const char * | pString, |
const ConstReverseIterator & | begin | ||
) | const |
Returns the iterator pointing to the 'next' occurrence of pString within this string, starting at position begin. Since this function works on reverse iterators, the 'next' occurrence is really the previous occurrence within the string. Returns REnd() if pString is not found.
Returns a string containg the last len characters of this string. If len is larger than the length of this string, the full string is returned.
std::vector<CYIString> CYIString::Split | ( | CYIStringView | delimiter, |
bool | ignoreEmptySubstrings = true , |
||
size_t | maximumParts = NPos |
||
) | const |
Splits the current string into a vector of strings whenever the delimeter occurs in the string.
If ignoreEmptySubstrings is true, 'empty' substrings are not included in the returned vector.
The maximumParts parameter can be used to specify the maximum number of elements to return in the vector. When more than ( maximumParts - 1 ) parts are found during splitting, the remaining parts will be left as is and appended to the vector. For example, calling CYIString("foo;bar;baz").Split(";", true, 2) would result in a vector containing 'foo' and 'bar;baz' being returned. Providing a value of 0 to maximumParts will result in an empty vector being returned, and providing a value of 1 will result in the original string being returned as the sole element in the vector. When ignoreEmptySubstrings is true, 'empty' substrings do not count towards the parts count. A value of CYIString::NPos indicates that there is no parts limit.
bool CYIString::StartsWith | ( | CYIStringView | s, |
CaseMode | caseSensitivity = CaseMode::CaseSensitive |
||
) | const |
Returns true if the string starts with the sub-string s.
If a case-insensitive compare is needed, pass CaseMode::CaseInsensitiveASCII to the caseSensitivity parameter.
bool CYIString::StartsWith | ( | const char * | pString, |
CaseMode | caseSensitivity = CaseMode::CaseSensitive |
||
) | const |
Returns true if the string starts with the sub-string pString.
If a case-insenstive compare is needed, pass CaseMode::CaseInsensitiveASCII to the caseSensitivity parameter.
Returns the sub-string of the current string from character position pos for len characters. A len value of CYIString::NPos indicates that the sub-string from pos to the end of the string should be returned. Returns an empty string in the case of invalid pos or len values.
CYIString CYIString::SubStr | ( | const ConstIterator & | begin, |
const ConstIterator & | end | ||
) | const |
Returns the sub-string of the current string from iterator begin to iterator end.
void CYIString::Swap | ( | CYIString & | s | ) |
Swaps the contents of the string with the contents of s.
std::string CYIString::TakeStdString | ( | ) |
T CYIString::To | ( | bool * | pError = nullptr | ) | const |
Converts this string to the specified template type T. Custom types are supported so long as they have an implementation of operator>> .
If a conversion error occurs, an object created with the default constructor is returned. A pointer to a boolean, pError, can optionally be provided – if a conversion error occurs, its pointed-to boolean will be set to true. If no conversion error occurs, the pointed-to boolean will be set to false.
sstream
header must be included.Sample usage:
bool CYIString::ToBool | ( | bool * | pError = nullptr | ) | const |
Interprets the provided string as a boolean. The following string values will result in a value of true being returned:
The following string values will result in a value of false being returned:
All string values are case-insensitive. Leading and trailing spaces are ignored.
Any other string value will be considered a conversion error and will result in a value of false being returned. A pointer to a boolean, pError, can optionally be provided – if a conversion error occurs, its pointed-to boolean will be set to true. If no conversion error occurs, the pointed-to boolean will be set to false.
CFStringRef CYIString::ToCFStringRef | ( | ) | const |
Returns the CFStringRef representation of this string. The caller is responsible for deleting this resource (using CFRelease).
double CYIString::ToDouble | ( | bool * | pError = nullptr | ) | const |
Converts this string to a double-precision floating point value.
If a conversion error occurs, 0.0 is returned. A pointer to a boolean, pError, can optionally be provided – if a conversion error occurs, its pointed-to boolean will be set to true. If no conversion error occurs, the pointed-to boolean will be set to false.
float CYIString::ToFloat | ( | bool * | pError = nullptr | ) | const |
Converts this string to a single-precision floating point value.
If a conversion error occurs, 0.0f is returned. A pointer to a boolean, pError, can optionally be provided – if a conversion error occurs, its pointed-to boolean will be set to true. If no conversion error occurs, the pointed-to boolean will be set to false.
CYIString CYIString::ToHexadecimal | ( | ) | const |
Returns the hexadecimal representation of the raw bytes that back this string. The returned characters are always in lowercase. Calling this function on an empty string returns an empty string.
For example, calling this function on the string "K" would return "4b", and calling this function on the string "You.i" would return "596f752e69".
CYIString CYIString::ToLowerASCII | ( | ) | const |
Returns a lowercase version of this string. This string is not modified.
NSString* CYIString::ToNSString | ( | ) | const |
Returns the NSString representation of this string.
const std::string& CYIString::ToStdString | ( | ) | const |
Returns the STL string representation of this string.
std::wstring CYIString::ToStdWString | ( | ) | const |
Returns the STL wstring representation of this string.
CYIString CYIString::ToUpperASCII | ( | ) | const |
Returns an uppercase version of this string. This string is not modified.
std::unique_ptr<char16_t[]> CYIString::ToUTF16 | ( | size_t * | pElementsCount = nullptr | ) | const |
Returns a new instance of the null-terminated UTF-16 representation of this string.
If needed, the resulting number of char16_t elements in the returned array (excluding the null terminator) can be obtained by passing in a pointer to an size_t in pElementsCount.
std::unique_ptr<char32_t[]> CYIString::ToUTF32 | ( | size_t * | pElementsCount = nullptr | ) | const |
Returns a new instance of the null-terminated UTF-32 representation of this string.
If needed, the resulting number of char32_t elements in the returned array (excluding the null terminator) can be obtained by passing in a pointer to an size_t in pElementsCount.
std::unique_ptr<char[]> CYIString::ToUTF8 | ( | size_t * | pElementsCount = nullptr | ) | const |
Returns a new instance of the null-terminated UTF-8 representation of this string.
If needed, the resulting number of char elements in the returned array (excluding the null terminator) can be obtained by passing in a pointer to an size_t in pElementsCount.
T CYIString::ToValue | ( | bool * | pError = nullptr | ) | const |
Converts this string to the specified template type T. Custom types are supported so long as they have an implementation of operator>> .
If a conversion error occurs, an object created with the default constructor is returned. A pointer to a boolean, pError, can optionally be provided – if a conversion error occurs, its pointed-to boolean will be set to true. If no conversion error occurs, the pointed-to boolean will be set to false.
sstream
header must be included.Sample usage:
std::unique_ptr<wchar_t[]> CYIString::ToWideChars | ( | size_t * | pElementsCount = nullptr | ) | const |
Returns a new instance of the null-terminated wchar_t respresentation for this string.
If needed, the resulting number of wchar_t elements in the returned array (excluding the null terminator) can be obtained by passing in a pointer to an size_t pElementsCount.
void CYIString::Trim | ( | ) |
Trims whitespace at the beginning and at the end of the string.
Trims whitespace at the beginning of the string. The amount of removed whitespace can be limited using the len parameter. By default, all whitespace characters at the beginning of the string are removed.
Trims whitespace at the end of the string. The amount of removed whitespace can be limited using the len parameter. By default, all whitespace characters at the end of the string are removed.
|
friend |
|
friend |
Reads a single element from the stream stream and assigns it to the string val. By default, elements are delimited by whitespace characters, through this can be changed within the stream. The old value of val is discarded, even if an error occurred reading from the stream.
A constant whose meaning is context-dependent but usually means 'not found' or 'no limit'.