Пример #1
0
        public static Style Parse(CssReader reader, char stopChar = '\0')
        {
            Style  style = new Style();
            string propertyName = null, propertyValue = null;

            int p;

            reader.SkipWhiteSpaces();
            bool readingName = true;

            while ((p = reader.Peek()) > 0)
            {
                switch (unchecked ((char)p))
                {
                case ':':
                    reader.Read();
                    readingName = false;
                    reader.SkipWhiteSpaces();
                    break;

                case ';':
                    reader.Read();
                    if (!string.IsNullOrEmpty(propertyName) && !string.IsNullOrEmpty(propertyValue))
                    {
                        style.Declarations.Add(propertyName, propertyValue);
                    }
                    propertyName = propertyValue = null;
                    readingName  = true;
                    reader.SkipWhiteSpaces();
                    break;

                default:
                    if ((char)p == stopChar)
                    {
                        return(style);
                    }

                    if (readingName)
                    {
                        propertyName = reader.ReadIdent();
                        if (propertyName == null)
                        {
                            throw new Exception();
                        }
                    }
                    else
                    {
                        propertyValue = reader.ReadUntil(stopChar, ';', ':');
                    }
                    break;
                }
            }
            return(style);
        }