<commit_before>package jp.toastkid.yobidashi.search

import android.content.Context
import android.net.Uri
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.main.LocaleWrapper
import java.util.*

/**
 * Web search category.
 *
 * @author toastkidjp
 */
enum class SearchCategory(
        @StringRes val id: Int,
        @DrawableRes val iconId: Int,
        private val host: String,
        private val generator: (l: String, h: String, q: String) -> String = { _, h, q ->  h + q }
    ) {

    GOOGLE(R.string.google,
            R.drawable.ic_google,
            "https://www.google.com/search?q="
    ),
    BING(R.string.bing,
            R.drawable.ic_bing_logo,
            "https://www.bing.com/search?q="
    ),
    DUCKDUCKGO(R.string.search_category_web,
            R.drawable.ic_duckduckgo,
            "https://duckduckgo.com/%s?ia=web",
            { _, h, q -> String.format(h, q)}
    ),
    YANDEX(R.string.search_category_yandex,
            R.drawable.ic_yandex,
            "https://www.yandex.com/search/?text="
    ),
    YAHOO(R.string.search_category_yahoo,
            R.drawable.ic_yahoo,
            "https://search.yahoo.com/search?p="
    ),
    YAHOO_JAPAN(R.string.search_category_yahoo_japan,
            R.drawable.ic_yahoo_japan_logo,
            "https://search.yahoo.co.jp/search?p="
    ),
    BAIDU(R.string.baidu,
            R.drawable.ic_baidu,
            "https://www.baidu.com/s?wd="
    ),
    IMAGE(R.string.search_category_image,
            R.drawable.ic_image_search,
            "https://www.google.co.jp/search?site=imghp&tbm=isch&q="
    ),
    YOUTUBE(R.string.search_category_youtube,
            R.drawable.ic_video,
            "https://www.youtube.com/results?search_query="
    ),
    TIKTOK(R.string.search_category_tiktok,
            R.drawable.ic_tiktok,
            "https://www.tiktok.com/tag/"
    ),
    WIKIPEDIA(R.string.search_category_wikipedia,
            R.drawable.ic_wikipedia,
            "https://%s.wikipedia.org/w/index.php?search=",
            { l, h, q -> String.format(h, l) + Uri.encode(q) }
    ),
    TWITTER(R.string.search_category_twitter,
            R.drawable.ic_twitter,
            "https://twitter.com/search?src=typd&q="
    ),
    FACEBOOK(R.string.search_category_facebook,
            R.drawable.ic_facebook,
            "https://m.facebook.com/search?query="
    ),
    INSTAGRAM(R.string.search_category_instagram,
            R.drawable.ic_instagram_logo,
            "https://www.instagram.com/explore/tags/"
    ),
    FLICKR(R.string.search_category_flickr,
            R.drawable.ic_flickr,
            "https://www.flickr.com/search/?text="
    ),
    MAP(R.string.search_category_map,
            R.drawable.ic_map,
            "https://www.google.co.jp/maps/place/"
    ),
    APPS(R.string.search_category_apps,
            R.drawable.ic_google_play,
            "https://play.google.com/store/search?q="
    ),
    YELP(R.string.yelp,
            R.drawable.ic_yelp,
            "https://www.yelp.com/search?find_desc="
    ),
    GUTENBERG(R.string.gutenberg,
            R.drawable.ic_local_library_black,
            "http://www.gutenberg.org/ebooks/search/?query="
    ),
    AMAZON(R.string.search_category_shopping,
            R.drawable.ic_amazon,
            "https://www.amazon.co.jp/s/ref=nb_sb_noss?field-keywords=",
            { l, h, q ->
                if (Locale.JAPANESE.language == l) {
                    h + Uri.encode(q)
                } else {
                    "https://www.amazon.com/s/ref=nb_sb_noss?field-keywords=" + Uri.encode(q)
                }
            }
    ),
    TECHNICAL_QA(R.string.search_category_stack_overflow,
            R.drawable.ic_stackoverflow,
            "https://stackoverflow.com/search?q="
    ),
    TECHNOLOGY(R.string.search_category_technology,
            R.drawable.ic_techcrunch,
            "http://jp.techcrunch.com/search/",
            {l, h, q ->
                if (Locale.JAPANESE.language == l) {
                    h + Uri.encode(q)
                }
                "https://techcrunch.com/search/" + Uri.encode(q)
            }
    ),
    SLASHDOT(R.string.search_category_slashdot,
            R.drawable.ic_slashdot,
            "https://slashdot.org/index2.pl?fhfilter="
    ),
    REDDIT(R.string.search_category_reddit,
            R.drawable.ic_reddit,
            "https://www.reddit.com/search/?q="
    ),
    GITHUB(R.string.search_category_github,
            R.drawable.ic_github,
            "https://github.com/search?utf8=%E2%9C%93&type=&q="
    ),
    MVNREPOSITORY(R.string.search_category_mvnrepository,
            R.drawable.ic_mvn,
            "https://mvnrepository.com/search?q="
    ),
    MEDIUM(R.string.medium,
            R.drawable.ic_medium,
            "https://medium.com/search?q="
    ),
    TED(R.string.ted,
            R.drawable.ic_ted,
            "https://www.ted.com/search?q="
    ),
    SLIDESHARE(R.string.slideshare,
            R.drawable.ic_slideshare,
            "https://www.slideshare.net/search/slideshow?q="
    ),
    SPEAKERDECK(R.string.speakerdeck,
            R.drawable.ic_speakerdeck,
            "https://cse.google.com/cse?cx=010150859881542981030%3Ahqhxyxpwtc4&q=java"
    ),
    BUZZFEED(R.string.buzzfeed,
            R.drawable.ic_buzzfeed,
            "https://www.buzzfeed.com/jp/search?q="
    ),
    LIVEJOURNAL(R.string.livejournal,
            R.drawable.ic_livejournal,
            "https://www.livejournal.com/gsearch/?engine=google&cx=partner-pub-5600223439108080:3711723852&q="
    ),
    ;

    /**
     * Make search URL with query.
     *
     * @param context [Context]
     * @param query Query string
     *
     * @return Search result URL
     */
    fun make(context: Context, query: String): String {
        return generate(
                LocaleWrapper.getLocale(context.resources.configuration),
                host,
                query
        )
    }

    /**
     * Generate URL.
     *
     * @param l Locale string
     * @param h Host of search result
     * @param q Search query
     *
     * @return Search result URL
     */
    private fun generate(l: String, h: String, q: String): String = generator(l, h, q)

    companion object {

        /**
         * Find [SearchCategory] by search category.
         *
         * @param category Search category
         * @return [SearchCategory]
         */
        fun findByCategory(category: String): SearchCategory {
            for (f in SearchCategory.values()) {
                if (f.name == category.toUpperCase()) {
                    return f
                }
            }
            return SearchCategory.values()
                    .find { it.name == category.toUpperCase() }
                    .let { if (it == null) { GOOGLE } else { it } }
        }

        /**
         * Find index in values by search category string form.
         *
         * @param category Search category string form
         *
         * @return index
         */
        fun findIndex(category: String): Int =
                values().find { it.name == category.toUpperCase() } ?.ordinal ?: 0

        /**
         * Get default object.
         *
         * @return GOOGLE
         */
        fun getDefault(): SearchCategory = GOOGLE

        /**
         * Get default category name.
         *
         * @return "GOOGLE"
         */
        fun getDefaultCategoryName(): String = getDefault().name
    }
}<commit_msg>bugfix #412 Fix Speaker Deck's URL.<commit_after>package jp.toastkid.yobidashi.search

