[llvm] [FileCheck] Add split view diff option for FileCheck (PR #189269)
Henrik G. Olsson via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 18 10:06:31 PDT 2026
================
@@ -2762,11 +2762,45 @@ static DiffContext getDiffContext(SourceMgr &SM, unsigned LineNo,
getLineText(LineNo + 1)};
}
+// Extracts a fixed-width "window" from string S, centered around DiffPos.
+static std::string getCenteredView(StringRef S, size_t DiffPos, size_t Width) {
+ if (S.size() <= Width)
+ return S.str() + std::string(Width - S.size(), ' ');
+
+ size_t HalfWidth = Width / 2;
+ size_t Start = (DiffPos > HalfWidth) ? DiffPos - HalfWidth : 0;
+
+ if (Start + Width > S.size())
+ Start = (S.size() > Width) ? S.size() - Width : 0;
+
+ std::string View = S.substr(Start, Width).str();
+
+ if (Start > 0 && Width > 3)
+ View.replace(0, 3, "...");
----------------
hnrklssn wrote:
I think this could technically still overlap with `DiffPos` if e.g. `Width` is 4.
https://github.com/llvm/llvm-project/pull/189269
More information about the llvm-commits
mailing list