diff --git a/str_util.cpp b/str_util.cpp index dc10528..f3f5dc5 100644 --- a/str_util.cpp +++ b/str_util.cpp @@ -101,6 +101,14 @@ bool str_util::str_endswith(std::string input, std::string pattern) { return i == ilen - plen; } +bool str_util::str_startswith(std::string input, std::string pattern) { + auto ilen = input.length(); + auto plen = pattern.length(); + if (ilen < plen) return false; + auto i = input.find(pattern); + return i == 0; +} + std::string str_util::remove_quote(std::string input) { if (input.length() < 2) return input; if (input[0] == '"' && input[input.length() - 1] == '"') { diff --git a/str_util.h b/str_util.h index ba67887..89e2bb5 100644 --- a/str_util.h +++ b/str_util.h @@ -60,6 +60,13 @@ namespace str_util { * @return true if input ends with pattern */ bool str_endswith(std::string input, std::string pattern); + /** + * @brief Check if a string starts with a pattern + * @param input Input data + * @param pattern Pattern + * @return true if input starts with pattern + */ + bool str_startswith(std::string input, std::string pattern); /** * @brief Trim a string * @param input Input string