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


C# IDocument.GetCharAt方法代码示例

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


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

示例1: GenerateFoldMarkers

        /// <summary>
        /// Generates the foldings for our document.
        /// </summary>
        /// <param name="document">The current document.</param>
        /// <param name="fileName">The filename of the document.</param>
        /// <param name="parseInformation">Extra parse information, not used in this sample.</param>
        /// <returns>A list of FoldMarkers.</returns>
        public List<FoldMarker> GenerateFoldMarkers(IDocument document, string fileName, object parseInformation)
        {
            List<FoldMarker> list = new List<FoldMarker>();

            Stack<int> startLines = new Stack<int>();

            // Create foldmarkers for the whole document, enumerate through every line.
            for (int i = 0; i < document.TotalNumberOfLines; i++)
            {
                LineSegment seg = document.GetLineSegment(i);
                int offs, end = document.TextLength;
                char c;
                for (offs = seg.Offset; offs < end && ((c = document.GetCharAt(offs)) == ' ' || c == '\t'); offs++)
                { }
                if (offs == end)
                    break;
                int spaceCount = offs - seg.Offset;

                // now offs points to the first non-whitespace char on the line
                if (document.GetCharAt(offs) == '#')
                {
                    string text = document.GetText(offs, seg.Length - spaceCount);
                    if (text.StartsWith("#region"))
                        startLines.Push(i);
                    if (text.StartsWith("#endregion") && startLines.Count > 0)
                    {
                        // Add a new FoldMarker to the list.
                        int start = startLines.Pop();
                        list.Add(new FoldMarker(document, start, document.GetLineSegment(start).Length, i, spaceCount + "#endregion".Length));
                    }
                }
            }

            return list;
        }
开发者ID:276398084,项目名称:KW.OrderManagerSystem,代码行数:42,代码来源:RegionFoldingStrategy.cs

示例2: DoQuickFindForward

		int DoQuickFindForward(IDocument document, int offset, char openBracket, char closingBracket)
		{
			int brackets = 1;
			// try "quick find" - find the matching bracket if there is no string/comment in the way
			for (int i = offset; i < document.TextLength; ++i) {
				char ch = document.GetCharAt(i);
				if (ch == openBracket) {
					++brackets;
				} else if (ch == closingBracket) {
					--brackets;
					if (brackets == 0) return i;
				} else if (ch == '"') {
					break;
				} else if (ch == '#') {
					break;
				} else if (ch == '\'') {
					break;
				} else if (ch == '/' && i > 0) {
					if (document.GetCharAt(i - 1) == '/') break;
				} else if (ch == '*' && i > 0) {
					if (document.GetCharAt(i - 1) == '/') break;
				}
			}
			return -1;
		}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:25,代码来源:FormattingStrategy.cs

示例3: 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(IDocument 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 "//"
        LineSegment line = document.GetLineSegmentForOffset(offset);
        int offsetOfNextLine = line.Offset + line.TotalLength;
        return offsetOfNextLine;
      }
      else 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;
      }
      else
      {
        return offset + 1;
      }
    }
开发者ID:sanyaade-fintechnology,项目名称:SquareOne,代码行数:41,代码来源:CSharpFoldingStrategy.cs

示例4: SearchBracketBackward

		static int SearchBracketBackward(IDocument document, int offset, char openBracket, char closingBracket)
		{
			bool inString  = false;
			char ch;
			int brackets = -1;
			for (int i = offset; i > 0; --i) {
				ch = document.GetCharAt(i);
				if (ch == openBracket && !inString) {
					++brackets;
					if (brackets == 0) return i;
				} else if (ch == closingBracket && !inString) {
					--brackets;
				} else if (ch == '"') {
					inString = !inString;
				} else if (ch == '\n') {
					int lineStart = ScanLineStart(document, i);
					if (lineStart >= 0) { // line could have a comment
						inString = false;
						for (int j = lineStart; j < i; ++j) {
							ch = document.GetCharAt(j);
							if (ch == '"') inString = !inString;
							if (ch == '\'' && !inString) {
								// comment found!
								// Skip searching in the comment:
								i = j;
								break;
							}
						}
					}
					inString = false;
				}
			}
			return -1;
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:34,代码来源:VBNetBracketSearcher.cs

示例5: FindWordEnd

        static int FindWordEnd(IDocument document, int offset)
        {
            LineSegment line = document.GetLineSegmentForOffset(offset);
              int endPos = line.Offset + line.Length;
              offset = Math.Min(offset, endPos - 1);

              if (IsSelectableChar(document.GetCharAt(offset)))
              {
            while (offset < endPos && IsSelectableChar(document.GetCharAt(offset)))
            {
              ++offset;
            }
              }
              else if (Char.IsWhiteSpace(document.GetCharAt(offset)))
              {
            if (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset - 1)))
            {
              while (offset < endPos && Char.IsWhiteSpace(document.GetCharAt(offset)))
              {
            ++offset;
              }
            }
              }
              else
              {
            return Math.Max(0, offset + 1);
              }

              return offset;
        }
