Пример #1
0
        /// <summary>
        /// Advances the reader and reads until a substring specified by <paramref name="indicator" /> is encountered.
        /// The reader's position after executing this method depends on the <paramref name="options" />.
        /// </summary>
        /// <param name="indicator">The reader stops when an occurrence of this string instance 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 indicator, ReadOptions options = ReadOptions.StopAfterKey | ReadOptions.DiscardKey)
        {
            var idx = options.HasFlag(ReadOptions.InLine) ? UnderlyingString.InlineIndexOf(indicator, CurrentPosition, EndPosition - CurrentPosition, ComparisonType) :
                      UnderlyingString.IndexOf(indicator, CurrentPosition, EndPosition - CurrentPosition, ComparisonType);

            return(_innerReadTo(idx, indicator.Length, options));
        }
Пример #2
0
        /// <summary>
        /// Advances the reader to the beginning of the next line. If the current line is the last line, the reader advances to the end of the underlying string.
        /// </summary>
        /// <param name="skipBlankLines"><c>true</c> to indicate the reader should skip all blank lines it encounters before a non-empty line is reached.
        /// If no non-empty line is found, the reader will advance to the end of the underlying string.
        /// </param>
        public void SeekToNextLine(bool skipBlankLines = true)
        {
            var newline = Environment.NewLine;
            var idx     = UnderlyingString.IndexOf(newline, CurrentPosition, EndPosition - CurrentPosition, ComparisonType);

            if (idx == -1)
            {
                CurrentPosition = EndPosition;
            }
            else
            {
                CurrentPosition = idx + newline.Length;
            }

            while (UnderlyingString.StartsWith(CurrentPosition, newline))
            {
                CurrentPosition += newline.Length;
                if (CurrentPosition > EndPosition)
                {
                    CurrentPosition = EndPosition;
                    break;
                }
            }
        }
Пример #3
0
 public bool StartsWith(string str) => (str.Length <= Length) && UnderlyingString.IndexOf(str, Index, str.Length) == Index;
Пример #4
0
        /// <summary>
        /// Advances the reader until a character satisfying <paramref name="predicate"/> is encountered.
        /// </summary>
        /// <param name="predicate">A method to test each character.</param>
        /// <param name="skipKeychar">
        /// <c>true</c> if the reader stops at the position next to the first encountered character satisfying the <paramref name="predicate"/>;
        /// <c>false</c> if the reader stops at the position of such a character.
        /// </param>
        /// <param name="seekToEndIfKeycharNotFound">
        /// <c>true</c> if the reader should advance to the end of the reading scope if no character satisfying the <paramref name="predicate"/> is found;
        /// <c>false</c> if the reader should stand still if such a character cannot be found.
        /// </param>
        /// <returns><c>true</c> if the reader has advanced to a character satisfying the specified <paramref name="predicate"/>; <c>false</c> if no such character is found.</returns>
        public void SeekTo(Func <char, bool> predicate, bool skipKeychar = true, bool seekToEndIfKeycharNotFound = true)
        {
            var idx = UnderlyingString.IndexOf(predicate, CurrentPosition);

            _innerSeekTo(idx, 1, skipKeychar, seekToEndIfKeycharNotFound);
        }
Пример #5
0
        /// <summary>
        /// Advances the reader until an occurrence of the specified character is encountered.
        /// </summary>
        /// <param name="keychar">The reader stops when this character is encountered.</param>
        /// <param name="skipKeychar">
        /// <c>true</c> if the reader stops at the position next to the encountered <paramref name="keychar"/>;
        /// <c>false</c> if the reader stops at the position of the encountered <paramref name="keychar"/>.
        /// </param>
        /// <param name="seekToEndIfKeycharNotFound">
        /// <c>true</c> if the reader should advance to the end of the reading scope if <paramref name="keychar"/> is not 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 <paramref name="keychar" /> is found and the reader has advanced to that character; <c>false</c> if no such character is found.
        /// </returns>
        public bool SeekTo(char keychar, bool skipKeychar = true, bool seekToEndIfKeycharNotFound = true)
        {
            var keycharPos = UnderlyingString.IndexOf(keychar, CurrentPosition, EndPosition - CurrentPosition);

            return(_innerSeekTo(keycharPos, 1, skipKeychar, seekToEndIfKeycharNotFound));
        }
Пример #6
0
        //TODO this file is not complete

        #region SeekTo A Keyword

        /// <summary>
        /// Advances the reader until an occurrence of the specified string is encountered.
        /// </summary>
        /// <param name="keyword">The reader stops when this string 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 <paramref name="keyword"/> is not 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 <paramref name="keyword" /> is encountered and the reader is advanced to that keyword; <c>false</c> if no such keyword is found.
        /// </returns>
        public bool SeekTo(string keyword, bool skipKeyword = true, bool seekToEndIfKeywordNotFound = true)
        {
            var keywordPos = UnderlyingString.IndexOf(keyword, CurrentPosition, EndPosition - CurrentPosition);

            return(_innerSeekTo(keywordPos, keyword.Length, skipKeyword, seekToEndIfKeywordNotFound));
        }