[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:01:38 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();
----------------
hnrklssn wrote:
nit: might be a bit confusing that `View` is not a `string_view` or `StringRef`. Maybe rename it to "VisibleText" or "Display" or "Line" or something?
https://github.com/llvm/llvm-project/pull/189269
More information about the llvm-commits
mailing list