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

Function peak_source

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

for displaying source code around error position

Source from the content-addressed store, hash-verified

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) {
30 if (source.empty()) {
31 return "(no source available)";
32 }
33 std::string output;
34 size_t start = (pos >= max_peak_chars) ? (pos - max_peak_chars) : 0;
35 size_t end = std::min(pos + max_peak_chars, source.length());
36 std::string substr = source.substr(start, end - start);
37 string_replace_all(substr, "\n", "↵");
38 output += "..." + substr + "...\n";
39 std::string spaces(pos - start + 3, ' ');
40 output += spaces + "^";
41 return output;
42}
43
44static std::string fmt_error_with_source(const std::string & tag, const std::string & msg, const std::string & source, size_t pos) {
45 std::ostringstream oss;

Callers 2

executeMethod · 0.85
fmt_error_with_sourceFunction · 0.85

Calls 4

minFunction · 0.85
string_replace_allFunction · 0.70
emptyMethod · 0.65
lengthMethod · 0.65

Tested by

no test coverage detected