Samchon Framework for CPP
1.0.0
|
A string class only references characeters, reference only. More...
#include <WeakString.hpp>
Public Member Functions | |
WeakString () | |
Default Constructor does not reference any character. More... | |
WeakString (const char *data, size_t size) | |
Constructor by characters with specified size. More... | |
WeakString (const char *begin, const char *end) | |
Constructor by characters of begin and end. More... | |
WeakString (const char *data) | |
Constructor by characters. More... | |
WeakString (const char &ch) | |
Constructor by a single character. More... | |
WeakString (std::initializer_list< char > &il) | |
Constructor by a initializer list. More... | |
WeakString (const std::string &str) | |
Constructor by string. More... | |
auto | data () const -> const char * |
Get string data; referenced characeters. More... | |
auto | size () const -> size_t |
Returns size of the characters which are being referenced. More... | |
auto | empty () const -> bool |
Tests wheter string is emtpy. More... | |
auto | at (size_t index) const -> const char & |
Get character of string Returns a const reference to the character at the specified position. More... | |
auto | operator[] (size_t index) const -> const char & |
Get character of string Returns a const reference to the character at the specified position. More... | |
auto | find (const WeakString &delim, size_t startIndex=NULL) const -> size_t |
Finds first occurence in string. More... | |
auto | rfind (const WeakString &delim, size_t endIndex=SIZE_MAX) const -> size_t |
Finds last occurence in string. More... | |
auto | finds (const std::vector< std::string > &delims, size_t startIndex=0) const -> IndexPair< WeakString > |
Finds first occurence in string. More... | |
auto | rfinds (const std::vector< std::string > &delims, size_t endIndex=SIZE_MAX) const -> IndexPair< WeakString > |
Finds last occurence in string. More... | |
auto | substr (size_t startIndex, size_t endIndex=SIZE_MAX) const -> WeakString |
Generates a substring. More... | |
auto | substring (size_t startIndex, size_t size=SIZE_MAX) const -> WeakString |
Generates a substring. More... | |
auto | between (const WeakString &start={}, const WeakString &end={}) const -> WeakString |
Generates a substring. More... | |
auto | split (const WeakString &delim) const -> std::vector< WeakString > |
Generates substrings. More... | |
auto | betweens (const WeakString &start={}, const WeakString &end={}) const -> std::vector< WeakString > |
Generates substrings. More... | |
auto | trim (const std::vector< std::string > &delims) const -> WeakString |
Removes all designated characters from the beginning and end of the specified string. More... | |
auto | ltrim (const std::vector< std::string > &delims) const -> WeakString |
Removes all designated characters from the beginning of the specified string. More... | |
auto | rtrim (const std::vector< std::string > &delims) const -> WeakString |
Removes all designated characters from the end of the specified string. More... | |
auto | replace (const WeakString &before, const WeakString &after) const -> std::string |
Replace portion of string once. More... | |
auto | replaceAll (const WeakString &before, const WeakString &after) const -> std::string |
Returns a string specified word is replaced. More... | |
auto | replaceAll (const std::vector< std::pair< std::string, std::string >> &pairs) const -> std::string |
Returns a string specified words are replaced. More... | |
auto | toLowerCase () const -> std::string |
Convert uppercase letters to lowercase. More... | |
auto | toUpperCase () const -> std::string |
Convert uppercase letters to lowercase. More... | |
auto | str () const -> std::string |
Get the string content. More... | |
Static Public Attributes | |
static const size_t | npos = -1 |
Maximum value for size_t. More... | |
Private Attributes | |
const char * | data_ |
Referenced characters's pointer of begining position. More... | |
size_t | size_ |
(Specified) size of referenced characters More... | |
Static Private Attributes | |
static const std::vector< std::string > | SPACE_ARRAY = { " ", "\t", "\r", "\n" } |
An array containing whitespaces. More... | |
A string class only references characeters, reference only.
WeakSring does not consider any construction, modification and destruction of characters.
Thus, you can have greater advantages than std::string on the side of performance and memory, but of course, you can't modify the characeters at all.
Definition at line 32 of file WeakString.hpp.
WeakString::WeakString | ( | ) |
Default Constructor does not reference any character.
Constructs an empty string, with zero size
Definition at line 18 of file WeakString.cpp.
Referenced by rfinds(), substr(), and substring().
WeakString::WeakString | ( | const char * | data, |
size_t | size | ||
) |
Constructor by characters with specified size.
Constructs by characters to be referenced with limited size.
Although the original size of data is over the specified size, you can limit referencing size of the characters
data | Target characters to be referenced by string |
size |
Specified limit-size of characters to be referenced.
If the specified size is greater than original size, it will be ignored
Definition at line 23 of file WeakString.cpp.
WeakString::WeakString | ( | const char * | begin, |
const char * | end | ||
) |
Constructor by characters of begin and end.
Constructs by characters to be referenced with its end position.
Although the original end point of data is over the specified end, you can limit end point of the characters.
begin | Target characters to be referenced by string |
end |
Specified end point of characters to be referenced.
If the specified end point is greater than original end point, it will be ignored.
Definition at line 29 of file WeakString.cpp.
WeakString::WeakString | ( | const char * | data | ) |
Constructor by characters.
References the null-terminated character sequence pointed by ptr
data | Target characters to be referenced by string |
Definition at line 33 of file WeakString.cpp.
References data(), data_, and size_.
WeakString::WeakString | ( | const char & | ch | ) |
Constructor by a single character.
References a single character
ch | Target character to be referenced by string |
Definition at line 42 of file WeakString.cpp.
WeakString::WeakString | ( | std::initializer_list< char > & | il | ) |
Constructor by a initializer list.
References initializer list of character
il | Target initializer list of characters to be referenced by string |
Definition at line 47 of file WeakString.cpp.
WeakString::WeakString | ( | const std::string & | str | ) |
Constructor by string.
References whole chracters of the string
str | Target string to be referenced by string |
Definition at line 56 of file WeakString.cpp.
auto WeakString::data | ( | ) | const -> const char* |
Get string data; referenced characeters.
Returns a pointer to an array that contains a null-terminated sequence of characters representing the current value of the string object
Definition at line 65 of file WeakString.cpp.
References data_.
Referenced by WeakString().
auto WeakString::size | ( | ) | const -> size_t |
Returns size of the characters which are being referenced.
Returns the length of the string, in terms of number of referenced characters
Definition at line 69 of file WeakString.cpp.
References size_.
Referenced by betweens(), replace(), replaceAll(), split(), substr(), toUpperCase(), and samchon::library::XML::XML().
auto WeakString::empty | ( | ) | const -> bool |
Tests wheter string is emtpy.
Returns wheter characters' size is zero or not.
Of course, string references nothing, then returns false, too.
Definition at line 74 of file WeakString.cpp.
Referenced by betweens(), samchon::library::XML::push_back(), and rfind().
auto WeakString::at | ( | size_t | index | ) | const -> const char& |
Get character of string Returns a const reference to the character at the specified position.
Definition at line 79 of file WeakString.cpp.
References data_.
Referenced by toUpperCase().
auto WeakString::operator[] | ( | size_t | index | ) | const -> const char& |
Get character of string Returns a const reference to the character at the specified position.
Definition at line 83 of file WeakString.cpp.
References data_.
auto WeakString::find | ( | const WeakString & | delim, |
size_t | startIndex = NULL |
||
) | const -> size_t |
Finds first occurence in string.
Finds the string after startIndex and returns the position of first occurence of delim.
If delim is not found, returns -1 (npos)
delim | The substring of the string which to find |
startIndex | Specified starting index of find. Default is 0 |
Definition at line 91 of file WeakString.cpp.
References data_, npos, and size_.
Referenced by between(), betweens(), finds(), samchon::library::HTTPLoader::load(), replace(), replaceAll(), samchon::library::Datetime::set(), samchon::library::Date::set(), split(), samchon::library::URLVariables::URLVariables(), and samchon::library::XML::XML().
auto WeakString::rfind | ( | const WeakString & | delim, |
size_t | endIndex = SIZE_MAX |
||
) | const -> size_t |
Finds last occurence in string.
Finds the string before endIndex and returns the position of last occurence of delim. If delim is not found, returns -1 (npos)
delim | The substring of the string which to find |
endIndex | Specified last index of find. Default is size() - 1 |
Definition at line 103 of file WeakString.cpp.
References data_, empty(), npos, and size_.
Referenced by betweens(), rfinds(), and samchon::library::XML::XML().
auto WeakString::finds | ( | const std::vector< std::string > & | delims, |
size_t | startIndex = 0 |
||
) | const -> IndexPair<WeakString> |
Finds first occurence in string.
Finds first occurence position of each delim in the string after startIndex and returns the minimum position of them.
delims | The substrings of target(str) which to find |
startIndex | Specified starting index of find. Default is 0 |
Definition at line 121 of file WeakString.cpp.
References find(), samchon::IndexPair< T >::getIndex(), and samchon::IndexPair< T >::getValue().
Referenced by samchon::library::StringUtil::finds().
auto WeakString::rfinds | ( | const std::vector< std::string > & | delims, |
size_t | endIndex = SIZE_MAX |
||
) | const -> IndexPair<WeakString> |
Finds last occurence in string.
Finds last occurence position of each delim in the string before endIndex and returns the maximum position of them.
delims | The substrings of target(str) which to find |
endIndex | Specified starting index of find. Default is size() - 1 |
Definition at line 141 of file WeakString.cpp.
References samchon::IndexPair< T >::getIndex(), samchon::IndexPair< T >::getValue(), rfind(), and WeakString().
Referenced by samchon::library::StringUtil::rfinds().
auto WeakString::substr | ( | size_t | startIndex, |
size_t | endIndex = SIZE_MAX |
||
) | const -> WeakString |
Generates a substring.
Extracts a substring consisting of the characters starts from startIndex and with a size specified size.
startIndex |
Index of the first character.
If startIndex is greater than endIndex, those will be swapped.
endIndex |
Number of characters to include in substring.
If the specified size is greater than last index of characeters, it will be shrinked.
Definition at line 174 of file WeakString.cpp.
References data_, size(), size_, and WeakString().
Referenced by between(), samchon::library::HTTPLoader::load(), replace(), replaceAll(), samchon::library::URLVariables::URLVariables(), and samchon::library::XML::XML().
auto WeakString::substring | ( | size_t | startIndex, |
size_t | size = SIZE_MAX |
||
) | const -> WeakString |
Generates a substring.
Extracts a substring consisting of the character specified by startIndex and all characters up to endIndex - 1.
startIndex |
Index of the first character.
If startIndex is greater than endIndex, those will be swapped.
size |
Index of the last character - 1.
If not specified, then string::size() will be used instead.
Definition at line 181 of file WeakString.cpp.
References data_, size_, and WeakString().
Referenced by between(), betweens(), replaceAll(), split(), samchon::library::StringUtil::substring(), and samchon::library::XML::XML().
auto WeakString::between | ( | const WeakString & | start = {} , |
const WeakString & | end = {} |
||
) | const -> WeakString |
Generates a substring.
Extracts a substring consisting of the characters from specified start to end.
It's same with substring( ? = (str.find(start) + start.size()), find(end, ?) )
start | A string for separating substring at the front |
end | A string for separating substring at the end |
Definition at line 194 of file WeakString.cpp.
References find(), substr(), and substring().
Referenced by samchon::library::StringUtil::between(), samchon::library::HTTPLoader::load(), samchon::protocol::IWebServer::open(), samchon::library::Datetime::set(), samchon::library::Date::set(), and samchon::library::XML::XML().
auto WeakString::split | ( | const WeakString & | delim | ) | const -> std::vector<WeakString> |
Generates substrings.
Splits a string in to an array of substrings dividing by the specified delimiter
delim | The pattern which specifies where to split the string |
Definition at line 212 of file WeakString.cpp.
References find(), npos, size(), and substring().
Referenced by betweens(), samchon::library::HTTPLoader::load(), samchon::library::Date::set(), samchon::library::StringUtil::split(), and samchon::library::URLVariables::URLVariables().
auto WeakString::betweens | ( | const WeakString & | start = {} , |
const WeakString & | end = {} |
||
) | const -> std::vector<WeakString> |
Generates substrings.
Splits a string into an array of substrings dividing by delimeters of start and end.
It's the array of substrings adjusted the between.
start |
A string for separating substring at the front.
If omitted, it's same with split(end) not having last item.
end |
A string for separating substring at the end.
If omitted, it's same with split(start) not having first item.
Definition at line 237 of file WeakString.cpp.
References data_, empty(), find(), samchon::IndexPair< T >::getIndex(), samchon::IndexPair< T >::getValue(), ltrim(), npos, rfind(), rtrim(), size(), size_, SPACE_ARRAY, split(), str(), substring(), and trim().
Referenced by samchon::library::StringUtil::betweens(), and samchon::protocol::IClient::listen().
auto WeakString::trim | ( | const std::vector< std::string > & | delims | ) | const -> WeakString |
Removes all designated characters from the beginning and end of the specified string.
delims | Designated character(s) |
Definition at line 374 of file WeakString.cpp.
References trim().
Referenced by betweens(), samchon::library::StringUtil::colorPercentFormat(), samchon::library::XML::hasProperty(), samchon::library::Date::set(), trim(), and samchon::library::XML::XML().
auto WeakString::ltrim | ( | const std::vector< std::string > & | delims | ) | const -> WeakString |
Removes all designated characters from the beginning of the specified string.
delims | Designated character(s) |
Definition at line 382 of file WeakString.cpp.
References ltrim().
Referenced by betweens(), samchon::library::StringUtil::colorPercentFormat(), and ltrim().
auto WeakString::rtrim | ( | const std::vector< std::string > & | delims | ) | const -> WeakString |
Removes all designated characters from the end of the specified string.
delims | Designated character(s) |
Definition at line 390 of file WeakString.cpp.
References rtrim().
Referenced by betweens(), samchon::library::StringUtil::colorPercentFormat(), and rtrim().
auto WeakString::replace | ( | const WeakString & | before, |
const WeakString & | after | ||
) | const -> std::string |
Replace portion of string once.
before | A specific word you want to be replaced |
after | A specific word you want to replace |
Definition at line 402 of file WeakString.cpp.
References find(), npos, size(), str(), and substr().
auto WeakString::replaceAll | ( | const WeakString & | before, |
const WeakString & | after | ||
) | const -> std::string |
Returns a string specified word is replaced.
before | A specific word you want to be replaced |
after | A specific word you want to replace |
Definition at line 418 of file WeakString.cpp.
Referenced by samchon::library::XML::hasProperty(), replaceAll(), and samchon::library::StringUtil::toUpperCase().
auto WeakString::replaceAll | ( | const std::vector< std::pair< std::string, std::string >> & | pairs | ) | const -> std::string |
Returns a string specified words are replaced.
str | Target string to replace |
pairs | A specific word's pairs you want to replace and to be replaced |
Definition at line 423 of file WeakString.cpp.
References find(), npos, replaceAll(), size(), str(), substr(), and substring().
auto WeakString::toLowerCase | ( | ) | const -> std::string |
Convert uppercase letters to lowercase.
Returns a string that all uppercase characters are converted to lowercase.
wstr | Target string to convert uppercase to lowercase |
Definition at line 491 of file WeakString.cpp.
References str().
Referenced by samchon::library::StringUtil::toLowerCase().
auto WeakString::toUpperCase | ( | ) | const -> std::string |
Convert uppercase letters to lowercase.
Returns a string all lowercase characters are converted to uppercase.
str | Target string to convert lowercase to uppercase |
Definition at line 500 of file WeakString.cpp.
References at(), size(), and str().
Referenced by samchon::library::StringUtil::toUpperCase().
auto WeakString::str | ( | ) | const -> std::string |
Get the string content.
Returns a string object with a copy of the current contents in the WeakString.
Definition at line 546 of file WeakString.cpp.
Referenced by betweens(), samchon::protocol::IHTMLEntity::IHTMLEntity(), samchon::protocol::InvokeParameter::InvokeParameter(), samchon::library::HTTPLoader::load(), replace(), replaceAll(), samchon::library::XML::setProperty(), samchon::library::XML::setValue(), toLowerCase(), and toUpperCase().
|
staticprivate |
An array containing whitespaces.
Definition at line 38 of file WeakString.hpp.
Referenced by betweens().
|
static |
Maximum value for size_t.
npos is a static member constant value with the greatest possible value for an element of type size_t.
This value, when used as the value for a len (or sublen) parameter in string's member functions, means "until the end of the string". As a return value, it is usually used to indicate no matches.
This constant is defined with a value of -1, which because size_t is an unsigned integral type, it is the largest possible representable value for this type.
Definition at line 53 of file WeakString.hpp.
Referenced by betweens(), find(), replace(), replaceAll(), rfind(), and split().
|
private |
Referenced characters's pointer of begining position.
Definition at line 59 of file WeakString.hpp.
Referenced by at(), betweens(), data(), empty(), find(), operator[](), rfind(), str(), substr(), substring(), and WeakString().
|
private |
(Specified) size of referenced characters
Definition at line 64 of file WeakString.hpp.
Referenced by betweens(), empty(), find(), rfind(), size(), str(), substr(), substring(), and WeakString().