当前位置: 首页>>代码示例>>C#>>正文


C# TextDocument.GetCharAt方法代码示例

本文整理汇总了C#中ICSharpCode.AvalonEdit.Document.TextDocument.GetCharAt方法的典型用法代码示例。如果您正苦于以下问题:C# TextDocument.GetCharAt方法的具体用法?C# TextDocument.GetCharAt怎么用?C# TextDocument.GetCharAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.AvalonEdit.Document.TextDocument的用法示例。


在下文中一共展示了TextDocument.GetCharAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetStartType

        /// <summary>
        /// Gets the type of code at offset.<br/>
        /// 0 = Code,<br/>
        /// 1 = Comment,<br/>
        /// 2 = String<br/>
        /// Block comments and multiline strings are not supported.
        /// </summary>
        static int GetStartType(TextDocument document, int linestart, int offset)
        {
            bool inString = false;
            bool inChar = false;
            bool verbatim = false;
            int result = 0;
            for (int i = linestart; i < offset; i++)
            {
                switch (document.GetCharAt(i))
                {
                    case '/':
                        if (!inString && !inChar && i + 1 < document.TextLength)
                        {
                            if (document.GetCharAt(i + 1) == '/')
                            {
                                result = 1;
                            }
                        }
                        break;

                    case '"':
                    case '\'':
                        if (!inChar)
                        {
                            if (inString && verbatim)
                            {
                                if (i + 1 < document.TextLength && document.GetCharAt(i + 1) == '"')
                                {
                                    ++i; // skip escaped quote
                                    inString = false; // let the string go on
                                }
                                else
                                {
                                    verbatim = false;
                                }
                            }
                            else if (!inString && i > 0 && document.GetCharAt(i - 1) == '@')
                            {
                                verbatim = true;
                            }
                            inString = !inString;
                        }
                        break;

                    case '\\':
                        if ((inString && !verbatim) || inChar)
                            ++i; // skip next character
                        break;
                }
            }

            return (inString || inChar) ? 2 : result;
        }
开发者ID:Konctantin,项目名称:Yanitta,代码行数:60,代码来源:BracketSearcher.cs

示例2: SearchBracket

 public BracketSearchResult SearchBracket(TextDocument document, int offset)
 {
     BracketSearchResult result;
     if (offset > 0)
     {
         var charAt = document.GetCharAt(offset - 1);
         var num = "([{".IndexOf(charAt);
         var num2 = -1;
         if (num > -1)
         {
             num2 = SearchBracketForward(document, offset, "([{"[num], ")]}"[num]);
         }
         num = ")]}".IndexOf(charAt);
         if (num > -1)
         {
             num2 = SearchBracketBackward(document, offset - 2, "([{"[num], ")]}"[num]);
         }
         if (num2 > -1)
         {
             result = new BracketSearchResult(Math.Min(offset - 1, num2), 1, Math.Max(offset - 1, num2), 1);
             return result;
         }
     }
     result = null;
     return result;
 }
开发者ID:mookiejones,项目名称:miEditor,代码行数:26,代码来源:MyBracketSearcher.cs

示例3: RawlyIndentLine

        public void RawlyIndentLine(int tabsToInsert, TextDocument document, DocumentLine line)
        {
            if (!_doBeginUpdateManually)
                document.BeginUpdate();
            /*
             * 1) Remove old indentation
             * 2) Insert new one
             */

            // 1)
            int prevInd = 0;
            int curOff = line.Offset;
            if (curOff < document.TextLength)
            {
                char curChar = '\0';
                while (curOff < document.TextLength && ((curChar = document.GetCharAt(curOff)) == ' ' || curChar == '\t'))
                {
                    prevInd++;
                    curOff++;
                }

                document.Remove(line.Offset, prevInd);
            }

            // 2)
            string indentString = "";
            for (int i = 0; i < tabsToInsert; i++)
                indentString += dEditor.Editor.Options.IndentationString;

            document.Insert(line.Offset, indentString);
            if (!_doBeginUpdateManually)
                document.EndUpdate();
        }
开发者ID:rumbu13,项目名称:D-IDE,代码行数:33,代码来源:DIndentationStrategy.cs

