<commit_before>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using System.Collections.Generic;
using System.Linq;

namespace osu.Framework.Graphics.Containers
{
    public class SearchContainer : SearchContainer<Drawable>
    { }

    public class SearchContainer<T> : Container<T>, ISearchableChildren where T : Drawable
    {
        private string searchTerm;
        /// <summary>
        /// String to match with the <see cref="ISearchable"/>s
        /// </summary>
        public string SearchTerm
        {
            get
            {
                return searchTerm;
            }
            set
            {
                searchTerm = value;
                match(this);
            }
        }

        public IEnumerable<ISearchable> SearchableChildren => Children.OfType<ISearchable>();
        public string[] Keywords => null;
        public bool Matching { get; set; }


        private bool match(ISearchable searchable, List<string> parentKeywords = null)
        {
            var searchContainer = searchable as ISearchableChildren;

            List<string> keywords;
            (keywords = new List<string>(searchable.Keywords ?? new string[0])).AddRange(parentKeywords ?? new string[0].ToList());

            if (searchContainer != null)
                return searchContainer.Matching = searchContainer.SearchableChildren.Any(children => match(children, keywords));
            else
                return searchable.Matching = keywords.Any(keyword => keyword.IndexOf(SearchTerm, StringComparison.InvariantCultureIgnoreCase) >= 0);
        }
    }
}
<commit_msg>Changed "Made code more compact"<commit_after>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using System.Collections.Generic;
using System.Linq;

namespace osu.Framework.Graphics.Containers
{
    public class SearchContainer : SearchContainer<Drawable>
    { }

    public class SearchContainer<T> : Container<T>, ISearchableChildren where T : Drawable
    {
        private string searchTerm;
        /// <summary>
        /// String to match with the <see cref="ISearchable"/>s
        /// </summary>
        public string SearchTerm
        {
            get
            {
                return searchTerm;
            }
            set
            {
                searchTerm = value;
                match(this);
            }
        }

        public IEnumerable<ISearchable> SearchableChildren => Children.OfType<ISearchable>();
        public string[] Keywords => null;
        public bool Matching { get; set; }


        private bool match(ISearchable searchable, List<string> parentKeywords = null)
        {
            var searchContainer = searchable as ISearchableChildren;
            
            var keywords = new List<string>(searchable.Keywords ?? new string[0]);
            keywords.AddRange(parentKeywords ?? new string[0].ToList());

            if (searchContainer != null)
            {
                bool matching = false;
                foreach(ISearchable searchableChildren in searchContainer.SearchableChildren)
                    matching = match(searchableChildren, keywords) || matching;
                return searchContainer.Matching = matching;
            }
            else
            {
                return searchable.Matching = keywords.Any(keyword => keyword.IndexOf(SearchTerm, StringComparison.InvariantCultureIgnoreCase) >= 0);
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.09216467463479415, 'fraction_numerical': 0.0058432934926958835, 'mean_word_length': 1.896923076923077, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 37, 'https://': 2, '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': '6197400', 'n_tokens_mistral': 975, 'n_tokens_neox': 915, 'n_words': 223}