summaryrefslogtreecommitdiff
path: root/llama.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llama.cpp')
-rw-r--r--llama.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/llama.cpp b/llama.cpp
index 0d12d9cc..0bb8fcd6 100644
--- a/llama.cpp
+++ b/llama.cpp
@@ -114,12 +114,17 @@ static size_t utf8_len(char src) {
}
void replace_all(std::string & s, const std::string & search, const std::string & replace) {
- for (size_t pos = 0; ; pos += replace.length()) {
- pos = s.find(search, pos);
- if (pos == std::string::npos) break;
- s.erase(pos, search.length());
- s.insert(pos, replace);
+ std::string result;
+ for (size_t pos = 0; ; pos += search.length()) {
+ auto new_pos = s.find(search, pos);
+ if (new_pos == std::string::npos) {
+ result += s.substr(pos, s.size() - pos);
+ break;
+ }
+ result += s.substr(pos, new_pos - pos) + replace;
+ pos = new_pos;
}
+ s = std::move(result);
}
static void zeros(std::ofstream & file, size_t n) {