import android.content.Context
import android.net.Uri
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.main.LocaleWrapper
import java.util.*

/**
 * Web search category.
 *
 * @author toastkidjp
 */
enum class SearchCategory(
        @StringRes val id: Int,
        @DrawableRes val iconId: Int,
        private val host: String,
        private val generator: (l: String, h: String, q: String) -> String = { _, h, q ->  h + q }
    ) {

    GOOGLE(R.string.google,
            R.drawable.ic_google,
            "https://www.google.com/search?q="
    ),
    BING(R.string.bing,
            R.drawable.ic_bing_logo,
            "https://www.bing.com/search?q="
    ),
    DUCKDUCKGO(R.string.search_category_web,
            R.drawable.ic_duckduckgo,
            "https://duckduckgo.com/%s?ia=web",
            { _, h, q -> String.format(h, q)}
    ),
    YANDEX(R.string.search_category_yandex,
            R.drawable.ic_yandex,
            "https://www.yandex.com/search/?text="
    ),
    YAHOO(R.string.search_category_yahoo,
            R.drawable.ic_yahoo,
            "https://search.yahoo.com/search?p="
    ),
    YAHOO_JAPAN(R.string.search_category_yahoo_japan,
            R.drawable.ic_yahoo_japan_logo,
            "https://search.yahoo.co.jp/search?p="
    ),
    BAIDU(R.string.baidu,
            R.drawable.ic_baidu,
            "https://www.baidu.com/s?wd="
    ),
    IMAGE(R.string.search_category_image,
            R.drawable.ic_image_search,
            "https://www.google.co.jp/search?site=imghp&tbm=isch&q="
    ),
    YOUTUBE(R.string.search_category_youtube,
            R.drawable.ic_video,
            "https://www.youtube.com/results?search_query="
    ),
    TIKTOK(R.string.search_category_tiktok,
            R.drawable.ic_tiktok,
            "https://www.tiktok.com/tag/"
    ),
    WIKIPEDIA(R.string.search_category_wikipedia,
            R.drawable.ic_wikipedia,
            "https://%s.wikipedia.org/w/index.php?search=",
            { l, h, q -> String.format(h, l) + Uri.encode(q) }
    ),
    TWITTER(R.string.search_category_twitter,
            R.drawable.ic_twitter,
            "https://twitter.com/search?src=typd&q="
    ),
    FACEBOOK(R.string.search_category_facebook,
            R.drawable.ic_facebook,
            "https://m.facebook.com/search?query="
    ),
    INSTAGRAM(R.string.search_category_instagram,
            R.drawable.ic_instagram_logo,
            "https://www.instagram.com/explore/tags/"
    ),
    FLICKR(R.string.search_category_flickr,
            R.drawable.ic_flickr,
            "https://www.flickr.com/search/?text="
    ),
    MAP(R.string.search_category_map,
            R.drawable.ic_map,
            "https://www.google.co.jp/maps/place/"
    ),
    APPS(R.string.search_category_apps,
            R.drawable.ic_google_play,
            "https://play.google.com/store/search?q="
    ),
    YELP(R.string.yelp,
            R.drawable.ic_yelp,
            "https://www.yelp.com/search?find_desc="
    ),
    GUTENBERG(R.string.gutenberg,
            R.drawable.ic_local_library_black,
            "http://www.gutenberg.org/ebooks/search/?query="
    ),
    AMAZON(R.string.search_category_shopping,
            R.drawable.ic_amazon,
            "https://www.amazon.co.jp/s/ref=nb_sb_noss?field-keywords=",
            { l, h, q ->
                if (Locale.JAPANESE.language == l) {
                    h + Uri.encode(q)
                } else {
                    "https://www.amazon.com/s/ref=nb_sb_noss?field-keywords=" + Uri.encode(q)
                }
            }
    ),
    TECHNICAL_QA(R.string.search_category_stack_overflow,
            R.drawable.ic_stackoverflow,
            "https://stackoverflow.com/search?q="
    ),
    TECHNOLOGY(R.string.search_category_technology,
            R.drawable.ic_techcrunch,
            "http://jp.techcrunch.com/search/",
            {l, h, q ->
                if (Locale.JAPANESE.language == l) {
                    h + Uri.encode(q)
                }
                "https://techcrunch.com/search/" + Uri.encode(q)
            }
    ),
    SLASHDOT(R.string.search_category_slashdot,
            R.drawable.ic_slashdot,
            "https://slashdot.org/index2.pl?fhfilter="
    ),
    REDDIT(R.string.search_category_reddit,
            R.drawable.ic_reddit,
            "https://www.reddit.com/search/?q="
    ),
    GITHUB(R.string.search_category_github,
            R.drawable.ic_github,
            "https://github.com/search?utf8=%E2%9C%93&type=&q="
    ),
    MVNREPOSITORY(R.string.search_category_mvnrepository,
            R.drawable.ic_mvn,
            "https://mvnrepository.com/search?q="
    ),
    MEDIUM(R.string.medium,
            R.drawable.ic_medium,
            "https://medium.com/search?q="
    ),
    TED(R.string.ted,
            R.drawable.ic_ted,
            "https://www.ted.com/search?q="
    ),
    SLIDESHARE(R.string.slideshare,
            R.drawable.ic_slideshare,
            "https://www.slideshare.net/search/slideshow?q="
    ),
    SPEAKERDECK(R.string.speakerdeck,
            R.drawable.ic_speakerdeck,
            "https://cse.google.com/cse?cx=010150859881542981030%3Ahqhxyxpwtc4&q="
    ),
    BUZZFEED(R.string.buzzfeed,
            R.drawable.ic_buzzfeed,
            "https://www.buzzfeed.com/jp/search?q="
    ),
    LIVEJOURNAL(R.string.livejournal,
            R.drawable.ic_livejournal,
            "https://www.livejournal.com/gsearch/?engine=google&cx=partner-pub-5600223439108080:3711723852&q="
    ),
    ;

    /**
     * Make search URL with query.
     *
     * @param context [Context]
     * @param query Query string
     *
     * @return Search result URL
     */
    fun make(context: Context, query: String): String {
        return generate(
                LocaleWrapper.getLocale(context.resources.configuration),
                host,
                query
        )
    }

    /**
     * Generate URL.
     *
     * @param l Locale string
     * @param h Host of search result
     * @param q Search query
     *
     * @return Search result URL
     */
    private fun generate(l: String, h: String, q: String): String = generator(l, h, q)

    companion object {

        /**
         * Find [SearchCategory] by search category.
         *
         * @param category Search category
         * @return [SearchCategory]
         */
        fun findByCategory(category: String): SearchCategory {
            for (f in SearchCategory.values()) {
                if (f.name == category.toUpperCase()) {
                    return f
                }
            }
            return SearchCategory.values()
                    .find { it.name == category.toUpperCase() }
                    .let { if (it == null) { GOOGLE } else { it } }
        }

        /**
         * Find index in values by search category string form.
         *
         * @param category Search category string form
         *
         * @return index
         */
        fun findIndex(category: String): Int =
                values().find { it.name == category.toUpperCase() } ?.ordinal ?: 0

        /**
         * Get default object.
         *
         * @return GOOGLE
         */
        fun getDefault(): SearchCategory = GOOGLE

        /**
         * Get default category name.
         *
         * @return "GOOGLE"
         */
        fun getDefaultCategoryName(): String = getDefault().name
    }
}
{'fraction_non_alphanumeric': 0.13211166975390315, 'fraction_numerical': 0.007607832759989415, 'mean_word_length': 1.7814167433302668, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 64, 'lorem ipsum': 0, 'www.': 38, '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': '3315051', 'n_tokens_mistral': 5172, 'n_tokens_neox': 4870, 'n_words': 643}