mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-14 05:36:36 -05:00
Add return value to ReplaceAll()
Returns true of the string was modified and false otherwise
This commit is contained in:
parent
b803c0ad75
commit
cb58eb9f04
|
|
@ -21,17 +21,20 @@ bool DoubleEquals(double left, double right, double epsilon)
|
|||
return (fabs(left - right) < epsilon);
|
||||
}
|
||||
|
||||
void ReplaceAll(std::string &str, const std::string &from,
|
||||
bool ReplaceAll(std::string &str, const std::string &from,
|
||||
const std::string &to)
|
||||
{
|
||||
if (from.empty()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
bool somethingWasReplaced = false;
|
||||
size_t start_pos = 0;
|
||||
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length();
|
||||
somethingWasReplaced = true;
|
||||
}
|
||||
return somethingWasReplaced;
|
||||
}
|
||||
|
||||
std::optional<std::string> GetJsonField(const std::string &jsonStr,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ EXPORT std::pair<int, int> GetCursorPos();
|
|||
|
||||
EXPORT bool DoubleEquals(double left, double right, double epsilon);
|
||||
|
||||
void ReplaceAll(std::string &str, const std::string &from,
|
||||
bool ReplaceAll(std::string &str, const std::string &from,
|
||||
const std::string &to);
|
||||
EXPORT std::optional<std::string> GetJsonField(const std::string &json,
|
||||
const std::string &id);
|
||||
|
|
|
|||
|
|
@ -14,17 +14,20 @@ bool DoubleEquals(double left, double right, double epsilon)
|
|||
return (fabs(left - right) < epsilon);
|
||||
}
|
||||
|
||||
void ReplaceAll(std::string &str, const std::string &from,
|
||||
bool ReplaceAll(std::string &str, const std::string &from,
|
||||
const std::string &to)
|
||||
{
|
||||
if (from.empty()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
size_t start_pos = 0;
|
||||
bool somethingWasReplaced = false;
|
||||
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length();
|
||||
somethingWasReplaced = true;
|
||||
}
|
||||
return somethingWasReplaced;
|
||||
}
|
||||
|
||||
std::optional<std::string> GetJsonField(const std::string &jsonStr,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user