Linked list of style properties (c) 1998-2000 (W3C) MIT, INRIA, Keio University See Tidy.cs for the copyright notice. Derived from HTML Tidy Release 4 Aug 2000
Example #1
0
        private StyleProp InsertProperty(StyleProp props, string name, string val)
        {
            StyleProp prop;

            StyleProp prev = null;
            StyleProp first = props;

            while (props != null)
            {
                int cmp = String.Compare(props.Name, name, StringComparison.Ordinal);
                if (cmp == 0)
                {
                    /* this property is already defined, ignore new value */
                    return first;
                }
                if (cmp > 0)
                {
                    // props.name > name
                    /* insert before this */

                    prop = new StyleProp(name, val, props);

                    if (prev != null)
                    {
                        prev.Next = prop;
                    }
                    else
                    {
                        first = prop;
                    }

                    return first;
                }

                prev = props;
                props = props.Next;
            }

            prop = new StyleProp(name, val);
            if (prev != null)
            {
                prev.Next = prop;
            }
            else
            {
                first = prop;
            }

            return first;
        }
Example #2
0
        /*
        Create sorted linked list of properties from style string
        It temporarily places nulls in place of ':' and ';' to
        delimit the strings for the property name and value.
        Some systems don't allow you to null literal strings,
        so to avoid this, a copy is made first.
        */
        private StyleProp CreateProps(StyleProp prop, string style)
        {
            int valueStart = 0;
            int nameStart;

            nameStart = 0;
            while (nameStart < style.Length)
            {
                while (nameStart < style.Length && style[nameStart] == ' ')
                {
                    ++nameStart;
                }

                int nameEnd = nameStart;

                while (nameEnd < style.Length)
                {
                    if (style[nameEnd] == ':')
                    {
                        valueStart = nameEnd + 1;
                        break;
                    }

                    ++nameEnd;
                }

                if (nameEnd >= style.Length || style[nameEnd] != ':')
                {
                    break;
                }

                while (valueStart < style.Length && style[valueStart] == ' ')
                {
                    ++valueStart;
                }

                int valueEnd = valueStart;
                bool more = false;

                while (valueEnd < style.Length)
                {
                    if (style[valueEnd] == ';')
                    {
                        more = true;
                        break;
                    }

                    ++valueEnd;
                }

                prop = InsertProperty(prop, style.Substring(nameStart, (nameEnd) - (nameStart)),
                                      style.Substring(valueStart, (valueEnd) - (valueStart)));

                if (more)
                {
                    nameStart = valueEnd + 1;
                    continue;
                }

                break;
            }

            return prop;
        }
Example #3
0
        private string CreatePropString(StyleProp props)
        {
            string style = "";
            StyleProp prop;

            /* compute length */

            for (prop = props; prop != null; prop = prop.Next)
            {
            }

            for (prop = props; prop != null; prop = prop.Next)
            {
                style = string.Concat(style, prop.Name);
                style = string.Concat(style, ": ");

                style = string.Concat(style, prop.Val);

                if (prop.Next == null)
                {
                    break;
                }

                style = string.Concat(style, "; ");
            }

            return style;
        }