mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-17 11:28:25 +00:00
Add string util search_deliminated_string (#1260)
This function takes a string of deliminated an see if another string is one of those This function also verifies it's not finding a substring
This commit is contained in:
committed by
GitHub
parent
1cfdd7e4a2
commit
74ce20b256
@@ -125,6 +125,19 @@ std::vector<std::string> SplitString(const std::string &str, char delim) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string::size_type search_deliminated_string(const std::string &haystack, const std::string &needle, const char deliminator)
|
||||
{
|
||||
// this shouldn't go out of bounds, even without obvious bounds checks
|
||||
auto pos = haystack.find(needle);
|
||||
while (pos != std::string::npos) {
|
||||
auto c = haystack[pos + needle.length()];
|
||||
if ((c == '\0' || c == deliminator) && (pos == 0 || haystack[pos - 1] == deliminator))
|
||||
return pos;
|
||||
pos = haystack.find(needle, pos + needle.length());
|
||||
}
|
||||
return std::string::npos;
|
||||
}
|
||||
|
||||
std::string implode(std::string glue, std::vector<std::string> src)
|
||||
{
|
||||
if (src.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user