public PDFStyleClassSelector(string name, PDFStyleClassSelector and)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            this.ClassName = name;
            this.AndClass  = and;
        }
Пример #2
0
        public static PDFStyleSelector ParseSingleSelector(string selector)
        {
            string appliedType = null;
            PDFStyleClassSelector appliedClass = null;
            string appliedId = null;

            ParsingType pt = ParsingType.Type; // no selector

            StringBuilder sb = new StringBuilder();

            foreach (var c in selector)
            {
                if (c == '#')
                {
                    if (sb.Length > 0)
                    {
                        switch (pt)
                        {
                        case ParsingType.Type:
                            appliedType = sb.ToString();
                            break;

                        case ParsingType.Class:
                            appliedClass = new PDFStyleClassSelector(sb.ToString(), appliedClass);
                            break;

                        case ParsingType.Id:
                            appliedId = sb.ToString();
                            break;

                        default:

                            break;
                        }
                        sb.Clear();
                    }
                    pt = ParsingType.Id;
                }
                else if (c == '.')
                {
                    if (sb.Length > 0)
                    {
                        switch (pt)
                        {
                        case ParsingType.Type:
                            appliedType = sb.ToString();
                            break;

                        case ParsingType.Class:
                            appliedClass = new PDFStyleClassSelector(sb.ToString(), appliedClass);
                            break;

                        case ParsingType.Id:
                            appliedId = sb.ToString();
                            break;

                        default:

                            break;
                        }
                        sb.Clear();
                    }
                    pt = ParsingType.Class;
                }
                else
                {
                    sb.Append(c);
                }
            }
            if (sb.Length > 0)
            {
                switch (pt)
                {
                case ParsingType.Type:
                    appliedType = sb.ToString();
                    break;

                case ParsingType.Class:
                    appliedClass = new PDFStyleClassSelector(sb.ToString(), appliedClass);;
                    break;

                case ParsingType.Id:
                    appliedId = sb.ToString();
                    break;

                default:

                    break;
                }
                sb.Clear();
            }
            return(new PDFStyleSelector()
            {
                AppliedClass = appliedClass, AppliedID = appliedId, AppliedElement = appliedType
            });
        }
Пример #3
0
        public static PDFStyleSelector ParseSingleSelector(string selector, StringBuilder buffer)
        {
            string appliedType = null;
            PDFStyleClassSelector appliedClass = null;
            string appliedId = null;

            int         stateIndex        = -1;
            ParsingType statePreviousType = ParsingType.Type;

            ComponentState appliedState = ComponentState.Normal;

            ParsingType pt = ParsingType.Type; // no selector

            StringBuilder sb = buffer;

            sb.Clear();

            for (var currIndex = 0; currIndex < selector.Length; currIndex++)
            {
                char c = selector[currIndex];

                if (c == '#')
                {
                    if (sb.Length > 0)
                    {
                        switch (pt)
                        {
                        case ParsingType.Type:
                            appliedType = sb.ToString();
                            break;

                        case ParsingType.Class:
                            appliedClass = new PDFStyleClassSelector(sb.ToString(), appliedClass);
                            break;

                        case ParsingType.Id:
                            appliedId = sb.ToString();
                            break;

                        default:

                            break;
                        }
                        sb.Clear();
                    }
                    pt = ParsingType.Id;
                }
                else if (c == '.')
                {
                    if (sb.Length > 0)
                    {
                        switch (pt)
                        {
                        case ParsingType.Type:
                            appliedType = sb.ToString();
                            break;

                        case ParsingType.Class:
                            appliedClass = new PDFStyleClassSelector(sb.ToString(), appliedClass);
                            break;

                        case ParsingType.Id:
                            appliedId = sb.ToString();
                            break;

                        default:

                            break;
                        }
                        sb.Clear();
                    }
                    pt = ParsingType.Class;
                }
                else
                {
                    if (c == ':')
                    {
                        stateIndex        = currIndex;
                        statePreviousType = pt;
                    }
                    sb.Append(c);
                }
            }
            //At the end of the string
            if (sb.Length > 0)
            {
                switch (pt)
                {
                case ParsingType.Type:
                    appliedType = sb.ToString();
                    break;

                case ParsingType.Class:
                    appliedClass = new PDFStyleClassSelector(sb.ToString(), appliedClass);;
                    break;

                case ParsingType.Id:
                    appliedId = sb.ToString();
                    break;

                default:

                    break;
                }
                sb.Clear();
            }

            if (stateIndex >= 0)
            {
                //TODO: Check for state
                if (stateIndex == 0 && appliedType == ":root")
                {
                }
            }

            return(new PDFStyleSelector()
            {
                AppliedClass = appliedClass, AppliedID = appliedId, AppliedElement = appliedType, AppliedState = appliedState
            });
        }