Пример #1
0
        /// <summary>
        /// Gets the zero-based index of the first occurrence of the character <paramref name="c"/> in this <see cref="StringSegment"/>.
        /// The search starts at <paramref name="start"/> and examines a specified number of <paramref name="count"/> character positions.
        /// </summary>
        /// <param name="c">The Unicode character to seek.</param>
        /// <param name="start">The zero-based index position at which the search starts. </param>
        /// <param name="count">The number of characters to examine.</param>
        /// <returns>The zero-based index position of <paramref name="c"/> from the beginning of the <see cref="StringSegment"/> if that character is found, or -1 if it is not.</returns>
        public int IndexOf(char c, int start, int count)
        {
            if (start < 0 || Offset + start > Buffer.Length)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
            }

            if (count < 0 || Offset + start + count > Buffer.Length)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count);
            }
            var index = Buffer.IndexOf(c, start + Offset, count);

            if (index != -1)
            {
                return(index - Offset);
            }
            else
            {
                return(index);
            }
        }
Пример #2
0
        public int IndexOf(char c, int start, int count)
        {
            int offset = Offset + start;

            if (!HasValue || start < 0 || (uint)offset > (uint)Buffer.Length)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
            }

            if (count < 0)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count);
            }

            int index = AsSpan().Slice(start, count).IndexOf(c);

            if (index >= 0)
            {
                index += start;
            }

            return(index);
        }
Пример #3
0
        public int IndexOf(char c, int start, int count)
        {
            var offset = Offset + start;

            if (!HasValue || start < 0 || (uint)offset > (uint)Buffer.Length)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
            }

            if (count < 0)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count);
            }

            var index = Buffer.IndexOf(c, offset, count);

            if (index != -1)
            {
                index -= Offset;
            }

            return(index);
        }