feat add StartsWith,EndsWith
This commit is contained in:
parent
333281ec06
commit
d048a2676c
@ -20,6 +20,8 @@ std::string TrimLeft(const std::string &str,
|
|||||||
const std::string &chars = " \t\n\r");
|
const std::string &chars = " \t\n\r");
|
||||||
std::string TrimRight(const std::string &str,
|
std::string TrimRight(const std::string &str,
|
||||||
const std::string &chars = " \t\n\r");
|
const std::string &chars = " \t\n\r");
|
||||||
|
bool EndsWith(const std::string &str, const std::string &suffix);
|
||||||
|
bool StartsWith(const std::string &str, const std::string &prefix);
|
||||||
|
|
||||||
}// namespace sled
|
}// namespace sled
|
||||||
#endif// SLED_STRINGS_UTILS_H
|
#endif// SLED_STRINGS_UTILS_H
|
||||||
|
@ -65,4 +65,18 @@ TrimRight(const std::string &str, const std::string &chars)
|
|||||||
return str.substr(0, end);
|
return str.substr(0, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
EndsWith(const std::string &str, const std::string &suffix)
|
||||||
|
{
|
||||||
|
return str.size() >= suffix.size()
|
||||||
|
&& str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
StartsWith(const std::string &str, const std::string &prefix)
|
||||||
|
{
|
||||||
|
return str.size() >= prefix.size()
|
||||||
|
&& str.compare(0, prefix.size(), prefix) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
}// namespace sled
|
}// namespace sled
|
||||||
|
Loading…
Reference in New Issue
Block a user