/// <summary>
        /// Advances the reader until an occurrence of any of the specified characters is encountered.
        /// </summary>
        /// <param name="keychars">The reader stops when any of these characters is encountered.</param>
        /// <param name="skipKeychar">
        /// <c>true</c> if the reader stops at the position next to the encountered keychar.
        /// <c>false</c> if the reader stops at the position of the encountered keychar.
        /// </param>
        /// <param name="seekToEndIfKeycharNotFound">
        /// <c>true</c> if the reader should advance to the end of the reading scope if none of <paramref name="keychars"/> is found.
        /// <c>false</c> if the reader should stand still if such a character cannot be found.
        /// </param>
        /// <returns>
        /// <c>true</c> if an occurrence of any of the <paramref name="keywords" /> is found and the reader is advanced to that character;
        /// <c>false</c> if no such character is found.
        /// </returns>
        public int SeekTo(char[] keychars, bool skipKeychar = true, bool seekToEndIfKeycharNotFound = true)
        {
            var keycharPos = UnderlyingString.IndexOfAny(keychars, CurrentPosition, EndPosition - CurrentPosition, out var keycharIndex);

            _innerSeekTo(keycharPos, 1, skipKeychar, seekToEndIfKeycharNotFound);
            return(keycharIndex);
        }
示例#2
0
        /// <summary>
        /// Advances the reader until an occurrence of any of the specified strings is encountered.
        /// </summary>
        /// <param name="keywords">The reader stops when any of these strings is encountered.</param>
        /// <param name="skipKeyword">
        /// <c>true</c> if the reader stops at the position next to the last character of the encountered keyword.
        /// <c>false</c> if the reader stops at the position of the first character of the encountered keyword.
        /// </param>
        /// <param name="seekToEndIfKeywordNotFound">
        /// <c>true</c> if the reader should advance to the end of the reading scope if none of <paramref name="keywords"/> is found.
        /// <c>false</c> if the reader should stand still if such a keyword cannot be found.
        /// </param>
        /// <returns>
        /// <c>true</c> if an occurrence of any of the <paramref name="keywords" /> is found and the reader is advanced to that keyword;
        /// <c>false</c> if no such keyword is found.
        /// </returns>
        public int SeekTo(string[] keywords, bool skipKeyword = true, bool seekToEndIfKeywordNotFound = true)
        {
            var keywordSearchResult = UnderlyingString.IndexOfAny(keywords, CurrentPosition, EndPosition - CurrentPosition);

            if (keywordSearchResult == null)
            {
                _innerSeekTo(-1, 0, skipKeyword, seekToEndIfKeywordNotFound);
                return(-1);
            }
            else
            {
                _innerSeekTo(keywordSearchResult.Position, keywordSearchResult.Value.Length, skipKeyword, seekToEndIfKeywordNotFound);
                return(keywordSearchResult.HitIndex);
            }
        }
        /// <summary>
        /// Advances the reader and reads until any substring specified in <paramref name="indicators"/> is encountered.
        /// The reader's position after executing this method depends on the <paramref name="options"/>.
        /// </summary>
        /// <param name="indicators">The reader stops an occurrence of this string instances is encountered.</param>
        /// <param name="options">Specifies the reading options.</param>
        /// <returns>A substring read from the underlying string instance.</returns>
        public string ReadTo(string[] indicators, ReadOptions options = ReadOptions.StopAfterKey | ReadOptions.DiscardKey)
        {
            var idx = UnderlyingString.IndexOfAny(indicators, CurrentPosition, EndPosition - CurrentPosition, ComparisonType);

            return(_innerReadTo(idx.Position, idx.Value.Length, options));
        }