Esempio n. 1
0
        // note: in the future, we might allow for more "font" data - at that point, I'll think about the syntax
        //
        // at this point, we allow a simple "color" line:
        // color fg [bg]
        private static filter_line parse_font(string line)
        {
            Debug.Assert(line.StartsWith("color"));
            string[] colors = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

            filter_line fi = new filter_line {
                part = part_type.font
            };

            if (colors.Length >= 2)
            {
                fi.fi.fg = util.str_to_color(colors[1]);
            }
            if (colors.Length >= 3)
            {
                fi.fi.bg = util.str_to_color(colors[2]);
            }
            return(fi);
        }
Esempio n. 2
0
        public filter_row(string text)
        {
            List <filter_line> lines     = new List <filter_line>();
            List <addition>    additions = new List <addition>();

            foreach (string line in text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
            {
                filter_line item = filter_line.parse(line);
                if (item != null)
                {
                    lines.Add(item);
                }
                addition add = addition.parse(line);
                if (add != null)
                {
                    additions.Add(add);
                }
            }
            init(lines, additions);
        }
Esempio n. 3
0
 protected bool Equals(filter_line other)
 {
     return(part == other.part && comparison == other.comparison && string.Equals(text, other.text));// && Equals(fi, other.fi);
 }
Esempio n. 4
0
        // tries to parse a line - if it fails, it will return null
        private static filter_line parse_impl(string line)
        {
            line = line.Trim();
            if (line.StartsWith("#"))
            {
                // allow comments
                return(null);
            }

            if (line.StartsWith("font") || line.StartsWith("color"))
            {
                return(parse_font(line));
            }

            if (line == "case-insensitive")
            {
                return new filter_line {
                           part = part_type.case_sensitive_info, case_sensitive = false
                }
            }
            ;

            if (!line.StartsWith("$"))
            {
                return(null);
            }

            string[] words = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

            // Syntax:
            // $ColumnName Comparison Text
            if (words.Length < 3)
            {
                // we need at least $c compare word(s)
                return(null);
            }

            filter_line fi = new filter_line();

            switch (words[0])
            {
            case "$date": fi.part = part_type.date; break;

            case "$time": fi.part = part_type.time; break;

            case "$level": fi.part = part_type.level; break;

            case "$file": fi.part = part_type.file; break;

            case "$func": fi.part = part_type.func; break;

            case "$msg": fi.part = part_type.message; break;

            case "$class": fi.part = part_type.class_; break;

            case "$ctx1": fi.part = part_type.ctx1; break;

            case "$ctx2": fi.part = part_type.ctx2; break;

            case "$ctx3": fi.part = part_type.ctx3; break;

            case "$thread": fi.part = part_type.thread; break;

            default:
                return(null);
            }

            switch (words[1].ToLower())
            {
            case "!=": fi.comparison = comparison_type.not_equal; break;

            case "==":
            case "=":
                fi.comparison = comparison_type.equal; break;

            case "+":
            case "startswith":
                fi.comparison = comparison_type.starts_with; break;

            case "-":
            case "!startswith":
                fi.comparison = comparison_type.does_not_start_with; break;

            case "++":
            case "contains":
                fi.comparison = comparison_type.contains; break;

            case "--":
            case "!contains":
                fi.comparison = comparison_type.does_not_contain; break;

            case "containsany":
            case "any":
                fi.comparison = comparison_type.contains_any; break;

            case "containsnone":
            case "none":
                fi.comparison = comparison_type.contains_none;
                break;

            default:
                return(null);
            }

            // take the rest of the text
            int compare_idx = line.IndexOf(words[1]);

            line = line.Substring(compare_idx + words[1].Length).Trim();
            if (fi.comparison == comparison_type.contains_any || fi.comparison == comparison_type.contains_none)
            {
                fi.words    = line.Split('|');
                fi.lo_words = fi.words.Select(w => w.ToLower()).ToArray();
            }
            fi.text    = line;
            fi.lo_text = line.ToLower();

            return(fi);
        }
Esempio n. 5
0
        // tries to parse a line - if it fails, it will return null
        private static filter_line parse_impl(string line)
        {
            line = line.Trim();
            if (line.StartsWith("#"))
                // allow comments
                return null;

            if (line.StartsWith("font") || line.StartsWith("color"))
                return parse_font(line);

            if (line == "case-insensitive")
                return new filter_line {part = part_type.case_sensitive_info, case_sensitive = false };

            if ( !line.StartsWith("$"))
                return null;

            string[] words = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

            // Syntax:
            // $ColumnName Comparison Text
            if (words.Length < 3)
                // we need at least $c compare word(s)
                return null;

            filter_line fi = new filter_line();
            switch ( words[0]) {
            case "$date": fi.part = part_type.date; break;
            case "$time": fi.part = part_type.time; break;
            case "$level": fi.part = part_type.level; break;
            case "$file": fi.part = part_type.file; break;
            case "$func": fi.part = part_type.func; break;
            case "$msg": fi.part = part_type.message; break;
            case "$class": fi.part = part_type.class_; break;

            case "$ctx1": fi.part = part_type.ctx1; break;
            case "$ctx2": fi.part = part_type.ctx2; break;
            case "$ctx3": fi.part = part_type.ctx3; break;

            case "$thread": fi.part = part_type.thread; break;
            default:
                return null;
            }

            switch ( words[1].ToLower() ) {
            case "!=": fi.comparison = comparison_type.not_equal; break;

            case "==":
            case "=":
                fi.comparison = comparison_type.equal; break;

            case "+":
            case "startswith":
                fi.comparison = comparison_type.starts_with; break;

            case "-":
            case "!startswith":
                fi.comparison = comparison_type.does_not_start_with; break;

            case "++":
            case "contains":
                fi.comparison = comparison_type.contains; break;

            case "--":
            case "!contains":
                fi.comparison = comparison_type.does_not_contain; break;

            case "containsany":
            case "any":
                fi.comparison = comparison_type.contains_any; break;

            case "containsnone":
            case "none":
                fi.comparison = comparison_type.contains_none;
                break;
            default:
                return null;
            }

            // take the rest of the text
            int compare_idx = line.IndexOf(words[1]);
            line = line.Substring(compare_idx + words[1].Length).Trim();
            if (fi.comparison == comparison_type.contains_any || fi.comparison == comparison_type.contains_none) {
                fi.words = line.Split('|');
                fi.lo_words = fi.words.Select(w => w.ToLower()).ToArray();
            }
            fi.text = line;
            fi.lo_text = line.ToLower();

            return fi;
        }
Esempio n. 6
0
        // note: in the future, we might allow for more "font" data - at that point, I'll think about the syntax
        //
        // at this point, we allow a simple "color" line:
        // color fg [bg]
        private static filter_line parse_font(string line)
        {
            Debug.Assert(line.StartsWith("color"));
            string[] colors = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

            filter_line fi = new filter_line { part = part_type.font };
            if (colors.Length >= 2)
                fi.fi.fg = util.str_to_color(colors[1]);
            if (colors.Length >= 3)
                fi.fi.bg = util.str_to_color(colors[2]);
            return fi;
        }
Esempio n. 7
0
 protected bool Equals(filter_line other)
 {
     return part == other.part && comparison == other.comparison && string.Equals(text, other.text);// && Equals(fi, other.fi);
 }