开发者ID:cavaliercoder,项目名称:expression-lab,代码行数:30,代码来源:TextAreaMouseHandler.cs

示例6: 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(IDocument 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 '"':
                        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) inChar = !inChar;
                        break;
                    case '\\':
                        if ((inString && !verbatim) || inChar)
                            ++i; // skip next character
                        break;
                }
            }

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

示例7: MarkDifference

        private static void MarkDifference(IDocument document, ISegment lineRemoved,
            ISegment lineAdded, int beginOffset)
        {
            var lineRemovedEndOffset = lineRemoved.Length;
            var lineAddedEndOffset = lineAdded.Length;
            var endOffsetMin = Math.Min(lineRemovedEndOffset, lineAddedEndOffset);
            var reverseOffset = 0;

            while (beginOffset < endOffsetMin)
            {
                if (!document.GetCharAt(lineAdded.Offset + beginOffset).Equals(
                        document.GetCharAt(lineRemoved.Offset + beginOffset)))
                    break;

                beginOffset++;
            }

            while (lineAddedEndOffset > beginOffset && lineRemovedEndOffset > beginOffset)
            {
                reverseOffset = lineAdded.Length - lineAddedEndOffset;

                if (!document.GetCharAt(lineAdded.Offset + lineAdded.Length - 1 - reverseOffset).
                         Equals(document.GetCharAt(lineRemoved.Offset + lineRemoved.Length - 1 -
                                                   reverseOffset)))
                    break;

                lineRemovedEndOffset--;
                lineAddedEndOffset--;
            }

            Color color;
            var markerStrategy = document.MarkerStrategy;

            if (lineAdded.Length - beginOffset - reverseOffset > 0)
            {
                color = AppSettings.DiffAddedExtraColor;
                markerStrategy.AddMarker(new TextMarker(lineAdded.Offset + beginOffset,
                                                        lineAdded.Length - beginOffset - reverseOffset,
                                                        TextMarkerType.SolidBlock, color,
                                                        ColorHelper.GetForeColorForBackColor(color)));
            }

            if (lineRemoved.Length - beginOffset - reverseOffset > 0)
            {
                color = AppSettings.DiffRemovedExtraColor;
                markerStrategy.AddMarker(new TextMarker(lineRemoved.Offset + beginOffset,
                                                        lineRemoved.Length - beginOffset - reverseOffset,
                                                        TextMarkerType.SolidBlock, color,
                                                        ColorHelper.GetForeColorForBackColor(color)));
            }

        }
开发者ID:vbjay,项目名称:gitextensions,代码行数:52,代码来源:DiffHighlightService.cs

示例8:

        /// <summary>
        /// Get the object, which was inserted under the keyword (line, at offset, with length length),
        /// returns null, if no such keyword was inserted.
        /// </summary>
        public object this[IDocument document, LineSegment line, int offset, int length]
        {
            get
            {
                if(length == 0)
                {
                    return null;
                }
                Node next = root;

                int wordOffset = line.Offset + offset;
                if (casesensitive)
                {
                    for (int i = 0; i < length; ++i)
                    {
                        int index = ((int)document.GetCharAt(wordOffset + i)) % 256;
                        next = next[index];

                        if (next == null)
                        {
                            return null;
                        }

                        if (next.color != null && TextUtility.RegionMatches(document, wordOffset, length, next.word))
                        {
                            return next.color;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < length; ++i)
                    {
                        int index = ((int)Char.ToUpper(document.GetCharAt(wordOffset + i))) % 256;

                        next = next[index];

                        if (next == null)
                        {
                            return null;
                        }

                        if (next.color != null && TextUtility.RegionMatches(document, casesensitive, wordOffset, length, next.word))
                        {
                            return next.color;
                        }
                    }
                }
                return null;
            }
        }
开发者ID:KindDragon,项目名称:ICSharpCode.TextEditor.V4,代码行数:55,代码来源:LookupTable.cs

示例9: DoesLineStartWith

        public bool DoesLineStartWith(IDocument document, int lineOffset, string prefixStr)
        {
            Debug.Assert(prefixStr.Length <= 2 && prefixStr.Length >= 1);
            if (prefixStr.Length == 1) return document.GetCharAt(lineOffset) == prefixStr[0];

            if (document.TextLength <= lineOffset + 1)
            {
                return false;
            }

            var firstChar = document.GetCharAt(lineOffset);
            var secondChar = document.GetCharAt(lineOffset + 1);

            return firstChar == prefixStr[0] && secondChar == prefixStr[1];
        }
开发者ID:vbjay,项目名称:gitextensions,代码行数:15,代码来源:LinePrefixHelper.cs

示例10: SearchBracket

        public BracketSearchResult SearchBracket(IDocument document, int offset)
        {
            if (offset > 0)
            {
                char 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), 1,
                                                         Math.Max(offset - 1, otherOffset), 1);
                    SearchDefinition(document, result);
                    return result;
                }
            }

            return null;
        }
