MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / string_replace_all

Function string_replace_all

smallthinker/common/common.cpp:431–446  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429}
430
431void string_replace_all(std::string & s, const std::string & search, const std::string & replace) {
432 if (search.empty()) {
433 return;
434 }
435 std::string builder;
436 builder.reserve(s.length());
437 size_t pos = 0;
438 size_t last_pos = 0;
439 while ((pos = s.find(search, last_pos)) != std::string::npos) {
440 builder.append(s, last_pos, pos - last_pos);
441 builder.append(replace);
442 last_pos = pos + search.length();
443 }
444 builder.append(s, last_pos, std::string::npos);
445 s = std::move(builder);
446}
447
448bool string_ends_with(const std::string_view & str, const std::string_view & suffix) {
449 return str.size() >= suffix.size() && str.compare(str.size()-suffix.size(), suffix.size(), suffix) == 0;

Callers 3

common_get_hf_fileFunction · 0.70
write_table_entryFunction · 0.50

Calls 5

reserveMethod · 0.80
lengthMethod · 0.80
findMethod · 0.80
emptyMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected