AvalonStudio.TextEditor.Utils.CharRope.IndexOfAny C# (CSharp) 메소드

IndexOfAny() 공개 정적인 메소드

Gets the index of the first occurrence of any element in the specified array.
public static IndexOfAny ( this rope, char anyOf, int startIndex, int length ) : int
rope this The target rope.
anyOf char Array of characters being searched.
startIndex int Start index of the search.
length int Length of the area to search.
리턴 int
		public static int IndexOfAny(this Rope<char> rope, char[] anyOf, int startIndex, int length)
		{
			if (rope == null)
				throw new ArgumentNullException("rope");
			if (anyOf == null)
				throw new ArgumentNullException("anyOf");
			rope.VerifyRange(startIndex, length);

			while (length > 0)
			{
				var entry = rope.FindNodeUsingCache(startIndex).PeekOrDefault();
				var contents = entry.node.contents;
				var startWithinNode = startIndex - entry.nodeStartIndex;
				var nodeLength = Math.Min(entry.node.length, startWithinNode + length);
				for (var i = startIndex - entry.nodeStartIndex; i < nodeLength; i++)
				{
					var element = contents[i];
					foreach (var needle in anyOf)
					{
						if (element == needle)
							return entry.nodeStartIndex + i;
					}
				}
				length -= nodeLength - startWithinNode;
				startIndex = entry.nodeStartIndex + nodeLength;
			}
			return -1;
		}