MatchEvaluator

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there ANY way to cause a MatchEvaluator delegate to just *stop matching*
i.e. DON'T call this function any more, for the current Replace() call

Similar to the way in which you would return false from an EnumWindowsProc, to not process any more windows for the current call of EnumWindows

Thanks!
 
Beeeeeeeves,
Only way I can think of is to have a class level variable to indicate to
stop, (a state pattern comes to mind) when this variable is set, you simply
return the input, effectively stopping the replacement...

Hope this helps
Jay

Beeeeeeeves said:
Is there ANY way to cause a MatchEvaluator delegate to just *stop matching*?
i.e. DON'T call this function any more, for the current Replace() call?

Similar to the way in which you would return false from an
EnumWindowsProc, to not process any more windows for the current call of
EnumWindows.
 
I tried this by profiling it, and although it works fine, I instead tried a
method which calls Regex.Match, and then m = m.NextMatch in a
while(m.Success) loop, and although it is a slight bit more 'hacky' because
I have to increment a variable when I replace to keep track of the string's
current length, on profiling this method takes 0.17 seconds to operate on a
few 100 KB of text, compared to the matchevaluator returning m.Value which
takes 3.8 seconds... no surprise which method I'm going for considering this
is a time critical bit.
The reason being that the match evaluator has to get called every time,
which puts the time the algorithm (or a part of it) takes to operate in
direct proportion to L, the length of the text, which is something I wanted
to avoid (as opposed to being proportional to the dL/dt, the amount of text
that's changed.)
 
Back
Top