MCPcopy Create free account
hub / github.com/Cantera/cantera / formatInputFile

Function formatInputFile

src/base/AnyMap.cpp:1918–1952  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1916
1917namespace {
1918void formatInputFile(fmt::memory_buffer& b, const shared_ptr<AnyMap>& metadata,
1919 const string& filename, int lineno, int column, int lineno2=-1, int column2=-1)
1920{
1921 if (lineno2 == -1) {
1922 lineno2 = lineno;
1923 column2 = column;
1924 }
1925
1926 fmt_append(b, "| Line |\n");
1927 if (!metadata->hasKey("file-contents")) {
1928 std::ifstream infile(findInputFile(filename));
1929 std::stringstream buffer;
1930 buffer << infile.rdbuf();
1931 (*metadata)["file-contents"] = buffer.str();
1932 }
1933 string line;
1934 int i = 0;
1935 int lastShown = -1;
1936 std::stringstream contents((*metadata)["file-contents"].asString());
1937 while (std::getline(contents, line)) {
1938 if (i == lineno || i == lineno2) {
1939 fmt_append(b, "> {: 5d} > {}\n", i+1, line);
1940 fmt_append(b, "{:>{}}\n", "^", column + 11);
1941 lastShown = i;
1942 } else if ((lineno + 4 > i && lineno < i + 6) ||
1943 (lineno2 + 4 > i && lineno2 < i + 6)) {
1944 if (lastShown >= 0 && i - lastShown > 1) {
1945 fmt_append(b, "...\n");
1946 }
1947 fmt_append(b, "| {: 5d} | {}\n", i+1, line);
1948 lastShown = i;
1949 }
1950 i++;
1951 }
1952}
1953}
1954
1955string InputFileError::formatError(const string& message, int lineno, int column,

Callers 3

formatErrorMethod · 0.85
formatError2Method · 0.85
warn_deprecatedFunction · 0.85

Calls 4

fmt_appendFunction · 0.85
findInputFileFunction · 0.85
hasKeyMethod · 0.80
strMethod · 0.80

Tested by

no test coverage detected