result.append(csi_seq.data(), csi_seq.length());
line = line.substr(csi_seq.length());
}
- size_t path_end = line.find(':');
- if (path_end == std::string_view::npos) {
+ size_t path_end = get_diagnostics_path_length(line);
+ if (path_end == 0) {
result.append(line.data(), line.length());
} else {
fs::path path(line.substr(0, path_end));
std::filesystem::path make_relative_path(const Context& ctx,
const std::filesystem::path& path);
-// Rewrite path to absolute path in `text` in the following two cases, where X
+// Rewrite path to absolute path in `text` in the following cases, where X
// may be optional ANSI CSI sequences:
//
// X<path>[:1:2]X: ...
// In file included from X<path>[:1:2]X:
+// X<path>(line[,column])[ ]: ...
+//
+// See get_diagnostics_path_length().
std::string rewrite_stderr_to_absolute_paths(std::string_view text);
// Send `text` to file descriptor `fd` (typically stdout or stderr, which
std::string input =
"a:1:2\n"
+ "a(3):\n"
+ "a(3) :\n"
+ "a(3,4):\n"
+ "a(3,4) :\n"
+ "existing\n"
"existing:3:4\n"
+ "existing(3):\n"
+ "existing(3) :\n"
+ "existing(3,4):\n"
+ "existing(3,4) :\n"
"c:5:6\n"
"\x1b[01m\x1b[Kexisting:\x1b[m\x1b[K: foo\n"
"\x1b[01m\x1b[Kexisting:47:11:\x1b[m\x1b[K: foo\n"
"In file included from \x1b[01m\x1b[Kexisting:47:11:\x1b[m\x1b[K: foo\n";
std::string expected = FMT(
"a:1:2\n"
+ "a(3):\n"
+ "a(3) :\n"
+ "a(3,4):\n"
+ "a(3,4) :\n"
+ "existing\n"
"{0}:3:4\n"
+ "{0}(3):\n"
+ "{0}(3) :\n"
+ "{0}(3,4):\n"
+ "{0}(3,4) :\n"
"c:5:6\n"
"\x1b[01m\x1b[K{0}:\x1b[m\x1b[K: foo\n"
"\x1b[01m\x1b[K{0}:47:11:\x1b[m\x1b[K: foo\n"