@@ -54,6 +54,8 @@ bool NotFound (CFindInfo & FindInfo)
54
54
FindInfo.m_bAgain ? " again." : " ." );
55
55
::UMessageBox (strMsg, MB_ICONINFORMATION);
56
56
FindInfo.m_iStartColumn = -1 ;
57
+ FindInfo.m_iLastLineSearched = -1 ;
58
+ FindInfo.m_MatchesOnLine .clear ();
57
59
return false ;
58
60
} // end of NotFound
59
61
@@ -72,6 +74,8 @@ CFindDlg dlg (FindInfo.m_strFindStringList);
72
74
if (!FindInfo.m_bAgain || FindInfo.m_strFindStringList .IsEmpty ())
73
75
{
74
76
FindInfo.m_iStartColumn = -1 ; // return consistent column number
77
+ FindInfo.m_iLastLineSearched = -1 ;
78
+ FindInfo.m_MatchesOnLine .clear ();
75
79
76
80
if (!FindInfo.m_strFindStringList .IsEmpty ())
77
81
dlg.m_strFindText = FindInfo.m_strFindStringList .GetHead ();
@@ -118,7 +122,7 @@ CFindDlg dlg (FindInfo.m_strFindStringList);
118
122
else
119
123
{
120
124
if (FindInfo.m_bRepeatOnSameLine )
121
- FindInfo.m_iStartColumn ++ ; // skip previous match
125
+ FindInfo.m_iStartColumn = FindInfo. m_iEndColumn ; // skip previous match
122
126
else
123
127
FindInfo.m_iStartColumn = -1 ; // return consistent column number
124
128
@@ -150,10 +154,6 @@ CFindDlg dlg (FindInfo.m_strFindStringList);
150
154
return NotFound (FindInfo);
151
155
}
152
156
153
- // re-initiate the search - this will set up the POSITION parameter, if it wants to
154
-
155
- // (*pInitiateSearch) (pObject, FindInfo);
156
-
157
157
// loop until end of text, or text found
158
158
159
159
CString strLine;
@@ -217,6 +217,87 @@ CString strStatus = TFormat ("Finding: %s", (LPCTSTR) FindInfo.m_strFindStringLi
217
217
}
218
218
} // end of having a progress control
219
219
220
+ // if searching backwards, and doing more than one, find all matches on this line
221
+
222
+ if (!FindInfo.m_bForwards && FindInfo.m_bRepeatOnSameLine )
223
+ {
224
+
225
+ if (FindInfo.m_nCurrentLine != FindInfo.m_iLastLineSearched )
226
+ {
227
+ FindInfo.m_iLastLineSearched = FindInfo.m_nCurrentLine ;
228
+ FindInfo.m_MatchesOnLine .clear (); // no matches yet
229
+ int iStartCol = 0 ; // start at start of line
230
+
231
+ // if case-insensitive search wanted, force this line to lower case
232
+ if (!FindInfo.m_bMatchCase && !FindInfo.m_bRegexp )
233
+ strLine.MakeLower ();
234
+
235
+ // loop until we run out of matches
236
+ while (true )
237
+ {
238
+
239
+ if (FindInfo.m_bRegexp )
240
+ {
241
+ if (regexec (FindInfo.m_regexp , strLine, iStartCol))
242
+ {
243
+ FindInfo.m_MatchesOnLine .push_back (
244
+ pair <int , int > (FindInfo.m_regexp ->m_vOffsets [0 ],
245
+ FindInfo.m_regexp ->m_vOffsets [1 ]));
246
+ iStartCol = FindInfo.m_regexp ->m_vOffsets [1 ];
247
+ if (iStartCol >= strLine.GetLength ())
248
+ break ;
249
+ } // end of regexp matched
250
+ else
251
+ break ; // no match, done searching
252
+
253
+ } // end regexp
254
+ else
255
+ {
256
+ if ((iStartCol = strLine.Find (strFindString, iStartCol)) != -1 )
257
+ {
258
+ // work out ending column
259
+ int iEndCol = iStartCol + strFindString.GetLength ();
260
+ FindInfo.m_MatchesOnLine .push_back (pair <int , int > (iStartCol, iEndCol));
261
+ iStartCol = iEndCol;
262
+ if (iStartCol >= strLine.GetLength ())
263
+ break ;
264
+ } // end of found
265
+ else
266
+ break ; // no match, done searching
267
+
268
+ } // end not regexp
269
+
270
+
271
+ } // end of while we found something
272
+
273
+
274
+ } // end of different line to last time
275
+
276
+
277
+ // if m_MatchesOnLine is not empty we had a match (either this time or last time)
278
+
279
+ if (!FindInfo.m_MatchesOnLine .empty ())
280
+ {
281
+ // get last match
282
+ pair<int , int > result = FindInfo.m_MatchesOnLine .back ();
283
+ // don't want it any more
284
+ FindInfo.m_MatchesOnLine .pop_back ();
285
+ // copy first and last column
286
+ FindInfo.m_iStartColumn = result.first ;
287
+ FindInfo.m_iEndColumn = result.second ;
288
+ // all done!
289
+ WrapUpFind (FindInfo);
290
+ return true ; // found it!
291
+ } // end if found
292
+ else
293
+ {
294
+ // nothing found, try previous line
295
+ FindInfo.m_nCurrentLine --;
296
+ continue ; // skip other testing
297
+ } // end if not found
298
+
299
+ } // end of searching backwards with repeat on same line
300
+
220
301
// if text found on this line, then we have done it!
221
302
222
303
if (FindInfo.m_bRegexp )
@@ -233,14 +314,14 @@ CString strStatus = TFormat ("Finding: %s", (LPCTSTR) FindInfo.m_strFindStringLi
233
314
} // end of regular expression
234
315
else
235
316
{ // not regular expression
317
+
236
318
// if case-insensitive search wanted, force this line to lower case
237
319
if (!FindInfo.m_bMatchCase )
238
320
strLine.MakeLower ();
239
321
if ((FindInfo.m_iStartColumn = strLine.Find (strFindString, maximum (FindInfo.m_iStartColumn , 0 ))) != -1 )
240
322
{
241
323
// work out ending column
242
- FindInfo.m_iEndColumn = FindInfo.m_iStartColumn +
243
- FindInfo.m_strFindStringList .GetHead ().GetLength ();
324
+ FindInfo.m_iEndColumn = FindInfo.m_iStartColumn + strFindString.GetLength ();
244
325
WrapUpFind (FindInfo);
245
326
return true ; // found it!
246
327
} // end of found
0 commit comments