mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2024-12-27 06:39:25 +01:00
llama : better replace_all (#8852)
This commit is contained in:
parent
064cdc265f
commit
f1ea5146d7
@ -122,17 +122,14 @@ static std::string trim(const std::string & str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void replace_all(std::string & s, const std::string & search, const std::string & replace) {
|
static void replace_all(std::string & s, const std::string & search, const std::string & replace) {
|
||||||
std::string result;
|
if (search.empty()) {
|
||||||
for (size_t pos = 0; ; pos += search.length()) {
|
return; // Avoid infinite loop if 'search' is an empty string
|
||||||
auto new_pos = s.find(search, pos);
|
}
|
||||||
if (new_pos == std::string::npos) {
|
size_t pos = 0;
|
||||||
result += s.substr(pos, s.size() - pos);
|
while ((pos = s.find(search, pos)) != std::string::npos) {
|
||||||
break;
|
s.replace(pos, search.length(), replace);
|
||||||
}
|
pos += replace.length();
|
||||||
result += s.substr(pos, new_pos - pos) + replace;
|
|
||||||
pos = new_pos;
|
|
||||||
}
|
}
|
||||||
s = std::move(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_float_close(float a, float b, float abs_tol) {
|
static bool is_float_close(float a, float b, float abs_tol) {
|
||||||
|
Loading…
Reference in New Issue
Block a user