Samchon Framework for CPP
1.0.0
|
Utility class for string. More...
#include <StringUtil.hpp>
Static Public Member Functions | |
template<typename T , typename... _Args> | |
static auto | substitute (const std::string &format, const T &val, const _Args &...args) -> std::string |
Substitutes "{n}" tokens within the specified string with the respective arguments passed in. More... | |
template<typename T , typename... _Args> | |
static auto | substituteSQL (const std::string &format, const T &value, const _Args &...args) -> std::string |
Substitutes "{n}" tokens within the specified sql-string with the respective arguments passed in. . More... | |
static auto | isNumeric (const std::string &str) -> bool |
Returns wheter the std::string represents Number or not . More... | |
static auto | toNumber (const std::string &str) -> double |
Number std::string to Number having ',' symbols. More... | |
static auto | numberFormat (double val, int precision=2) -> std::string |
static auto | percentFormat (double val, int precision=2) -> std::string |
Returns a percentage string converted from the number rounded off from specified precision with "," symbols ex) percentFormat(11.3391, 1) => 1,133.9%. More... | |
static auto | colorNumberFormat (double value, int precision=2, double delimiter=0.0) -> std::string |
Returns a string converted from the number rounded off from specified precision with "," symbols and color tag ex) numberFormat(17151.339, 2) => <font color="red">17,151.34</font> More... | |
static auto | colorPercentFormat (double value, int precision=2, double delimiter=0.0) -> std::string |
Returns a percentage string converted from the number rounded off from specified precision with "," symbols ex) percentFormat(11.3391, 1) => 1,133.9%. More... | |
static auto | trim (const std::string &val, const std::vector< std::string > &delims) -> std::string |
Removes all designated characters from the beginning and end of the specified string. More... | |
static auto | ltrim (const std::string &val, const std::vector< std::string > &delims) -> std::string |
Removes all designated characters from the beginning of the specified string. More... | |
static auto | rtrim (const std::string &val, const std::vector< std::string > &delims) -> std::string |
Removes all designated characters from the end of the specified string. More... | |
static auto | finds (const std::string &str, const std::vector< std::string > &delims, size_t startIndex=0) -> IndexPair< std::string > |
Finds first occurence in string. More... | |
static auto | rfinds (const std::string &str, const std::vector< std::string > &delims, size_t endIndex=SIZE_MAX) -> IndexPair< std::string > |
Finds last occurence in string. More... | |
static auto | substring (const std::string &str, size_t startIndex, size_t endIndex=SIZE_MAX) -> std::string |
Generates a substring. More... | |
static auto | between (const std::string &str, const std::string &start="", const std::string &end="") -> std::string |
Generate a substring. More... | |
static auto | addTab (const std::string &str, size_t n=1) -> std::string |
Adds tab() character to first position of each line. More... | |
static auto | split (const std::string &str, const std::string &delim) -> std::vector< std::string > |
Generates substrings. More... | |
static auto | betweens (const std::string &str, const std::string &start="", const std::string &end="") -> std::vector< std::string > |
Generates substrings. More... | |
static auto | toLowerCase (const std::string &str) -> std::string |
Returns a string that all uppercase characters are converted to lowercase. More... | |
static auto | yoUpperCase (const std::string &str) -> std::string |
static auto | replaceAll (const std::string &str, const std::string &before, const std::string &after) -> std::string |
Returns a string specified word is replaced. More... | |
static auto | replaceAll (const std::string &str, const std::vector< std::pair< std::string, std::string >> &pairs) -> std::string |
Returns a string specified words are replaced. More... | |
static auto | removeHTMLSpaces (const std::string &str) -> std::string |
Replace all HTML spaces to a literal space. More... | |
Utility class for string.
StringUtil is an utility class providing lots of static methods for std::string.
There are two methods to strength std::string to have addictional uility methods like trim and split. The way of first is to make std::string class inheriting from std::string. The second is to make StringUtil class having static methods.
But those methods have problems. std::string class violates standard and StringUtil class violates principle of Object-Oriented Design. For the present, I've made the StringUtil class, but if you have a good opinion about the issue, please write your opinion on my github.
Definition at line 36 of file StringUtil.hpp.
|
inlinestatic |
Substitutes "{n}" tokens within the specified string with the respective arguments passed in.
format | The string to make substitutions in. This string can contain special tokens of the form {n}, where n is a zero based index, that will be replaced with the additional parameters found at that index if specified |
val | Target value to substitute the minimum {n} tokens |
args | Additional parameters that can be substituted in the str parameter at each {n} location, where n is an integer (zero based) index value into the varadics of values specified. |
Definition at line 54 of file StringUtil.hpp.
Referenced by colorNumberFormat(), colorPercentFormat(), samchon::protocol::WebServerConnector::connect(), samchon::library::SQLi::connect(), samchon::library::HTTPLoader::load(), samchon::examples::packer::Instance::toString(), samchon::examples::tsp::GeometryPoint::toString(), samchon::library::Date::toString(), and samchon::protocol::WebServer::WebServer().
|
inlinestatic |
Substitutes "{n}" tokens within the specified sql-string with the respective arguments passed in.
.
format | The string to make substitutions in. This string can contain special tokens of the form {n}, where n is a zero based index, that will be replaced with the additional parameters found at that index if specified |
val | Target value to substitute the minimum {n} tokens |
args | Additional parameters that can be substituted in the str parameter at each {n} location, where n is an integer (zero based) index value into the varadics of values specified. |
Definition at line 80 of file StringUtil.hpp.
References betweens(), samchon::WeakString::empty(), samchon::WeakString::find(), isNumeric(), samchon::library::Math::minimum(), replaceAll(), samchon::WeakString::replaceAll(), and samchon::WeakString::str().
|
inlinestatic |
Returns wheter the std::string represents Number or not
.
str | Target std::string to check |
Definition at line 198 of file StringUtil.hpp.
Referenced by substituteSQL().
|
inlinestatic |
Number std::string to Number having ',' symbols.
str | Target std::string you want to convert to Number |
Definition at line 223 of file StringUtil.hpp.
References replaceAll().
|
inlinestatic |
Returns a string converted from the number rounded off from specified precision with "," symbols ex) numberFormat(17151.339, 2) => 17,151.34
val | A number wants to convert to string |
precision | Target precision of roundoff |
Definition at line 241 of file StringUtil.hpp.
Referenced by colorNumberFormat(), percentFormat(), and samchon::examples::tsp::Travel::toString().
|
inlinestatic |
Returns a percentage string converted from the number rounded off from specified precision with "," symbols
ex) percentFormat(11.3391, 1) => 1,133.9%.
val | A number wants to convert to percentage string |
precision | Target precision of roundoff |
Definition at line 303 of file StringUtil.hpp.
References numberFormat().
Referenced by colorPercentFormat().
|
inlinestatic |
Returns a string converted from the number rounded off from specified precision with "," symbols and color tag
ex) numberFormat(17151.339, 2) => <font color="red">17,151.34</font>
Which color would be chosen
val | A number wants to convert to colored string |
precision | Target precision of roundoff |
Definition at line 325 of file StringUtil.hpp.
References numberFormat(), and substitute().
|
inlinestatic |
Returns a percentage string converted from the number rounded off from specified precision with "," symbols
ex) percentFormat(11.3391, 1) => 1,133.9%.
val | A number wants to convert to percentage string |
precision | Target precision of roundoff |
Definition at line 349 of file StringUtil.hpp.
References percentFormat(), and substitute().
|
inlinestatic |
Removes all designated characters from the beginning and end of the specified string.
str | The string should be trimmed |
delims | Designated character(s) |
Definition at line 376 of file StringUtil.hpp.
Referenced by rtrim().
|
inlinestatic |
Removes all designated characters from the beginning of the specified string.
str | The string should be trimmed |
delims | Designated character(s) |
Definition at line 388 of file StringUtil.hpp.
Referenced by rtrim().
|
inlinestatic |
Removes all designated characters from the end of the specified string.
str | The string should be trimmed |
delims | Designated character(s) |
Definition at line 400 of file StringUtil.hpp.
References ltrim(), and trim().
|
inlinestatic |
Finds first occurence in string.
Finds first occurence position of each delim in the string after startIndex and returns the minimum position of them
If startIndex is not specified, then starts from 0.
If failed to find any substring, returns -1 (std::string::npos)
str | Target string to find |
delims | The substrings of target(str) which to find |
startIndex | Specified starting index of find. Default is 0 |
Definition at line 449 of file StringUtil.hpp.
References samchon::WeakString::finds(), samchon::IndexPair< T >::get_index(), and samchon::IndexPair< T >::getValue().
|
inlinestatic |
Finds last occurence in string.
Finds last occurence position of each delim in the string before endIndex and returns the maximum position of them
If index is not specified, then starts str.size() - 1
If failed to find any substring, returns -1 (std::string::npos)
str | Target string to find |
delims | The substrings of target(str) which to find |
endIndex | Specified starting index of find. Default is str.size() - 1 |
Definition at line 472 of file StringUtil.hpp.
References samchon::IndexPair< T >::get_index(), samchon::IndexPair< T >::getValue(), and samchon::WeakString::rfinds().
|
inlinestatic |
Generates a substring.
Extracts a string consisting of the character specified by startIndex and all characters up to endIndex - 1 If endIndex is not specified, string::size() will be used instead.
If endIndex is greater than startIndex, then those will be swapped
str | Target string to be applied substring |
startIndex | Index of the first character. If startIndex is greater than endIndex, those will be swapped |
endIndex | Index of the last character - 1. If not specified, then string::size() will be used instead |
Definition at line 495 of file StringUtil.hpp.
References samchon::WeakString::substring().
|
inlinestatic |
Generate a substring.
Extracts a substring consisting of the characters from specified start to end It's same with str.substring( ? = (str.find(start) + start.size()), str.find(end, ?) )
ex) between("ABCD[EFGH]IJK", "[", "]") => "EFGH"
str | Target string to be applied between |
start | A string for separating substring at the front |
end | A string for separating substring at the end |
Definition at line 520 of file StringUtil.hpp.
References samchon::WeakString::between().
|
inlinestatic |
Adds tab() character to first position of each line.
str | Target str to add tabs |
n | The size of tab to be added for each line |
Definition at line 534 of file StringUtil.hpp.
References split().
|
inlinestatic |
Generates substrings.
Splits a string into an array of substrings by dividing the specified delimiter
str | Target string to split |
delim | The pattern that specifies where to split this string |
Definition at line 563 of file StringUtil.hpp.
References betweens(), and samchon::WeakString::split().
Referenced by addTab().
|
inlinestatic |
Generates substrings.
Splits a string into an array of substrings dividing by specified delimeters of start and end. It's the array of substrings adjusted the between.
str | Target string to split by 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 593 of file StringUtil.hpp.
References samchon::WeakString::betweens().
Referenced by split(), and substituteSQL().
|
inlinestatic |
Returns a string that all uppercase characters are converted to lowercase.
str | Target string to convert uppercase to lowercase |
Definition at line 617 of file StringUtil.hpp.
References samchon::WeakString::toLowerCase().
|
inlinestatic |
Returns a string all lowercase characters are converted to uppercase
str | Target string to convert lowercase to uppercase |
Definition at line 628 of file StringUtil.hpp.
References replaceAll(), and samchon::WeakString::yoUpperCase().
|
inlinestatic |
Returns a string specified word is replaced.
str | Target string to replace |
before | Specific word you want to be replaced |
after | Specific word you want to replace |
Definition at line 642 of file StringUtil.hpp.
References samchon::WeakString::replaceAll().
Referenced by removeHTMLSpaces(), substituteSQL(), toNumber(), and yoUpperCase().
|
inlinestatic |
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 657 of file StringUtil.hpp.
References samchon::WeakString::replaceAll().
|
inlinestatic |
Replace all HTML spaces to a literal space.
str | Target string to replace. |
Definition at line 668 of file StringUtil.hpp.
References replaceAll().