/// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <param name="currentResult"></param>
        /// <returns></returns>
        protected override MatchTerminatorStatus Validate(TSource item, MatchTerminatorResult currentResult)
        {
            bool result = item.Equals(CurrentTerminator.Current);

            if (!result)
            {
                return(MatchTerminatorStatus.Fail);
            }

            return(CurrentTerminator.MoveNext() ?
                   MatchTerminatorStatus.SuccessPartial : MatchTerminatorStatus.Success);
        }
            /// <summary>
            ///
            /// </summary>
            /// <param name="item"></param>
            /// <param name="currentResult"></param>
            /// <returns></returns>
            protected override MatchTerminatorStatus Validate(byte item, MatchTerminatorResult currentResult)
            {
                bool result = item.Equals(CurrentTerminator.Current);

                if (!result)
                {
                    return(MatchTerminatorStatus.Fail);
                }

                try
                {
                    return(CurrentTerminator.MoveNext() ?
                           MatchTerminatorStatus.SuccessPartial :
                           (currentResult.Length == 1 ? MatchTerminatorStatus.SuccessReset : MatchTerminatorStatus.Success));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <param name="currentResult"></param>
        /// <returns></returns>
        protected override MatchTerminatorStatus Validate(TSource item, MatchTerminatorResult currentResult)
        {
            bool result = Terminator.Contains(t => t.Equals(item));

            return(result ? MatchTerminatorStatus.SuccessPartial : MatchTerminatorStatus.SuccessNoLength);
        }
Beispiel #4
0
        /// <summary>
        /// The predicate used to match the source and the match collection. By the default the equals parameter is passed.
        /// </summary>
        public virtual MatchTerminatorResult Match(IEnumerator <TSource> sourceEnum, Queue <TSource> slidingWindow, long length)
        {
            MatchTerminatorResult result = new MatchTerminatorResult();

            result.Length = 0;

            do
            {
                TSource item;
                MatchTerminatorStatus status = MatchTerminatorStatus.Exception;

                try
                {
                    item   = sourceEnum.Current;
                    status = mPredicate(item, result);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                try
                {
                    switch (status)
                    {
                    case MatchTerminatorStatus.SuccessPartial:
                        slidingWindow.Enqueue(item);
                        result.Status = MatchTerminatorStatus.SuccessPartial;
                        break;

                    case MatchTerminatorStatus.Success:
                    case MatchTerminatorStatus.SuccessReset:
                    case MatchTerminatorStatus.SuccessNoLength:
                    case MatchTerminatorStatus.SuccessNoLengthReset:
                    case MatchTerminatorStatus.Fail:
                    case MatchTerminatorStatus.FailNoLength:
                        if (CanScan && status == MatchTerminatorStatus.Fail &&
                            result.Status == MatchTerminatorStatus.NotSet)
                        {
                            break;
                        }

                        result.Status = status;
                        if (((status & MatchTerminatorStatus.NoLength) > 0))
                        {
                            result.CanContinue = true;
                        }
                        else
                        {
                            result.Length++;
                            slidingWindow.Enqueue(item);
                            result.CanContinue = sourceEnum.MoveNext();
                        }

                        //Check whether we have a termination condition.
                        if ((result.Status & MatchTerminatorStatus.Success) > 0)
                        {
                            result.IsTerminator = mPredicateTerminator(result, slidingWindow, item, length);
                        }


                        return(result);

                    case MatchTerminatorStatus.NotSet:
                        break;

                    default:
                        //This shouldn't happen
                        break;
                    }
                    result.Length++;
                }
                catch (Exception ex)
                {
                    result.Status = MatchTerminatorStatus.Exception;
                }
            }while (sourceEnum.MoveNext());

            result.CanContinue = false;


            return(result);
        }
Beispiel #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="result"></param>
 /// <param name="terminator"></param>
 /// <param name="currentItem"></param>
 /// <param name="length"></param>
 /// <returns></returns>
 protected virtual bool ValidateTerminator(MatchTerminatorResult result, Queue <TSource> terminator, TSource currentItem, long length)
 {
     return(false);
 }
Beispiel #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="item"></param>
 /// <param name="currentResult"></param>
 /// <returns></returns>
 protected virtual MatchTerminatorStatus Validate(TSource item, MatchTerminatorResult currentResult)
 {
     throw new NotImplementedException("Validate is not implemented.");
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="result"></param>
 /// <param name="terminator"></param>
 /// <param name="currentItem"></param>
 /// <param name="length"></param>
 /// <returns></returns>
 protected override bool ValidateTerminator(MatchTerminatorResult result, Queue <TSource> terminator, TSource currentItem, long length)
 {
     return(result.Length > 0);
 }