Exemplo n.º 1
0
        /// <summary>
        /// Advances the reader until an occurrence of any of the specified characters is encountered outside quotes.
        /// </summary>
        /// <param name="keychars">The reader stops when any of these characters is encountered.</param>
        /// <param name="leftQuotes">
        /// The left quotes that work together with <paramref name="rightQuotes"/> to escape the <paramref name="predicate"/>.
        /// A left quote of an index of this array corresponds to the right quote of that index of the array specified by <paramref name="rightQuotes" />.
        /// The reader will not stop when a character satisfying the <paramref name="predicate"/> is encountered inside a pair of quotes.
        /// </param>
        /// <param name="rightQuotes">
        /// The left quotes that work together with <paramref name="leftQuotes"/> to escape the <paramref name="predicate"/>.
        /// A right quote of an index of this array corresponds to the left quote of that index of the array specified by <paramref name="leftQuotes" />.
        /// The reader will not stop when a character satisfying the <paramref name="predicate"/> is encountered inside a pair of quotes.
        /// </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>
        /// '\0' if none of <paramref name="keychars"/> is found; ohterwise, the encountered keychar.
        /// </returns>
        public char SeekTo(char[] keychars, char[] leftQuotes, char[] rightQuotes, bool skipKeychar = true, bool seekToEndIfKeycharNotFound = true)
        {
            var keycharPos = UnderlyingString.IndexOfAnyWithQuotes(keychars, CurrentPosition, EndPosition - CurrentPosition, leftQuotes, rightQuotes);

            if (keycharPos == -1)
            {
                _innerSeekTo(-1, 0, skipKeychar, seekToEndIfKeycharNotFound);
                return('\0');
            }
            else
            {
                _innerSeekTo(keycharPos, 1, skipKeychar, seekToEndIfKeycharNotFound);
                return(UnderlyingString[keycharPos]);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Advances the reader until an occurrence of any of the specified <paramref name="keywords"/> is encountered outside quotes.
        /// </summary>
        /// <param name="keywords">The reader stops when any of these strings is encountered.</param>
        /// <param name="primaryLeftQuotes">Specifies an array of Unicode characters as the primary left quotes. A left quote of an index of this array corresponds to the right quote of that index of the array specified by <paramref name="primaryRightQuotes" />.</param>
        /// <param name="primaryRightQuotes">Specifies an array of Unicode characters as the primary right quotes. A right quote of an index of this array corresponds to the left quote of that index of the array specified by <paramref name="primaryLeftQuotes" />.</param>
        /// <param name="secondaryLeftQuotes">Specifies an array of Unicode characters as the secondary left quotes. A left quote of an index of this array corresponds to the right quote of that index of the array specified by <paramref name="secondaryRightQuotes" />. Secondary quotes are escaped when they are inside a pair of primary quotes.</param>
        /// <param name="secondaryRightQuotes">Specifies an array of Unicode characters as the secondary right quotes. A right quote of an index of this array corresponds to the left quote of that index of the array specified by <paramref name="secondaryLeftQuotes" />. Secondary quotes are escaped when they are inside a pair of primary quotes.</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>
        /// THe index of the encountered keyword in the <paramref name="keywords" />, if any ouccrrance of the <paramref name="keywords"/> is encountered outside quotes and the reader has advanced to that keyword;
        /// -1 if no keyword is encountered.
        /// </returns>
        public int SeekTo(string[] keywords, char[] primaryLeftQuotes, char[] primaryRightQuotes, char[] secondaryLeftQuotes, char[] secondaryRightQuotes, bool skipKeyword = true, bool seekToEndIfKeywordNotFound = true)
        {
            var keywordSearchResult = UnderlyingString.IndexOfAnyWithQuotes(keywords, CurrentPosition, EndPosition - CurrentPosition, primaryLeftQuotes, primaryRightQuotes, secondaryLeftQuotes, secondaryRightQuotes, ComparisonType);

            if (keywordSearchResult == null)
            {
                _innerSeekTo(-1, 0, skipKeyword, seekToEndIfKeywordNotFound);
                return(-1);
            }
            else
            {
                _innerSeekTo(keywordSearchResult.Position, keywordSearchResult.Value.Length, skipKeyword, seekToEndIfKeywordNotFound);
                return(keywordSearchResult.HitIndex);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Advances the reader and reads until any substring specified in <paramref name="indicators" /> is encountered outside quotes.
        /// 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="leftQuotes">
        /// An array of Unicode characters as the left quotes.
        /// A left quote of an index of this array corresponds to the right quote of that index of the array specified by <paramref name="rightQuotes" />.
        /// The reader will not stop when an <paramref name="indicator" /> is encountered inside a pair of quotes.</param>
        /// <param name="rightQuotes">
        /// An array of Unicode characters as the right quotes.
        /// A right quote of an index of this array corresponds to the left quote of that index of the array specified by <paramref name="leftQuotes" />.
        /// The reader will not stop when an <paramref name="indicator" /> is encountered inside a pair of quotes.</param>
        /// <param name="options">Specifies the reading options.</param>
        /// <returns>
        /// A substring read from the underlying string instance.
        /// </returns>
        public string ReadTo(string[] indicators, char[] leftQuotes, char[] rightQuotes, ReadOptions options = ReadOptions.StopAfterKey | ReadOptions.DiscardKey)
        {
            var idx = UnderlyingString.IndexOfAnyWithQuotes(indicators, CurrentPosition, EndPosition - CurrentPosition, leftQuotes, rightQuotes, ComparisonType);;

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