开发者ID:123marvin123,项目名称:PawnPlus,代码行数:25,代码来源:BracketSearcher.cs

示例11: SearchBracketForward

 int SearchBracketForward(IDocument document, int offset, char openBracket, char closingBracket)
 {
     int brackets = 1;
     for(int i = offset; i < document.TextLength; ++i){
         char ch = document.GetCharAt(i);
         if(ch == openBracket){
             ++brackets;
         }else if(ch == closingBracket){
             --brackets;
             if (brackets == 0) return i;
         }else if(ch == '/' && i > 0){
             if (document.GetCharAt(i - 1) == '/') break;
         }
     }
     return -1;
 }
开发者ID:hazama-yuinyan,项目名称:sharpdevelop-bvebinding,代码行数:16,代码来源:BVE5BracketSearcher.cs

示例12: GetHighlight

		public BracketHighlight GetHighlight(IDocument document, int offset)
		{
			int searchOffset;
			if (document.TextEditorProperties.BracketMatchingStyle == BracketMatchingStyle.After) {
				searchOffset = offset;
			} else {
				searchOffset = offset + 1;
			}
			char word = document.GetCharAt(Math.Max(0, Math.Min(document.TextLength - 1, searchOffset)));
			
			TextLocation endP = document.OffsetToPosition(searchOffset);
			if (word == opentag) {
				if (searchOffset < document.TextLength) {
					int bracketOffset = TextUtilities.SearchBracketForward(document, searchOffset + 1, opentag, closingtag);
					if (bracketOffset >= 0) {
						TextLocation p = document.OffsetToPosition(bracketOffset);
						return new BracketHighlight(p, endP);
					}
				}
			} else if (word == closingtag) {
				if (searchOffset > 0) {
					int bracketOffset = TextUtilities.SearchBracketBackward(document, searchOffset - 1, opentag, closingtag);
					if (bracketOffset >= 0) {
						TextLocation p = document.OffsetToPosition(bracketOffset);
						return new BracketHighlight(p, endP);
					}
				}
			}
			return null;
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:30,代码来源:BracketHighlighter.cs

示例13: MarkCodeBlocks

 /// <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 void MarkCodeBlocks(IDocument document, List<FoldMarker> 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:
         offset = TextUtilities.FindWordEnd(document, offset) + 1;
         break;
     }
   }
 }
开发者ID:Finarch,项目名称:DigitalRune.Windows.TextEditor,代码行数:39,代码来源:CSharpFoldingStrategy.cs

示例14: GenerateFoldMarkers

        /// Interface implementation.
        public List<FoldMarker> GenerateFoldMarkers(IDocument document, string fileName, object parseInformation)
        {
            List<FoldMarker> foldMarkers = new List<FoldMarker>();

            Stack<int> startOffsets = new Stack<int>();
            int lastNewLineOffset = 0;
            char openingBrace = '{';
            char closingBrace = '}';

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

            return foldMarkers;
        }
开发者ID:KindDragon,项目名称:ICSharpCode.TextEditor.V4,代码行数:34,代码来源:CodeFoldingStrategy.cs

示例15: ScanLineStart

		static int ScanLineStart(IDocument document, int offset)
		{
			for (int i = offset - 1; i > 0; --i) {
				if (document.GetCharAt(i) == '\n')
					return i + 1;
			}
			return 0;
		}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:8,代码来源:CSharpBracketSearcher.cs


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