mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-07-08 01:30:39 +08:00
Add new function
This commit is contained in:
@@ -57,3 +57,11 @@ std::string str_util::str_hex(std::string input) {
|
|||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool str_util::str_endswith(std::string input, std::string pattern) {
|
||||||
|
auto ilen = input.length();
|
||||||
|
auto plen = pattern.length();
|
||||||
|
if (ilen < plen) return false;
|
||||||
|
auto i = input.rfind(pattern);
|
||||||
|
return i == ilen - plen;
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,5 +33,12 @@ namespace str_util {
|
|||||||
* @return Output
|
* @return Output
|
||||||
*/
|
*/
|
||||||
std::string str_hex(std::string input);
|
std::string str_hex(std::string input);
|
||||||
|
/**
|
||||||
|
* @brief Check if a string ends with a pattern
|
||||||
|
* @param input Input data
|
||||||
|
* @param pattern Pattern
|
||||||
|
* @return true if input ends with pattern
|
||||||
|
*/
|
||||||
|
bool str_endswith(std::string input, std::string pattern);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user