Skip to content

Commit 258ac87

Browse files
committed
more compact format for stripHitPrefix
1 parent eecd0fc commit 258ac87

File tree

2 files changed

+1508
-28
lines changed

2 files changed

+1508
-28
lines changed

src/ResultDock.cpp

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,40 +1229,22 @@ namespace {
12291229
// --------------------------------------------------------------------------
12301230
// Remove "Line 123: " prefix from hit line (UTF‑16)
12311231
// --------------------------------------------------------------------------
1232-
std::wstring stripHitPrefix(const std::wstring& w)
1233-
{
1232+
std::wstring stripHitPrefix(const std::wstring& w) {
12341233
size_t i = 0;
12351234

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;
1235+
while (i < w.size() && iswspace(w[i])) ++i; // leading WS
1236+
while (i < w.size() && iswalpha(w[i])) ++i; // "Line", "Zeile", …
1237+
if (i < w.size() && w[i] == L' ') ++i; // single space
12471238

1248-
// 4. Consume at least one digit (line number).
12491239
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;
1240+
while (i < w.size() && iswdigit(w[i])) ++i; // digits
1241+
if (i == digitStart || i >= w.size()) return w; // no digits → bail
12591242

1260-
// 6. Skip whitespace after the colon.
1261-
while (i < w.size() && iswspace(w[i]))
1262-
++i;
1243+
if (w[i] != L':') return w; // must be ':'
1244+
++i;
12631245

1264-
// 7. Return the remainder: the actual hit text.
1265-
return w.substr(i);
1246+
while (i < w.size() && iswspace(w[i])) ++i; // WS after ':'
1247+
return w.substr(i); // remainder = hit
12661248
}
12671249

12681250
// --------------------------------------------------------------------------

0 commit comments

Comments
 (0)