public string ApplyConversionRule(string sourceCode, ConversionParameters conversionParameters) { Logger.AddLog(String.Format("ApplyingRule Name:{0}-Type:{1}-Priority:{2}", RuleName, RuleType, RuleTypePriority)); var match = Regex.Match(sourceCode, RuleApplicablePattern); if (match.Success) { Logger.AddLog("SourceCode:" + match.Value); string comment = match.Groups["comment"].ToString(); var convertedCode = @"\\ " + comment.Trim(); if (conversionParameters.CopyComments == false) { conversionParameters.AddConvertedCode(convertedCode); } Logger.AddLog("ConvertedCode:" + convertedCode); return(sourceCode.Remove(match.Index, match.Length)); } Logger.AddLog("MatchFailed"); return(sourceCode); }
public string ApplyConversionRule(string sourceCode, ConversionParameters conversionParameters) { Logger.AddApplyConversionRuleEntryLog(RuleName, RuleType, RuleTypePriority); var match = Regex.Match(sourceCode, RuleApplicablePattern); if (match.Success) { Logger.AddSourceCode(match.Value); string leadingSpace = match.Groups["leadingSpace"].ToString(); //string variableName = StringBuilder convertedCodeBuilder = new StringBuilder(); Dictionary <string, string> groupBuilder = new Dictionary <string, string>(); foreach (Match subMatch in Regex.Matches(match.Value, SubPattern)) { string variableName = subMatch.Groups["variableName"].Value; Utility.ConvertVariables(conversionParameters, groupBuilder, convertedCodeBuilder, variableName, leadingSpace, true); } if (conversionParameters.IsLocalVariableGroupingRequired) { foreach (KeyValuePair <string, string> keyValuePair in groupBuilder) { convertedCodeBuilder.AppendLine(leadingSpace + keyValuePair.Key + " " + keyValuePair.Value + ";"); } } string convertedCode = convertedCodeBuilder.ToString(); conversionParameters.AddConvertedCode(convertedCode); Logger.AddConvertedCode(convertedCode); sourceCode = sourceCode.Remove(match.Index, match.Length); if (sourceCode.Length > 0 && sourceCode.Substring(0, 1) == "\n") { sourceCode = sourceCode.Remove(0, 1); } return(sourceCode); } Logger.AddLog("MatchFailed"); return(sourceCode); }