1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Text.RegularExpressions;
6
using ICSharpCode.SharpDevelop.Editor;
8
namespace ICSharpCode.VBNetBinding
10
public static class LanguageUtils
12
public static string TrimComments(this string line)
14
if (string.IsNullOrEmpty(line))
19
for (int i = 0; i < line.Length; i++) {
22
if (line[i] == '\'' && !inStr)
23
return line.Substring(0, i);
29
public static string TrimPreprocessorDirectives(this string line)
31
if (string.IsNullOrEmpty(line))
36
for (int i = 0; i < line.Length; i++) {
37
if (line[i] == '#' && wsOnly) {
38
if (i < line.Length - 1) {
39
if (char.IsLetter(line[i + 1]))
40
return line.Substring(0, i);
42
return line.Substring(0, i);
44
if (!char.IsWhiteSpace(line[i]))
51
public static string TrimLine(this string line)
53
if (string.IsNullOrEmpty(line))
55
// remove string content
56
MatchCollection matches = Regex.Matches(line, "\"[^\"]*?\"", RegexOptions.Singleline);
57
foreach (Match match in matches) {
58
line = line.Remove(match.Index, match.Length).Insert(match.Index, new string('-', match.Length));
61
return TrimComments(line);
64
public static bool IsInsideDocumentationComment(ITextEditor editor)
66
return IsInsideDocumentationComment(editor, editor.Document.GetLineForOffset(editor.Caret.Offset), editor.Caret.Offset);
69
public static bool IsInsideDocumentationComment(ITextEditor editor, IDocumentLine curLine, int cursorOffset)
71
for (int i = curLine.Offset; i < cursorOffset; ++i) {
72
char ch = editor.Document.GetCharAt(i);
75
if (ch == '\'' && i + 2 < cursorOffset && editor.Document.GetCharAt(i + 1) == '\'' &&
76
editor.Document.GetCharAt(i + 2) == '\'')