Пример #1
0
        /// <summary>
        /// Searches the last segment.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        public int SearchLastSegment(SearchMarkState <T> state)
        {
            if (m_Segments.Count <= 0)
            {
                return(-1);
            }

            var lastSegment = m_Segments[m_Segments.Count - 1];

            if (lastSegment == null)
            {
                return(-1);
            }

            var result = lastSegment.Array.SearchMark(lastSegment.Offset, lastSegment.Count, state.Mark);

            if (!result.HasValue)
            {
                return(-1);
            }

            if (result.Value > 0)
            {
                state.Matched = 0;
                return(result.Value - lastSegment.Offset + lastSegment.From);
            }

            state.Matched = 0 - result.Value;
            return(-1);
        }
Пример #2
0
        /// <summary>
        /// Searches the mark from source.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">The source.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="length">The length.</param>
        /// <param name="searchState">State of the search.</param>
        /// <param name="parsedLength">Length of the parsed.</param>
        /// <returns></returns>
        public static int SearchMark <T>(this IList <T> source, int offset, int length, SearchMarkState <T> searchState, out int parsedLength)
            where T : IEquatable <T>
        {
            int?result = source.SearchMark(offset, length, searchState.Mark, searchState.Matched, out parsedLength);

            if (!result.HasValue)
            {
                searchState.Matched = 0;
                return(-1);
            }

            if (result.Value < 0)
            {
                searchState.Matched = 0 - result.Value;
                return(-1);
            }

            searchState.Matched = 0;
            return(result.Value);
        }
Пример #3
0
        /// <summary>
        /// Searches the mark from source.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">The source.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="length">The length.</param>
        /// <param name="searchState">State of the search.</param>
        /// <returns></returns>
        public static int SearchMark <T>(this IList <T> source, int offset, int length, SearchMarkState <T> searchState)
            where T : IEquatable <T>
        {
            var parsedLen = 0;

            return(SearchMark(source, offset, length, searchState, out parsedLen));
        }
Пример #4
0
 /// <summary>
 /// Searches the mark from source.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source">The source.</param>
 /// <param name="offset">The offset.</param>
 /// <param name="length">The length.</param>
 /// <param name="searchState">State of the search.</param>
 /// <returns></returns>
 public static int SearchMark <T>(this IList <T> source, int offset, int length, SearchMarkState <T> searchState) where T : IEquatable <T>
 => SearchMark(source, offset, length, searchState, out int parsedLen);