コード例 #1
0
        protected override void ProcessByte(byte current)
        {
            // if in segment
            if (PotentialStream.Count >= _startDelimiter.Length)
            {
                PotentialStream.Add(current);
                if (IsAccumulativeMatchComplete(_endDelimiter, current))
                {
                    // end segment
                    // remove delimiters
                    PotentialStream.RemoveRange(0, _startDelimiter.Length);
                    PotentialStream.RemoveRange(PotentialStream.Count - _endDelimiter.Length, _endDelimiter.Length);

                    var replacement = _byteArrayReplacer(PotentialStream.ToArray());

                    MemoryStream.AddRange(replacement);
                    PotentialStream.Clear();
                }
                return;
            }

            // if we match part of seg
            if (IsAccumulativeMatch(_startDelimiter, current))
            {
                PotentialStream.Add(current);
                return;
            }

            // cancel potential if exists
            if (PotentialStream.Any())
            {
                MemoryStream.AddRange(PotentialStream);
                PotentialStream.Clear();
            }

            MemoryStream.Add(current);
        }
コード例 #2
0
        protected override void ProcessByte(byte current)
        {
            // if we match part of seg
            if (IsAccumulativeMatch(_match, current))
            {
                PotentialStream.Add(current);
                if (IsAccumulativeMatchComplete(_match, current))
                {
                    MemoryStream.AddRange(_replace);
                    PotentialStream.Clear();
                }
                return;
            }

            // save potential, or normal
            if (PotentialStream.Any())
            {
                // didnt match, add what we got
                MemoryStream.AddRange(PotentialStream);
                PotentialStream.Clear();
            }

            MemoryStream.Add(current);
        }