added two string functions, doc updates
This commit is contained in:
@@ -77,3 +77,28 @@ std::string string_padd(const std::string &str, int pad_len, char fill_char, boo
|
||||
else
|
||||
return std::string(pad_len - str.size(), fill_char) + str;
|
||||
}
|
||||
|
||||
|
||||
std::string string_substring(const std::string & str, long pos, long count) {
|
||||
size_t start_pos = pos;
|
||||
|
||||
if (pos < 0) {
|
||||
start_pos = str.size() - abs(pos);
|
||||
}
|
||||
|
||||
if ( (start_pos >= str.size()) || (count < 1) || (start_pos < 0) ) {
|
||||
throw std::invalid_argument("Invalid parameter(s) for string-substr.");
|
||||
}
|
||||
|
||||
return str.substr(start_pos, count);
|
||||
}
|
||||
|
||||
size_t string_find_substr(const std::string & str, const std::string & pattern, long pos) {
|
||||
if (pos >= str.size()) {
|
||||
throw std::invalid_argument("Invalid parameter(s) for string-find.");
|
||||
}
|
||||
|
||||
size_t p = str.find(pattern, pos);
|
||||
|
||||
return p != str.npos ? p : -1;
|
||||
}
|
||||
Reference in New Issue
Block a user