Browse Source

moved TrimLine code to LanguageUtils and removed invalid handling of comments

pull/14/head
Siegfried Pammer 15 years ago
parent
commit
5e68dff78b
  1. 14
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs
  2. 27
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/LanguageUtils.cs
  3. 2
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetBracketSearcher.cs

14
src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs

@ -143,7 +143,7 @@ namespace ICSharpCode.VBNetBinding @@ -143,7 +143,7 @@ namespace ICSharpCode.VBNetBinding
if (ch == '\n' && lineAboveText != null)
{
string textToReplace = TrimLine(lineAboveText);
string textToReplace = lineAboveText.TrimLine();
if (doCasing)
DoCasingOnLine(lineAbove, textToReplace, editor);
@ -201,18 +201,6 @@ namespace ICSharpCode.VBNetBinding @@ -201,18 +201,6 @@ namespace ICSharpCode.VBNetBinding
}
}
internal static string TrimLine(string lineText)
{
string textToReplace = lineText;
// remove string content
MatchCollection strmatches = Regex.Matches(lineText, "\"[^\"]*?\"", RegexOptions.Singleline);
foreach (Match match in strmatches) {
textToReplace = textToReplace.Remove(match.Index, match.Length).Insert(match.Index, new String('-', match.Length));
}
// remove comments
return Regex.Replace(textToReplace, "'.*$", "", RegexOptions.Singleline);
}
void DoInsertionOnLine(string terminator, IDocumentLine currentLine, IDocumentLine lineAbove, string textToReplace, ITextEditor editor, int lineNr)
{
string curLineText = currentLine.Text;

27
src/AddIns/BackendBindings/VBNetBinding/Project/Src/LanguageUtils.cs

@ -7,21 +7,34 @@ namespace ICSharpCode.VBNetBinding @@ -7,21 +7,34 @@ namespace ICSharpCode.VBNetBinding
{
public static class LanguageUtils
{
public static string TrimComments(this string argument)
public static string TrimComments(this string line)
{
if (string.IsNullOrEmpty(argument))
if (string.IsNullOrEmpty(line))
return string.Empty;
bool inStr = false;
for (int i = 0; i < argument.Length; i++) {
if (argument[i] == '"')
for (int i = 0; i < line.Length; i++) {
if (line[i] == '"')
inStr = !inStr;
if (argument[i] == '\'' && !inStr)
return argument.Substring(0, i).Trim();
if (line[i] == '\'' && !inStr)
return line.Substring(0, i).Trim();
}
return argument;
return line;
}
public static string TrimLine(this string line)
{
if (string.IsNullOrEmpty(line))
return string.Empty;
// remove string content
MatchCollection matches = Regex.Matches(line, "\"[^\"]*?\"", RegexOptions.Singleline);
foreach (Match match in matches) {
line = line.Remove(match.Index, match.Length).Insert(match.Index, new string('-', match.Length));
}
// remove comments
return TrimComments(line);
}
}
}

2
src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetBracketSearcher.cs

@ -145,7 +145,7 @@ namespace ICSharpCode.VBNetBinding @@ -145,7 +145,7 @@ namespace ICSharpCode.VBNetBinding
{
IDocumentLine line = document.GetLineForOffset(offset);
string interestingText = VBNetFormattingStrategy.TrimLine(line.Text).Trim(' ', '\t');
string interestingText = line.Text.TrimLine().Trim(' ', '\t');
//LoggingService.Debug("text: '" + interestingText + "'");

Loading…
Cancel
Save