Exemple #1
0
        // ministream!

        public void SendLine(string line)
        {
            if (dest == null)
            {
                throw new Exception("GrepStream got line without dest being set.");
            }

            if (!Invert)
            {
                if (AndMode)
                {
                    for (int i = 0; i < regexes.Length; i++)
                    {
                        if (!regexes[i].IsMatch(line))
                        {
                            return;
                        }
                    }

                    dest.SendLine(line);
                }
                else
                {
                    for (int i = 0; i < regexes.Length; i++)
                    {
                        if (regexes[i].IsMatch(line))
                        {
                            dest.SendLine(line);
                            return;
                        }
                    }
                }
            }
            else
            {
                if (AndMode)
                {
                    for (int i = 0; i < regexes.Length; i++)
                    {
                        if (!regexes[i].IsMatch(line))
                        {
                            dest.SendLine(line);
                            return;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < regexes.Length; i++)
                    {
                        if (regexes[i].IsMatch(line))
                        {
                            return;
                        }
                    }

                    dest.SendLine(line);
                }
            }
        }
Exemple #2
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            // maybe replace this check with a try/catch, since I
            // assume we have to decode the buffer twice right now.

            int n = decoder.GetCharCount(buffer, offset, count);

            if (n > buf.Length)
            {
                buf = new char[n];
            }

            n = decoder.GetChars(buffer, offset, count, buf, 0);

            for (int i = 0; i < n; i++)
            {
                if (buf[i] == '\n')
                {
                    sink.SendLine(sb.ToString());
                    sb.Length = 0;
                }
                else if (buf[i] == '\r')
                {
                    // anything wrong with ignoring these?
                    // ... didn't think so.
                }
                else
                {
                    sb.Append(buf[i]);
                }
            }
        }
Exemple #3
0
		// static
	       
		public static void DrainStream (StreamReader reader, IMiniStreamSink sink) {
			if (reader == null)
				throw new ArgumentNullException ("reader");
			if (sink == null)
				throw new ArgumentNullException ("sink");

			string line;

			while ((line = reader.ReadLine ()) != null)
				sink.SendLine (line);

			sink.StreamDone ();
		}
Exemple #4
0
        // ministream!

        public void SendLine(string line)
        {
            if (dest == null)
            {
                throw new Exception("SedStream got line without dest being set.");
            }

            for (int i = 0; i < regexes.Count; i++)
            {
                Regex  rex  = (Regex)regexes[i];
                string repl = (string)repls[i];

                line = rex.Replace(line, repl);
            }

            dest.SendLine(line);
        }
Exemple #5
0
        // static

        public static void DrainStream(StreamReader reader, IMiniStreamSink sink)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (sink == null)
            {
                throw new ArgumentNullException("sink");
            }

            string line;

            while ((line = reader.ReadLine()) != null)
            {
                sink.SendLine(line);
            }

            sink.StreamDone();
        }