Skip to content

Commit eecd0fc

Browse files
committed
made stripHitPrefix more robust
1 parent 9c34ee3 commit eecd0fc

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

src/ResultDock.cpp

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,14 +1229,40 @@ namespace {
12291229
// --------------------------------------------------------------------------
12301230
// Remove "Line 123: " prefix from hit line (UTF‑16)
12311231
// --------------------------------------------------------------------------
1232-
std::wstring stripHitPrefix(const std::wstring& w) {
1233-
size_t pos = w.find(L"Line ");
1234-
if (pos == std::wstring::npos) return w;
1235-
pos += 5; // skip "Line "
1236-
while (pos < w.size() && iswdigit(w[pos])) ++pos;
1237-
if (pos < w.size() && w[pos] == L':') ++pos;
1238-
while (pos < w.size() && iswspace(w[pos])) ++pos;
1239-
return w.substr(pos);
1232+
std::wstring stripHitPrefix(const std::wstring& w)
1233+
{
1234+
size_t i = 0;
1235+
1236+
// 1. Skip leading whitespace (indentation).
1237+
while (i < w.size() && iswspace(w[i]))
1238+
++i;
1239+
1240+
// 2. Skip an optional alphabetic word such as "Line", "Zeile", etc.
1241+
while (i < w.size() && iswalpha(w[i]))
1242+
++i;
1243+
1244+
// 3. Skip one single space after that word, if present.
1245+
if (i < w.size() && w[i] == L' ')
1246+
++i;
1247+
1248+
// 4. Consume at least one digit (line number).
1249+
size_t digitStart = i;
1250+
while (i < w.size() && iswdigit(w[i]))
1251+
++i;
1252+
if (i == digitStart || i >= w.size())
1253+
return w; // Not our format – return unchanged.
1254+
1255+
// 5. Expect exactly one colon.
1256+
if (w[i] != L':')
1257+
return w; // Not our format – return unchanged.
1258+
++i;
1259+
1260+
// 6. Skip whitespace after the colon.
1261+
while (i < w.size() && iswspace(w[i]))
1262+
++i;
1263+
1264+
// 7. Return the remainder: the actual hit text.
1265+
return w.substr(i);
12401266
}
12411267

12421268
// --------------------------------------------------------------------------

0 commit comments

Comments
 (0)