MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / string_replace_all

Function string_replace_all

subprojects/llama.cpp/common/jinja/utils.h:11–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9namespace jinja {
10
11static void string_replace_all(std::string & s, const std::string & search, const std::string & replace) {
12 if (search.empty()) {
13 return;
14 }
15 std::string builder;
16 builder.reserve(s.length());
17 size_t pos = 0;
18 size_t last_pos = 0;
19 while ((pos = s.find(search, last_pos)) != std::string::npos) {
20 builder.append(s, last_pos, pos - last_pos);
21 builder.append(replace);
22 last_pos = pos + search.length();
23 }
24 builder.append(s, last_pos, std::string::npos);
25 s = std::move(builder);
26}
27
28// for displaying source code around error position
29static std::string peak_source(const std::string & source, size_t pos, size_t max_peak_chars = 40) {

Callers 1

peak_sourceFunction · 0.70

Calls 4

emptyMethod · 0.65
lengthMethod · 0.65
findMethod · 0.65
appendMethod · 0.65

Tested by

no test coverage detected