public static bool IsEmptyLine(IDocument document, int lineNumber) { return(TextUtilities.IsEmptyLine(document, document.GetLineSegment(lineNumber))); }
public static string GetExpressionBeforeOffset(TextArea textArea, int initialOffset) { IDocument document = textArea.Document; int num = initialOffset; while (num - 1 > 0) { char charAt = document.GetCharAt(num - 1); if (charAt <= ')') { if (charAt > '\r') { if (charAt == '\"') { if (num < initialOffset - 1) { return(null); } return("\"\""); } switch (charAt) { case '\'': { if (num < initialOffset - 1) { return(null); } return("'a'"); } case ')': { num = TextUtilities.SearchBracketBackward(document, num - 2, '(', ')'); continue; } } } else if (charAt == '\n' || charAt == '\r') { break; } } else if (charAt <= '>') { if (charAt == '.') { num--; continue; } else if (charAt == '>') { if (document.GetCharAt(num - 2) != '-') { break; } num -= 2; continue; } } else if (charAt == ']') { num = TextUtilities.SearchBracketBackward(document, num - 2, '[', ']'); continue; } else if (charAt == '}') { break; } if (!char.IsWhiteSpace(document.GetCharAt(num - 1))) { int num1 = num - 1; if (TextUtilities.IsLetterDigitOrUnderscore(document.GetCharAt(num1))) { while (num1 > 0 && TextUtilities.IsLetterDigitOrUnderscore(document.GetCharAt(num1 - 1))) { num1--; } string str = document.GetText(num1, num - num1).Trim(); string str1 = str; string str2 = str1; if (str1 != null && (str2 == "ref" || str2 == "out" || str2 == "in" || str2 == "return" || str2 == "throw" || str2 == "case") || str.Length > 0 && !TextUtilities.IsLetterDigitOrUnderscore(str[0])) { break; } num = num1; } else { break; } } else { num--; } } if (num < 0) { return(string.Empty); } string str3 = document.GetText(num, textArea.Caret.Offset - num).Trim(); int num2 = str3.LastIndexOf('\n'); if (num2 >= 0) { num = num + num2 + 1; } string str4 = document.GetText(num, textArea.Caret.Offset - num).Trim(); return(str4); }
/// <summary> /// returns the whitespaces which are before a non white space character in the line line /// as a string. /// </summary> protected string GetIndentation(TextArea textArea, int lineNumber, bool smart) { if (lineNumber < 0 || lineNumber > textArea.Document.TotalNumberOfLines) { throw new ArgumentOutOfRangeException("lineNumber"); } string lineText = TextUtilities.GetLineAsString(textArea.Document, lineNumber); StringBuilder whitespaces = new StringBuilder(); foreach (char ch in lineText) { if (Char.IsWhiteSpace(ch)) { whitespaces.Append(ch); } else { break; } } if (smart) { bool append = false; string word = lineText.TrimEnd(whitespaceChars).ToLowerInvariant(); if (word.EndsWith(" else") || word.EndsWith(" then")) { append = true; } else if (word.EndsWith(" begin")) { if (word.TrimStart().StartsWith("procedure ") && textArea.Document.FoldingManager.IsFoldStart(lineNumber)) { goto exiting; } lineNumber += 2; string newLine = CheckAndAddEndNewLine(lineNumber, textArea); LineSegment line = textArea.Document.GetLineSegment(lineNumber); if (textArea.Document.GetText(line).TrimStart(whitespaceChars).Length == 0) { if (lineText.TrimStart(whitespaceChars).ToLowerInvariant().StartsWith("if ")) { newLine = CheckAndAddEndNewLine(++lineNumber, textArea); lineText = TextUtilities.GetLineAsString(textArea.Document, lineNumber); textArea.Document.Insert(line.Offset, whitespaces.ToString() + "end" + newLine); word = lineText.TrimEnd(whitespaceChars).ToLowerInvariant(); if (word.EndsWith(" end")) { line = textArea.Document.GetLineSegment(lineNumber); textArea.Document.Insert(line.Offset, whitespaces.ToString() + "else begin" + newLine); } } else { textArea.Document.Insert(line.Offset, whitespaces.ToString() + "end" + newLine); } } append = true; } if (append) { if (textArea.TextEditorProperties.ConvertTabsToSpaces) { whitespaces.Append(new string(whitespaceChars[0], textArea.Document.TextEditorProperties.IndentationSize)); } else { whitespaces.Append(whitespaceChars[1]); } } } exiting: return(whitespaces.ToString()); }