public static string ConvertCode(string inAsp, bool forceTabs) { var outputStrings = new List <AspStringBlock>(); var codeSegmentRegex = new Regex(@"<%([^=][\s\S]*?[^\\]|[^=])%>"); var codeSegments = codeSegmentRegex.Matches(inAsp); var currentPosition = 0; foreach (Match codeSegment in codeSegments) { var stringBlock = new AspStringBlock(inAsp.Substring(currentPosition, codeSegment.Index - currentPosition), false); var codeBlock = new AspStringBlock(codeSegment.Groups[1].Value, true); outputStrings.Add(stringBlock); outputStrings.Add(codeBlock); currentPosition = codeSegment.Index + codeSegment.Length; } AspStringBlock lastBlock = new AspStringBlock(inAsp.Substring(currentPosition, inAsp.Length - currentPosition), false); outputStrings.Add(lastBlock); if (forceTabs) { outputStrings.ForEach(x => x.ForceTabs()); } var output = new StringBuilder(); foreach (var outputStringBlock in outputStrings) { output.Append(outputStringBlock.GetOutput()); } return(output.ToString()); }
public static string ConvertCode(string inAsp) { ArrayList outputStrings = new ArrayList(); Regex codeSegmentRegex = new Regex(@"<%([^=][\s\S]*?[^\\]|[^=])%>"); MatchCollection codeSegments = codeSegmentRegex.Matches(inAsp); int currentPosition = 0; foreach (Match codeSegment in codeSegments) { AspStringBlock stringBlock = new AspStringBlock(inAsp.Substring(currentPosition, codeSegment.Index - currentPosition), false); AspStringBlock codeBlock = new AspStringBlock(codeSegment.Groups[1].Value, true); outputStrings.Add(stringBlock); outputStrings.Add(codeBlock); currentPosition = codeSegment.Index + codeSegment.Length; } AspStringBlock lastBlock = new AspStringBlock(inAsp.Substring(currentPosition, inAsp.Length - currentPosition), false); outputStrings.Add(lastBlock); StringBuilder output = new StringBuilder(); foreach (AspStringBlock outputStringBlock in outputStrings) { output.Append(outputStringBlock.GetOutput()); } return(output.ToString()); }
private void cmdParse_Click(object sender, EventArgs e) { var text = txtInput.Text; text = text.Replace("\r\n", "\n"); text = text.Replace("\n", "\r\n"); txtOutput.Text = AspStringBlock.ConvertCode(text, chkTabs.Checked); }
public static string ConvertCode(string inAsp, bool forceTabs) { var outputStrings = new List<AspStringBlock>(); var codeSegmentRegex = new Regex(@"<%([^=][\s\S]*?[^\\]|[^=])%>"); var codeSegments = codeSegmentRegex.Matches(inAsp); var currentPosition = 0; foreach (Match codeSegment in codeSegments) { var stringBlock = new AspStringBlock(inAsp.Substring(currentPosition, codeSegment.Index - currentPosition), false); var codeBlock = new AspStringBlock(codeSegment.Groups[1].Value, true); outputStrings.Add(stringBlock); outputStrings.Add(codeBlock); currentPosition = codeSegment.Index + codeSegment.Length; } AspStringBlock lastBlock = new AspStringBlock(inAsp.Substring(currentPosition, inAsp.Length - currentPosition), false); outputStrings.Add(lastBlock); if (forceTabs) outputStrings.ForEach(x => x.ForceTabs()); var output = new StringBuilder(); foreach (var outputStringBlock in outputStrings) { output.Append(outputStringBlock.GetOutput()); } return output.ToString(); }