<commit_before>﻿namespace AngleSharp.Dom.Css
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using AngleSharp.Extensions;
    using AngleSharp.Parser.Css;

    /// <summary>
    /// Represents a CSS value.
    /// </summary>
    sealed class CssValue : ICssValue, IEnumerable<CssToken>
    {
        #region Fields

        readonly CssValueType _type;
        readonly List<CssToken> _tokens;

        public static CssValue Initial = new CssValue(new []
        { 
            new CssKeywordToken(CssTokenType.Ident, "initial", TextPosition.Empty) 
        });

        #endregion

        #region ctor

        /// <summary>
        /// Creates a new CSS value.
        /// </summary>
        /// <param name="tokens">The tokens to use.</param>
        public CssValue(IEnumerable<CssToken> tokens)
        {
            _tokens = new List<CssToken>(tokens);
            _type = FindType(_tokens);
        }

        static CssValueType FindType(List<CssToken> tokens)
        {
            var type = CssValueType.Custom;
            var open = 0;

            if (tokens.Count == 1)
            {
                if (tokens[0].Data.Equals(Keywords.Initial, StringComparison.OrdinalIgnoreCase))
                    return CssValueType.Initial;
                else if (tokens[0].Data.Equals(Keywords.Inherit, StringComparison.OrdinalIgnoreCase))
                    return CssValueType.Inherit;
            }

            for (int i = 0; i < tokens.Count; i++)
            {
                if (type == CssValueType.Custom)
                    type = CssValueType.Primitive;

                if (open > 0 && tokens[i].Type == CssTokenType.RoundBracketClose)
                    open--;

                if (tokens[i].Type == CssTokenType.Function || tokens[i].Type == CssTokenType.RoundBracketOpen)
                    open++;

                if (open > 0)
                    continue;

                if (tokens[i].Type == CssTokenType.Whitespace || tokens[i].Type == CssTokenType.Comma ||
                    (tokens[i].Type == CssTokenType.Delim && tokens[i].Data == "/"))
                    type = CssValueType.List;
            }

            return type;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets the token at the provided index.
        /// </summary>
        /// <param name="index">The index of the token.</param>
        /// <returns>The token at the index.</returns>
        public CssToken this[Int32 index]
        {
            get { return _tokens[index]; }
        }

        /// <summary>
        /// Gets the number of tokens for the current value.
        /// </summary>
        public Int32 Count
        {
            get { return _tokens.Count; }
        }

        /// <summary>
        /// Gets a code defining the type of the value as defined above.
		/// </summary>
        public CssValueType Type
        {
            get { return _type; }
        }

        /// <summary>
        /// Gets or sets a string representation of the current value.
        /// </summary>
        public String CssText
        {
            get { return _tokens.ToText(); }
        }

        #endregion

        #region IEnumerable

        public IEnumerator<CssToken> GetEnumerator()
        {
            return _tokens.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion
    }
}
<commit_msg>Exclude function tokens from nesting<commit_after>﻿namespace AngleSharp.Dom.Css
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using AngleSharp.Extensions;
    using AngleSharp.Parser.Css;

    /// <summary>
    /// Represents a CSS value.
    /// </summary>
    sealed class CssValue : ICssValue, IEnumerable<CssToken>
    {
        #region Fields

        readonly CssValueType _type;
        readonly List<CssToken> _tokens;

        public static CssValue Initial = new CssValue(new []
        { 
            new CssKeywordToken(CssTokenType.Ident, "initial", TextPosition.Empty) 
        });

        #endregion

        #region ctor

        /// <summary>
        /// Creates a new CSS value.
        /// </summary>
        /// <param name="tokens">The tokens to use.</param>
        public CssValue(IEnumerable<CssToken> tokens)
        {
            _tokens = new List<CssToken>(tokens);
            _type = FindType(_tokens);
        }

        static CssValueType FindType(List<CssToken> tokens)
        {
            var type = CssValueType.Custom;
            var open = 0;

            if (tokens.Count == 1)
            {
                if (tokens[0].Data.Equals(Keywords.Initial, StringComparison.OrdinalIgnoreCase))
                    return CssValueType.Initial;
                else if (tokens[0].Data.Equals(Keywords.Inherit, StringComparison.OrdinalIgnoreCase))
                    return CssValueType.Inherit;
            }

            for (int i = 0; i < tokens.Count; i++)
            {
                if (type == CssValueType.Custom)
                    type = CssValueType.Primitive;

                if (tokens[i].Type == CssTokenType.RoundBracketClose)
                    open--;

                if (tokens[i].Type == CssTokenType.RoundBracketOpen)
                    open++;

                if (open > 0)
                    continue;

                if (tokens[i].Type == CssTokenType.Whitespace || tokens[i].Type == CssTokenType.Comma ||
                    (tokens[i].Type == CssTokenType.Delim && tokens[i].Data == "/"))
                    type = CssValueType.List;
            }

            return type;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets the token at the provided index.
        /// </summary>
        /// <param name="index">The index of the token.</param>
        /// <returns>The token at the index.</returns>
        public CssToken this[Int32 index]
        {
            get { return _tokens[index]; }
        }

        /// <summary>
        /// Gets the number of tokens for the current value.
        /// </summary>
        public Int32 Count
        {
            get { return _tokens.Count; }
        }

        /// <summary>
        /// Gets a code defining the type of the value as defined above.
		/// </summary>
        public CssValueType Type
        {
            get { return _type; }
        }

        /// <summary>
        /// Gets or sets a string representation of the current value.
        /// </summary>
        public String CssText
        {
            get { return _tokens.ToText(); }
        }

        #endregion

        #region IEnumerable

        public IEnumerator<CssToken> GetEnumerator()
        {
            return _tokens.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion
    }
}

{'fraction_non_alphanumeric': 0.10658082975679542, 'fraction_numerical': 0.0030042918454935624, 'mean_word_length': 1.4504030844724851, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5976462', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1854, 'n_words': 452}