示例4: CreateMethodFold

        private void CreateMethodFold(TextDocument textDocument)
        {
            // TODO: Find a way to fold just functions brackets.

            this.startOffsets.Push(this.currentOffset);

            this.bracketSearcher.OpeningBrackets = "{";
            this.bracketSearcher.ClosingBrackets = "}";

            BracketSearchResult result = this.bracketSearcher.SearchBracket(textDocument, this.currentOffset + 1);

            if (result != null)
            {
                int startOffset = startOffsets.Pop();

                // Skip empty spaces.
                for(int i = startOffset - 1; i > 0; i--)
                {
                    char character = textDocument.GetCharAt(i);

                    if (char.IsWhiteSpace(character) == false && character != '\n' && character != '\r')
                    {
                        startOffset = i + 1;
                        break;
                    }
                }

                this.foldings.Foldings.Add(new NewFolding(startOffset, result.ClosingBracketOffset + 1) { Name = "..." });
            }
        }
开发者ID:123marvin123,项目名称:PawnPlus,代码行数:30,代码来源:PawnFoldingStrategy.cs

示例5: SearchBracket

        public BracketSearchResult SearchBracket(TextDocument document, int offset)
        {
            if (offset > 0)
            {
                var c = document.GetCharAt(offset - 1);
                int index = openingBrackets.IndexOf(c);
                int otherOffset = -1;
                if (index > -1)
                    otherOffset = SearchBracketForward(document, offset, openingBrackets[index], closingBrackets[index]);

                index = closingBrackets.IndexOf(c);
                if (index > -1)
                    otherOffset = SearchBracketBackward(document, offset - 2, openingBrackets[index], closingBrackets[index]);

                if (otherOffset > -1)
                {
                    var result = new BracketSearchResult(
                        Math.Min(offset - 1, otherOffset),
                        Math.Max(offset - 1, otherOffset));
                    SearchDefinition(document, result);
                    return result;
                }
            }

            return null;
        }
开发者ID:arkanoid1,项目名称:Yanitta,代码行数:26,代码来源:BracketSearcher.cs

示例6: CreateCommentFold

        private void CreateCommentFold(TextDocument textDocument)
        {
            this.startOffsets.Push(this.currentOffset - 1);

            for (; this.currentOffset < textDocument.TextLength; this.currentOffset++)
            {
                char character = textDocument.GetCharAt(this.currentOffset);

                if (character == '*' && textDocument.GetCharAt(++this.currentOffset) == '/')
                {
                    this.currentOffset++;
                    foldings.Foldings.Add(new NewFolding(startOffsets.Pop(), this.currentOffset) { Name = "/* ..." });

                    break;
                }
            }
        }
开发者ID:123marvin123,项目名称:PawnPlus,代码行数:17,代码来源:PawnFoldingStrategy.cs

示例7: SearchDefinition

 void SearchDefinition(TextDocument document, BracketSearchResult result)
 {
     if (document.GetCharAt(result.OpeningOffset) != '{')
         return;
     // get line
     var documentLine = document.GetLineByOffset(result.OpeningOffset);
     while (documentLine != null && IsBracketOnly(document, documentLine))
         documentLine = documentLine.PreviousLine;
     if (documentLine != null)
     {
         result.DefinitionHeaderOffset = documentLine.Offset;
         result.DefinitionHeaderLength = documentLine.Length;
     }
 }
开发者ID:arkanoid1,项目名称:Yanitta,代码行数:14,代码来源:BracketSearcher.cs

