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


C# ITextSource.GetCharAt方法代码示例

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


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

示例1: NextNewLine

		/// <summary>
		/// Gets the location of the next new line character, or SimpleSegment.Invalid
		/// if none is found.
		/// </summary>
		internal static SimpleSegment NextNewLine(ITextSource text, int offset)
		{
			int textLength = text.TextLength;
			int pos = text.IndexOfAny(newline, offset, textLength - offset);
			if (pos >= 0) {
				if (text.GetCharAt(pos) == '\r') {
					if (pos + 1 < textLength && text.GetCharAt(pos + 1) == '\n')
						return new SimpleSegment(pos, 2);
				}
				return new SimpleSegment(pos, 1);
			}
			return SimpleSegment.Invalid;
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:17,代码来源:NewLineFinder.cs

示例2: CreateNewFoldings

        /// <summary>
        ///     Create <see cref="NewFolding" />s for the specified document.
        /// </summary>
        public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
        {
            var newFoldings = new List<NewFolding>();

            var startOffsets = new Stack<int>();
            var lastNewLineOffset = 0;
            var openingBrace = OpeningBrace;
            var closingBrace = 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:Dessix,项目名称:TUM.CMS.VPLControl,代码行数:29,代码来源:BraceFoldingStrategy.cs

示例3: getOffsets

        protected IEnumerable<NewFolding> getOffsets(char opening, char closing, ITextSource document)
        {
            List<NewFolding> ret    = new List<NewFolding>();
            Stack<int> openings     = new Stack<int>();
            bool multiline          = false; //flag of multiline braces

            for(int pos = 0; pos < document.TextLength; ++pos)
            {
                char c = document.GetCharAt(pos);

                if(c == opening) {
                    openings.Push(pos + 1);
                    multiline = false;
                }
                else if(char.IsControl(c)) {
                    multiline = true;
                }
                else if(openings.Count > 0 && c == closing)
                {
                    int offset = openings.Pop();
                    if(multiline) {
                        ret.Add(new NewFolding(offset, pos));
                    }
                }
            }
            return ret;
        }
开发者ID:3F,项目名称:vsCommandEvent,代码行数:27,代码来源:BraceFoldingStrategy.cs

示例4: CreateNewFoldings

        /// <summary>
        /// Create <see cref="NewFolding"/>s for the specified document.
        /// </summary>
        public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
        {
            List<NewFolding> newFoldings = new List<NewFolding>();

            Stack<int> startOffsets = new Stack<int>();
            int lastNewLineOffset = 0;
            char openingBrace = this.OpeningBrace;
            char closingBrace = this.ClosingBrace;
            for (int i = 0; i < document.TextLength; i++)
            {
                char c = document.GetCharAt(i);
                bool isFirstInLine = IsFirstInLine(document, i);
                if (c == openingBrace && isFirstInLine)
                    startOffsets.Push(i);
                else if (c == closingBrace && isFirstInLine && startOffsets.Count > 0)
                {
                    int 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:netintellect,项目名称:NetOffice,代码行数:32,代码来源:BraceFoldingStrategy.cs

示例5: FindNextNewLine

 /// <summary>
 /// Finds the next new line character starting at offset.
 /// </summary>
 /// <param name="text">The text source to search in.</param>
 /// <param name="offset">The starting offset for the search.</param>
 /// <param name="newLineType">The string representing the new line that was found, or null if no new line was found.</param>
 /// <returns>The position of the first new line starting at or after <paramref name="offset"/>,
 /// or -1 if no new line was found.</returns>
 public static int FindNextNewLine(ITextSource text, int offset, out string newLineType)
 {
     if (text == null)
         throw new ArgumentNullException(nameof(text));
     if (offset < 0 || offset > text.TextLength)
         throw new ArgumentOutOfRangeException(nameof(offset), offset, "offset is outside of text source");
     SimpleSegment s = NewLineFinder.NextNewLine(text, offset);
     if (s == SimpleSegment.Invalid)
     {
         newLineType = null;
         return -1;
     }
     else
     {
         if (s.Length == 2)
         {
             newLineType = "\r\n";
         }
         else if (text.GetCharAt(s.Offset) == '\n')
         {
             newLineType = "\n";
         }
         else
         {
             newLineType = "\r";
         }
         return s.Offset;
     }
 }
开发者ID:arkanoid1,项目名称:Yanitta,代码行数:37,代码来源:NewLineFinder.cs

示例6: GetSingleIndentationSegment

		/// <summary>
		///     Gets a single indentation segment starting at <paramref name="offset" /> - at most one tab
		///     or <paramref name="indentationSize" /> spaces.
		/// </summary>
		/// <param name="textSource">The text source.</param>
		/// <param name="offset">The offset where the indentation segment starts.</param>
		/// <param name="indentationSize">The size of an indentation unit. See <see cref="TextEditorOptions.IndentationSize" />.</param>
		/// <returns>
		///     The indentation segment.
		///     If there is no indentation character at the specified <paramref name="offset" />,
		///     an empty segment is returned.
		/// </returns>
		public static ISegment GetSingleIndentationSegment(ITextSource textSource, int offset, int indentationSize)
		{
			if (textSource == null)
				throw new ArgumentNullException("textSource");
			var pos = offset;
			while (pos < textSource.TextLength)
			{
				var c = textSource.GetCharAt(pos);
				if (c == '\t')
				{
					if (pos == offset)
						return new SimpleSegment(offset, 1);
					break;
				}
				if (c == ' ')
				{
					if (pos - offset >= indentationSize)
						break;
				}
				else
				{
					break;
				}
				// continue only if c==' ' and (pos-offset)<tabSize
				pos++;
			}
			return new SimpleSegment(offset, pos - offset);
		}
开发者ID:VitalElement,项目名称:AvalonStudio,代码行数:40,代码来源:TextUtilities.cs

示例7: CreateNewFoldings

        public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
        {
            if (document == null)
                throw new ArgumentNullException("document");

            var newFoldings = new List<NewFolding>();

            var startOffsets = new Stack<int>();
            int lastNewLineOffset = 0;
            char openingBrace = OpeningBrace;
            char closingBrace = 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)
                    {
                        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:Xamarui,项目名称:elasticops,代码行数:35,代码来源:BraceFoldingStrategy.cs

示例8: CreateNewFoldings

		/// <summary>
		/// Create <see cref="NewFolding"/>s for the specified document.
		/// </summary>
		public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
		{
			List<NewFolding> newFoldings = new List<NewFolding>();
			
			Stack<int> startOffsets = new Stack<int>();
			int lastNewLineOffset = 0;
			
			for (int i = 0; i < document.TextLength-2; i++) {
				char c = document.GetCharAt(i);
                char c1 = document.GetCharAt(i+1);
                char c2 = document.GetCharAt(i+2);
                if ((c1 == '(' && (c == 'U' || c == 'O' || c == 'X')) || (c2 == '(' && c1=='N' && (c == 'U' || c == 'O' || c == 'X')))
                {
                    startOffsets.Push(i);
				} else if (c == ')' && startOffsets.Count > 0) {
					int 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;
				}
			}
		    int wrt = document.Text.IndexOf("Netzwerk");
            //try
            {
                while (wrt >= 0)
                {
                    int old = wrt;
                    wrt = document.Text.IndexOf("Netzwerk", wrt + 1);
                    if (wrt > old)
                        newFoldings.Add(new NewFolding(old, wrt - 2));
                    else
                    {
                        newFoldings.Add(new NewFolding(old, document.Text.Length));
                        break;                     
                    }
                }
            }
            //catch (Exception)
            {}


		    newFoldings.Sort((a,b) => a.StartOffset.CompareTo(b.StartOffset));
			return newFoldings;
		}
开发者ID:WaDeSo,项目名称:DotNetSiemensPLCToolBoxLibrary,代码行数:50,代码来源:BraceFoldingStrategy.cs

示例9: CreateNewFoldings

        /// <summary>
        /// Create <see cref="NewFolding"/>s for the specified document.
        /// </summary>
        public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
        {
            List<NewFolding> newFoldings = new List<NewFolding>();

            Stack<int> startOffsets = new Stack<int>();
            int lastNewLineOffset = 0;
            char openingBrace = OpeningBrace;
            char closingBrace = ClosingBrace;

            foreach (var startKeyword in foldingKeywords.Keys)
            {
                int lastKeywordPos = 0;
                int pos = 0;

                while ((pos = document.Text.IndexOf(startKeyword, pos)) > lastKeywordPos)
                {
                    int endOffset = document.Text.IndexOf(foldingKeywords[startKeyword], pos);

                    if (endOffset > pos)
                    {
                        var offset = document.Text.IndexOf("\r\n", pos);
                        var name = document.Text.Substring(pos + 8, offset - (pos + 8));
                        var folding = new NewFolding(pos, endOffset + 10);
                        folding.Name = name;

                        // Add the folding
                        newFoldings.Add(folding);
                    }

                    lastKeywordPos = pos;
                }
            }

            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)
                    {
                        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:peterschen,项目名称:SMAStudio,代码行数:62,代码来源:PowershellFoldingStrategy.cs

示例10: FindEndOfIdentifier

        /// <summary>
        /// Finds the end of the identifier at the given offset.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="offset">The offset.</param>
        /// <returns>
        /// The offset of the last character of the identifier; or -1 if there is no identifier at
        /// the specified offset.
        /// </returns>
        /// <remarks>
        /// <para>
        /// An identifier is a single word consisting of letters, digits, or underscores. An
        /// identifier must start with a letter or underscore.
        /// </para>
        /// <para>
        /// <strong>Important:</strong> This method does not guarantee that the word at
        /// <paramref name="offset"/> is an identifier - it could also be a number instead of an
        /// identifier. To make sure that the current word is really an identifier, you should
        /// search for the start of the identifier and check whether it starts with a letter or
        /// underscore.
        /// </para>
        /// </remarks>
        public static int FindEndOfIdentifier(ITextSource document, int offset)
        {
            if (offset < 0 || offset >= document.TextLength)
                return -1;

            if (!IsIdentifierPart(document.GetCharAt(offset)))
            {
                // Character at offset is does not belong to an identifier.
                return -1;
            }

            // Search forward
            while (offset + 1 < document.TextLength && IsIdentifierPart(document.GetCharAt(offset + 1)))
                ++offset;

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

示例11: NextNewLine

 /// <summary>
 /// Gets the location of the next new line character, or SimpleSegment.Invalid
 /// if none is found.
 /// </summary>
 internal static SimpleSegment NextNewLine(ITextSource text, int offset)
 {
     int textLength = text.TextLength;
     for (int i = offset; i < textLength; i++) {
         switch (text.GetCharAt(i)) {
             case '\r':
                 if (i + 1 < textLength) {
                     if (text.GetCharAt(i + 1) == '\n') {
                         return new SimpleSegment(i, 2);
                     }
                 }
                 goto case '\n';
             case '\n':
                 return new SimpleSegment(i, 1);
         }
     }
     return SimpleSegment.Invalid;
 }
开发者ID:Jaimerh,项目名称:lsystems-csharp-lib,代码行数:22,代码来源:NewLineFinder.cs

示例12: ReadOnlyDocument

		/// <summary>
		/// Creates a new ReadOnlyDocument from the given text source.
		/// </summary>
		public ReadOnlyDocument(ITextSource textSource)
		{
			if (textSource == null)
				throw new ArgumentNullException("textSource");
			// ensure that underlying buffer is immutable
			this.textSource = textSource.CreateSnapshot();
			List<int> lines = new List<int>();
			lines.Add(0);
			int offset = 0;
			int textLength = textSource.TextLength;
			while ((offset = textSource.IndexOfAny(newline, offset, textLength - offset)) >= 0) {
				offset++;
				if (textSource.GetCharAt(offset - 1) == '\r' && offset < textLength && textSource.GetCharAt(offset) == '\n') {
					offset++;
				}
				lines.Add(offset);
			}
			this.lines = lines.ToArray();
		}
开发者ID:Netring,项目名称:ILSpy,代码行数:22,代码来源:ReadOnlyDocument.cs

示例13: CreateNewFoldings

 /// <summary>
 /// Create <see cref="NewFolding"/>s for the specified document.
 /// </summary>
 public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
 {
     Stack<int> startOffsets = new Stack<int>();
     int lastNewLineOffset = 0;
     char openingBrace = this.OpeningBrace;
     char closingBrace = this.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) {
                 yield return new NewFolding(startOffset, i + 1);
             }
         } else if (c == '\n' || c == '\r') {
             lastNewLineOffset = i + 1;
         }
     }
 }
开发者ID:ousttrue,项目名称:EditorSample,代码行数:24,代码来源:BraceFoldingStrategy.cs

示例14: QuickSearchBracketForward

 private static int QuickSearchBracketForward(ITextSource document, int offset, char openBracket,
     char closingBracket)
 {
     var num = 1;
     int result;
     for (var i = offset; i < document.TextLength; i++)
     {
         var charAt = document.GetCharAt(i);
         if (charAt == openBracket)
         {
             num++;
         }
         else
         {
             if (charAt == closingBracket)
             {
                 num--;
                 if (num == 0)
                 {
                     result = i;
                     return result;
                 }
             }
             else
             {
                 if (charAt == '"')
                 {
                     break;
                 }
                 if (charAt == '\'')
                 {
                     break;
                 }
                 if (charAt == '/' && i > 0)
                 {
                     if (document.GetCharAt(i - 1) == '/')
                     {
                         break;
                     }
                 }
                 else
                 {
                     if (charAt == '*' && i > 0)
                     {
                         if (document.GetCharAt(i - 1) == '/')
                         {
                             break;
                         }
                     }
                 }
             }
         }
     }
     result = -1;
     return result;
 }
开发者ID:mookiejones,项目名称:miEditor,代码行数:56,代码来源:MyBracketSearcher.cs

示例15: GetXmlIdentifierBeforeIndex

		public static string GetXmlIdentifierBeforeIndex(ITextSource document, int index)
		{
			if (document == null)
				throw new ArgumentNullException("document");
			if (index < 0 || index > document.TextLength)
				throw new ArgumentOutOfRangeException("index", index, "Value must be between 0 and " + document.TextLength);
			int i = index - 1;
			while (i >= 0 && IsXmlNameChar(document.GetCharAt(i)) && document.GetCharAt(i) != '/')
				i--;
			return document.GetText(i + 1, index - i - 1);
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:11,代码来源:XmlParser.cs


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