Пример #1
0
        /// <summary>
        /// </summary>
        /// <param name="parser">CssParser</param>
        /// <param name="fragment">CssFragment</param>
        void GetAttributes(CssFragment fragment, CssParser parser)
        {
            // TODO: CssParserOptions.ReadAttributes
            string sTags, sBlocks;

            if (fragment.FragmentType == CssFragmentType.Definition)
            {
                sTags   = fragment.Tag.ToString();
                sBlocks = parser
                          .FindNextFragment(CssFragmentType.Block, (int)this.Position)
                          .section.Substring(parser.Text);
            }
        }
Пример #2
0
        /// <summary>
        /// Performs level-1 parsing providing a set of curly-block CssFragments.
        /// </summary>
        /// <exception cref="CssParserException">Throws an exception on inconsistent curly-blocks.</exception>
        void ParseLevel1()
        {
            // Set up our initial TextRange
            this.Defs.Root = new TextRange(0, this.textBuffer.Length);

            // Set our initial Read Position to 0
            int current = 0;

            // This is our output List.
            this.Defs.BlockLevels.Clear();
//			List<CssFragment> list = new List<CssFragment>();

            // The Stack.Count tells us what Block-Level were at.
            // It increments up each time we enter a new Block, and
            // increments down each time we exit a Block.
            Stack <CssFragment> stack = new Stack <CssFragment>();

            while ((current = this.Defs.Root.section.IndexOf(CssBlockElement, this.textBuffer, current, this.Defs.Root.section.Length32 - current, false)) > -1)
            {
                // This is used to store the largest possible hierarchical block level.
                // such as 'GLOBAL { LEVEL-1 { LEVEL-2 { LEVEL-3 { ... } } } }'.
                int stackRecursion = 0;

                // Exit the loop if no more block elements have been found.
                if (current == -1)
                {
                    break;
                }

                // Look into our buffer to tell if we're entering or exiting from a Block.
                char c = this.textBuffer[current];

                // Create a new CssFragment for using later.
                CssFragment temp = new CssFragment(new TextRange(current, 1))
                {
                    FragmentType = CssFragmentType.Block
                };

                // if we're in a comment segment, we have no pending action.
                                #if DEBUG
                if (this.IsInComment(temp)) /* skipping */ System {
Пример #3
0
        /// <summary>A utility function to quickly get all Definition names for a range of definitions.
        /// <para>A definition is what we term any declaration before the curly-block of attributes/values.</para>
        /// EG: <tt>definition-term1 :selector { attribute: value; }</tt>
        /// <para>Depends on (boolean) <see cref="CssParserOptions"/>.CleanDefinitionWhiteSpace value.</para>
        /// </summary>
        /// <returns></returns>
        /// <param name="parser">CssParser provides the text-buffer.</param>
        /// <exception cref="ArgumentException">Thrown if you try to get definitions from a tag that does not contain any.</exception>
        public string GetDefinitions(CssParser parser)
        {
            System.Diagnostics.Debug.Print("Reading Definitions from element.");
            if ((this.FragmentType != CssFragmentType.Definition) /* || (this.FragmentType != CssFragmentType.DefinitionFragment)*/)
            {
                throw new ArgumentException("Fragment MUST be CssFragmentType.Definition.");                //
            }
            // obtain a reference to the next curly-block.
            CssFragment nextBlock = parser.FindNextFragment(CssFragmentType.Block, (int)this.Position);

            // TODO: report mal-formed CSS.
            if (nextBlock == null)
            {
                System.Diagnostics.Debug.Print("Mal-Formed CSS @{0}", this.Position);
                return(null);
            }

            // Find fragmented terms, and comments
            IEnumerable <CssFragment> resultset = parser.Defs.Leveled.Where(
                f =>
                (f.Position < nextBlock.Position) &&
                (f.Position > this.Position) &&
                ((f.FragmentType == CssFragmentType.Definition) || (f.FragmentType == CssFragmentType.CommentBlock))
                );

            // Get Text for the current element fro the buffer
            string temp = this.section.Substring(parser.Text);

            // clean up the text if need be
            if (parser.ParserOptions.CleanDefinitionWhiteSpace)
            {
                temp = CleanupDefinition(temp);
            }

            // Get text for fragmented definitions and if need be, comments.
            using (IEnumerator <CssFragment> rs = resultset.GetEnumerator())
            {
                while (rs.MoveNext())
                {
                    System.Diagnostics.Debug.Print("Fragment: {0}", rs.Current.Position);

                    // CssFragmentType.DefinitionFragmentComment
                    if ((rs.Current.FragmentType == CssFragmentType.CommentBlock) && (!parser.ParserOptions.CleanDefinitionFragmentedComments))
                    {
                        System.Diagnostics.Debug.Print("Found Fragmented Comment at Position: {0}", rs.Current.Position);
                        rs.Current.FragmentType = CssFragmentType.DefinitionFragmentComment;
                        temp += parser.GetEOL() + rs.Current.section.Substring(parser.Text) + parser.GetEOL();
                    }

                    // CssFragmentType.DefinitionFragment
                    else if ((rs.Current.FragmentType == CssFragmentType.Definition))
                    {
                        System.Diagnostics.Debug.Print("Found Fragmented Definition at Position: {0}", rs.Current.Position);
                        rs.Current.FragmentType = CssFragmentType.DefinitionFragment;
                        temp += parser.ParserOptions.CleanDefinitionWhiteSpace ?
                                CleanupDefinition(rs.Current.section.Substring(parser.Text)) :
                                rs.Current.section.Substring(parser.Text);
                    }
                    // This is a bad idea.
                    this.section.Length += rs.Current.Length;
                }
            }

            return(temp);
        }
Пример #4
0
 /// <summary>
 /// The .NET v2.0 standard for sorting.
 /// </summary>
 /// <returns></returns>
 /// <param name="a"></param>
 /// <param name="b"></param>
 static public int SortCompare(CssFragment a, CssFragment b)
 {
     return(a.section.Position.CompareTo(b.section.Position));
 }