GetLineAsString() публичный статический Метод

public static GetLineAsString ( IDocument document, int lineNumber ) : string
document IDocument
lineNumber int
Результат string
Пример #1
0
        /// <summary>
        /// Could be overwritten to define more complex indenting.
        /// </summary>
        protected virtual int AutoIndentLine(TextArea textArea, int lineNumber)
        {
            string indentation = lineNumber != 0 ? GetIndentation(textArea, lineNumber - 1) : "";

            if (indentation.Length > 0)
            {
                string      newLineText = indentation + TextUtilities.GetLineAsString(textArea.Document, lineNumber).Trim();
                LineSegment oldLine     = textArea.Document.GetLineSegment(lineNumber);
                textArea.Document.Replace(oldLine.Offset, oldLine.Length, newLineText);
            }
            return(indentation.Length);
        }
        protected virtual int AutoIndentLine(TextArea textArea, int lineNumber)
        {
            string str = (lineNumber != 0 ? this.GetIndentation(textArea, lineNumber - 1) : "");

            if (str.Length > 0)
            {
                string      str1        = string.Concat(str, TextUtilities.GetLineAsString(textArea.Document, lineNumber).Trim());
                LineSegment lineSegment = textArea.Document.GetLineSegment(lineNumber);
                DefaultFormattingStrategy.SmartReplaceLine(textArea.Document, lineSegment, str1);
            }
            return(str.Length);
        }
Пример #3
0
        /// <summary>
        ///     Could be overwritten to define more complex indenting.
        /// </summary>
        protected virtual int AutoIndentLine(TextArea textArea, int lineNumber)
        {
            var indentation = lineNumber != 0 ? GetIndentation(textArea, lineNumber - 1) : "";

            if (indentation.Length > 0)
            {
                var newLineText = indentation + TextUtilities.GetLineAsString(textArea.Document, lineNumber).Trim();
                var oldLine     = textArea.Document.GetLineSegment(lineNumber);
                SmartReplaceLine(textArea.Document, oldLine, newLineText);
            }

            return(indentation.Length);
        }
        protected string GetIndentation(TextArea textArea, int lineNumber)
        {
            if (lineNumber < 0 || lineNumber > textArea.Document.TotalNumberOfLines)
            {
                throw new ArgumentOutOfRangeException("lineNumber");
            }
            string        lineAsString  = TextUtilities.GetLineAsString(textArea.Document, lineNumber);
            StringBuilder stringBuilder = new StringBuilder();
            string        str           = lineAsString;

            for (int i = 0; i < str.Length; i++)
            {
                char chr = str[i];
                if (!char.IsWhiteSpace(chr))
                {
                    break;
                }
                stringBuilder.Append(chr);
            }
            return(stringBuilder.ToString());
        }
Пример #5
0
        /// <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)
        {
            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;
                }
            }
            return(whitespaces.ToString());
        }
Пример #6
0
        /// <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());
        }