示例8: FindAndMarkRegions

        /// <summary>
        /// Finds and marks all regions.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="offset">The offset where the search starts.</param>
        /// <param name="folds">The fold markers.</param>
        /// <returns>The index of the next character after the all regions.</returns>
        /// <remarks>
        /// This method returns when it finds a "#endregion" string that does not have
        /// a "#region" statement after <paramref name="offset"/>. In this case it 
        /// returns the index of the next character after the "#endregion" statement.
        /// </remarks>
        private static int FindAndMarkRegions(TextDocument document, int offset, List<NewFolding> folds)
        {
            if (offset >= document.TextLength)
                return offset;

            while (offset < document.TextLength)
            {
                char c = document.GetCharAt(offset);
                switch (c)
                {
                    case '/':
                        // Skip comments
                        offset = SkipComment(document, offset);
                        break;
                    case '#':
                        string word = TextUtilities.GetIdentifierAt(document, offset + 1);
                        if (word == "region")
                        {
                            offset = MarkRegion(document, offset, folds);
                        }
                        else if (word == "endregion")
                        {
                            return offset + "endregion".Length + 1;
                        }
                        else
                        {
                            offset++;
                        }
                        break;
                    default:
                        // Skip to next word
                        int endOfIdentifier = TextUtilities.FindEndOfIdentifier(document, offset);
                        if (endOfIdentifier > 0)
                            offset = endOfIdentifier + 1;
                        else
                            ++offset;
                        break;
                }
            }
            return offset;
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:53,代码来源:CSharpFoldingStrategy.cs

示例9: MarkBlocks

 /// <summary>
 /// Marks all code blocks (namespaces, classes, methods, etc.) in the document.
 /// </summary>
 /// <param name="document">The document.</param>
 /// <param name="foldMarkers">The fold markers.</param>
 private static void MarkBlocks(TextDocument document, ICollection<NewFolding> foldMarkers)
 {
     int offset = 0;
     while (offset < document.TextLength)
     {
         switch (document.GetCharAt(offset))
         {
             case '/':
                 offset = SkipComment(document, offset);
                 break;
             case 'c':
                 offset = MarkBlock("class", document, offset, foldMarkers);
                 break;
             case 'e':
                 offset = MarkBlock("enum", document, offset, foldMarkers);
                 break;
             case 'i':
                 offset = MarkBlock("interface", document, offset, foldMarkers);
                 break;
             case 'n':
                 offset = MarkBlock("namespace", document, offset, foldMarkers);
                 break;
             case 's':
                 offset = MarkBlock("struct", document, offset, foldMarkers);
                 break;
             case '{':
                 offset = MarkMethod(document, offset, foldMarkers);
                 break;
             default:
                 int endOfIdentifier = TextUtilities.FindEndOfIdentifier(document, offset);
                 if (endOfIdentifier > 0)
                     offset = endOfIdentifier + 1;
                 else
                     ++offset;
                 break;
         }
     }
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:43,代码来源:CSharpFoldingStrategy.cs

示例10: InsertBold

        public void InsertBold(int start, int length, TextDocument document)
        {
            var chs = document.GetCharAt(start);
            var che = document.GetCharAt(start + length - 1);

            document.Insert(start + length - 1, che.ToString());
            document.Replace(start + length, 1, "]");   //trick to keep anchors

            document.Insert(start + 1, chs.ToString());
            document.Replace(start, 1, "["); //trick to keep anchors

            Blocks.Add(new TextBlockBold()
            {
                OriginallyLength = length + 2,
                OriginallyOffset = start,
                MyAnchor = new AnchorSegment(document, start, length + 2)
            });
        }
开发者ID:yetanothervan,项目名称:conspector,代码行数:18,代码来源:TextModel.cs

示例11: MarkBlock

        /// <summary>
        /// Marks the block that starts at the current offset.
        /// </summary>
        /// <param name="name">The identifier of the block (e.g. "class", "struct").</param>
        /// <param name="document">The document.</param>
        /// <param name="offset">The offset of the identifier.</param>
        /// <param name="foldMarkers">The fold markers.</param>
        /// <returns>The index of the next character after the block.</returns>
        private static int MarkBlock(string name, TextDocument document, int offset, ICollection<NewFolding> foldMarkers)
        {
            if (offset >= document.TextLength)
                return offset;

            string word = TextUtilities.GetIdentifierAt(document, offset);
            if (word == name)
            {
                offset += word.Length;
                while (offset < document.TextLength)
                {
                    char c = document.GetCharAt(offset);
                    if (c == '}' || c == ';')
                    {
                        offset++;
                        break;
                    }
                    if (c == '{')
                    {
                        int startOffset = offset;
                        while (Char.IsWhiteSpace(document.GetCharAt(startOffset - 1)))
                            startOffset--;

                        int offsetOfClosingBracket = TextUtilities.FindClosingBracket(document, offset + 1, '{', '}');
                        if (offsetOfClosingBracket > 0)
                        {
                            AddFold(document, foldMarkers, startOffset, offsetOfClosingBracket + 1, "{...}");

                            // Skip to offset after '{'.
                            offset++;
                            break;
                        }
                    }
                    offset++;
                }
            }
            else
            {
                // Skip to next word
                offset += word.Length;
            }
            return offset;
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:51,代码来源:CSharpFoldingStrategy.cs

示例12: CreateNewFoldings

        private void CreateNewFoldings(TextDocument textDocument)
        {
            for (this.currentOffset = 0; this.currentOffset < textDocument.TextLength; this.currentOffset++)
            {
                char character = textDocument.GetCharAt(this.currentOffset);

                if (character == '{')
                {
                    this.CreateMethodFold(textDocument);
                }
                else if (character == '/' && ++this.currentOffset < textDocument.TextLength && textDocument.GetCharAt(this.currentOffset) == '*')
                {
                    this.CreateCommentFold(textDocument);
                }
            }

            this.foldings.Foldings.Sort((first, second) => first.StartOffset.CompareTo(second.StartOffset));
        }
开发者ID:123marvin123,项目名称:PawnPlus,代码行数:18,代码来源:PawnFoldingStrategy.cs

示例13: CreateNewFoldings

        private IEnumerable<NewFolding> CreateNewFoldings(TextDocument document)
        {
            var newFoldings = new List<NewFolding>();

            var startOffsets = new Stack<int>();
            var titles = new Stack<string>();
            var lastNewLineOffset = 0;
            for (var i = 0; i < document.TextLength; i++)
            {
                var c = document.GetCharAt(i);
                if (c == '#')
                {
                    // see if the next word is 'region', or 'endregion'
                    var directive = new StringBuilder();

                    var j = i + 1;
                    while (j < document.TextLength && !Char.IsWhiteSpace(document.GetCharAt(j)))
                    {
                        directive.Append(document.GetCharAt(j++));
                    }

                    if (directive.ToString().Equals("region"))
                    {

                        j++;

                        var nameBuilder = new StringBuilder();
                        while (j < document.TextLength && !Char.IsWhiteSpace(document.GetCharAt(j)))
                        {
                            nameBuilder.Append(document.GetCharAt(j++));
                        }

                        titles.Push(nameBuilder.ToString());

                        // go to next newline (if there is one), otherwise we don't start an offset
                        while(j < document.TextLength)
                        {
                            c = document.GetCharAt(j++);
                            if (c != '\n' && c != '\r') continue;

                            lastNewLineOffset = j;
                            startOffsets.Push(i);
                            break;
                        }
                    }
                    else if (directive.ToString().Equals("endregion") && startOffsets.Count > 0)
                    {
                        var startOffset = startOffsets.Pop();
                        var name = titles.Pop();

                        // don't fold if opening and closing brace are on the same line
                        if (startOffset < lastNewLineOffset)
                        {
                            newFoldings.Add(new NewFolding(startOffset, j) {Name = name} );
                        }
                    }

                    i = j;
                }
                else if (c == '\n' || c == '\r')
                {
                    lastNewLineOffset = i + 1;
                }

            }

            lastNewLineOffset = 0;
            const char openingBrace = '{';
            const char closingBrace = '}';
            for (var i = 0; i < document.TextLength; i++)
            {
                var c = document.GetCharAt(i);
                if (c == openingBrace)
                {
                    startOffsets.Push(i);
                }
                else if (c == closingBrace && startOffsets.Count > 0)
                {
                    var startOffset = startOffsets.Pop();
                    // don't fold if opening and closing brace are on the same line
                    if (startOffset < lastNewLineOffset)
                    {
                        newFoldings.Add(new NewFolding(startOffset, i + 1));
                    }
                }
                else if (c == '\n' || c == '\r')
                {
                    lastNewLineOffset = i + 1;
                }
            }

            newFoldings.Sort((a, b) => a.StartOffset.CompareTo(b.StartOffset));
            return newFoldings;
        }
开发者ID:soshimozi,项目名称:RedTail,代码行数:94,代码来源:RegionFoldingStrategy.cs

示例14: SkipComment

        /// <summary>
        /// Skips any comments that start at the current offset.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="offset">The offset.</param>
        /// <returns>The index of the next character after the comments.</returns>
        private static int SkipComment(TextDocument document, int offset)
        {
            if (offset >= document.TextLength - 1)
                return offset + 1;

            char current = document.GetCharAt(offset);
            char next = document.GetCharAt(offset + 1);

            if (current == '/' && next == '/')
            {
                // Skip line comment "//"
                var line = document.GetLineByOffset(offset);
                int offsetOfNextLine = line.Offset + line.TotalLength;
                return offsetOfNextLine;
            }

            if (current == '/' && next == '*')
            {
                // Skip block comment "/* ... */"
                offset += 2;
                while (offset + 1 < document.TextLength)
                {
                    if (document.GetCharAt(offset) == '*' && document.GetCharAt(offset + 1) == '/')
                    {
                        offset = offset + 2;
                        break;
                    }
                    offset++;
                }
                return offset;
            }

            return offset + 1;
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:40,代码来源:CSharpFoldingStrategy.cs

示例15: GetExpressionBeforeOffset

        /// <summary>
        /// Gets the expression before a given offset.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="initialOffset">The initial offset.</param>
        /// <returns>The expression.</returns>
        /// <remarks>
        /// This method returns the expression before a specified offset.
        /// That method is used in code completion to determine the expression before
        /// the caret. The expression can be passed to a parser to resolve the type
        /// or similar.
        /// </remarks>
        internal static string GetExpressionBeforeOffset(TextDocument document, int initialOffset)
        {
            int offset = initialOffset;
            while (offset - 1 > 0)
            {
                switch (document.GetCharAt(offset - 1))
                {
                    case '\n':
                    case '\r':
                    case '}':
                        goto done;
                    //offset = FindOpeningBracket(document, offset - 2, '{','}');
                    //break;
                    case ']':
                        offset = FindOpeningBracket(document, offset - 2, '[', ']');
                        break;
                    case ')':
                        offset = FindOpeningBracket(document, offset - 2, '(', ')');
                        break;
                    case '.':
                        --offset;
                        break;
                    case '"':
                        if (offset < initialOffset - 1)
                        {
                            return null;
                        }
                        return "\"\"";
                    case '\'':
                        if (offset < initialOffset - 1)
                        {
                            return null;
                        }
                        return "'a'";
                    case '>':
                        if (document.GetCharAt(offset - 2) == '-')
                        {
                            offset -= 2;
                            break;
                        }
                        goto done;
                    default:
                        if (char.IsWhiteSpace(document.GetCharAt(offset - 1)))
                        {
                            --offset;
                            break;
                        }
                        int start = offset - 1;
                        if (!IsIdentifierPart(document.GetCharAt(start)))
                        {
                            goto done;
                        }

                        while (start > 0 && IsIdentifierPart(document.GetCharAt(start - 1)))
                        {
                            --start;
                        }
                        string word = document.GetText(start, offset - start).Trim();
                        switch (word)
                        {
                            case "ref":
                            case "out":
                            case "in":
                            case "return":
                            case "throw":
                            case "case":
                                goto done;
                        }

                        if (word.Length > 0 && !IsIdentifierPart(word[0]))
                        {
                            goto done;
                        }
                        offset = start;
                        break;
                }
            }
            done:
            // simple exit fails when : is inside comment line or any other character
            // we have to check if we got several ids in resulting line, which usually happens when
            // id. is typed on next line after comment one
            // Would be better if lexer would parse properly such expressions. However this will cause
            // modifications in this area too - to get full comment line and remove it afterwards
            if (offset < 0)
                return string.Empty;

            string resText = document.GetText(offset, initialOffset - offset).Trim();
            int pos = resText.LastIndexOf('\n');
//.........这里部分代码省略.........
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:101,代码来源:TextUtilities.cs


注:本文中的ICSharpCode.AvalonEdit.Document.TextDocument.GetCharAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。