public static string Replace(Regex pattern, string text, MatchEvaluator evaluator, PreprocessedTextLocationMap locationMap, List <PreprocessingTextChange> changesDone = null) { if (locationMap == null && changesDone == null) { return(pattern.Replace(text, evaluator)); } var changes = changesDone ?? new List <PreprocessingTextChange>(); var output = pattern.Replace(text, m => PreprocessingTextChange.MatchEvaluatorWithTextChangeEmitWrapper(m, evaluator, changes)); if (locationMap != null) { locationMap.ApplyChanges(changes); } return(output); }