Ejemplo n.º 1
0
        // parsing

        #region public static PDFStyleMatcher Parse(string selector)

        public static PDFStyleMatcher Parse(string selector)
        {
            if (string.IsNullOrEmpty(selector))
            {
                return(null);
            }

            selector = selector.Trim();

            if (string.IsNullOrEmpty(selector))
            {
                return(null);
            }

            if (string.Equals("*", selector))
            {
                return(new PDFStyleCatchAllMatcher());
            }

            var each = selector.Split(", ", StringSplitOptions.RemoveEmptyEntries);

            if (each.Length > 1)
            {
                PDFStyleMatcher root = null;

                foreach (var one in each)
                {
                    var all = one.Split(" ", StringSplitOptions.RemoveEmptyEntries);

                    StylePlacement placement = StylePlacement.Any;
                    var            parsed    = ParseSelectorList(all, all.Length - 1, placement);

                    if (null == root)
                    {
                        root = new PDFStyleMatcher(parsed);
                    }
                    else
                    {
                        root = new PDFStyleMultipleMatcher(parsed, root);
                    }
                }
                return(root);
            }
            else
            {
                var all = String.IsNullOrEmpty(selector) ? new string[] { } : selector.Split(" ", StringSplitOptions.RemoveEmptyEntries);

                StylePlacement placement = StylePlacement.Any;
                var            one       = ParseSelectorList(all, all.Length - 1, placement);


                return(new PDFStyleMatcher(one));
            }
        }
Ejemplo n.º 2
0
        public static PDFStyleSelector ParseSelectorList(string[] selector, int index, StylePlacement placement)
        {
            if (selector[index] == ">")
            {
                placement = StylePlacement.DirectParent;
                index--;
            }
            var one = ParseSingleSelector(selector[index]);

            one.Placement = placement;

            if (index > 0)
            {
                one.Ancestor = ParseSelectorList(selector, index - 1, StylePlacement.Any);
            }

            return(one);
        }