<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace Whitebell.Library.Extension
{
    /// <summary>
    /// Indicates which type of conversion to perform
    /// </summary>
    [Flags]
    public enum StringConvert
    {
        /// <summary>
        /// Performs no conversion.
        /// </summary>
        None = 0,
        /// <summary>
        /// Converts the string to uppercase characters.
        /// </summary>
        Uppercase = 1,
        /// <summary>
        /// Converts the string to lowercase characters.
        /// </summary>
        Lowercase = 2,
        /// <summary>
        /// Converts the first letter of every word in the string to uppercase.
        /// </summary>
        TitleCase = 3,
        /// <summary>
        /// Converts narrow (single-byte) characters in the string to wide (double-byte) characters. Applies to Asian locales.
        /// </summary>
        FullWidth = 4,
        /// <summary>
        /// Converts wide (double-byte) characters in the string to narrow (single-byte) characters. Applies to Asian locales.
        /// </summary>
        HalfWidth = 8,
        /// <summary>
        /// Converts Hiragana characters in the string to Katakana characters. Applies to Japanese locale only.
        /// </summary>
        Katakana = 16,
        /// <summary>
        /// Converts Katakana characters in the string to Hiragana characters. Applies to Japanese locale only.
        /// </summary>
        Hiragana = 32,
        /// <summary>
        /// Converts the string to Simplified Chinese characters.
        /// </summary>
        SimplifiedChinese = 256,
        /// <summary>
        /// Converts the string to Traditional Chinese characters.
        /// </summary>
        TraditionalChinese = 512,
        /// <summary>
        /// Converts the string from file system rules for casing to linguistic rules.
        /// </summary>
        LinguisticCasing = 1024,
    }

    /// <summary>
    /// 区間の端点の扱いを示します。
    /// </summary>
    public enum Interval
    {
        /// <summary>閉区間 [min, max]</summary>
        Closed,
        /// <summary>開区間 (min, max)</summary>
        Open,
        /// <summary>左閉半開区間 [min, max)</summary>
        LeftClosedRightOpen,
        /// <summary>右閉半開区間 (min, max]</summary>
        LeftOpenRightClosed,
    }

    public static class Extension
    {
        #region where T : System.IComparable<T>

        /// <summary>
        /// 最小値、最大値を指定し、このインスタンスがその範囲外の場合は指定された最小値あるいは最大値を返します。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="val"></param>
        /// <param name="min">最小値</param>
        /// <param name="max">最大値</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"><paramref name="min"/> または <paramref name="max"/> が null です。</exception>
        /// <exception cref="ArgumentException"><paramref name="min"/> が <paramref name="max"/> よりも大きい値です。</exception>
        public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
        {
            if (val == null)
                throw new ArgumentNullException(nameof(val));
            if (min == null)
                throw new ArgumentNullException(nameof(min));
            if (max == null)
                throw new ArgumentNullException(nameof(max));
            if (min.CompareTo(max) > 0)
                throw new ArgumentException($"\"{nameof(min)}\" greater than \"{nameof(max)}\"");

            return val.CompareTo(min) < 0 ? min
                 : val.CompareTo(max) > 0 ? max
                 : val;
        }

        /// <summary>
        /// 最小値、最大値を指定し、このインスタンスがその範囲に含まれているかを示します。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="val"></param>
        /// <param name="min">最小値</param>
        /// <param name="max">最大値</param>
        /// <returns>最小値と最大値の範囲内に含まれている場合は true。それ以外の場合は false。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="min"/> または <paramref name="max"/> が null です。</exception>
        /// <exception cref="ArgumentException"><paramref name="min"/> が <paramref name="max"/> よりも大きい値です。</exception>
        [Obsolete("use InRange<T>(T, T, T, Interval)")]
        public static bool InRange<T>(this T val, T min, T max) where T : IComparable<T> => InRange(val, min, max, Interval.Closed);

        /// <summary>
        /// 最小値、最大値を指定し、このインスタンスがその区間に含まれているかを示します。<commit_msg>InRange<T>(this T, T, T)をObsoleteにするのやっぱりやめる<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace Whitebell.Library.Extension
{
    /// <summary>
    /// Indicates which type of conversion to perform
    /// </summary>
    [Flags]
    public enum StringConvert
    {
        /// <summary>
        /// Performs no conversion.
        /// </summary>
        None = 0,
        /// <summary>
        /// Converts the string to uppercase characters.
        /// </summary>
        Uppercase = 1,
        /// <summary>
        /// Converts the string to lowercase characters.
        /// </summary>
        Lowercase = 2,
        /// <summary>
        /// Converts the first letter of every word in the string to uppercase.
        /// </summary>
        TitleCase = 3,
        /// <summary>
        /// Converts narrow (single-byte) characters in the string to wide (double-byte) characters. Applies to Asian locales.
        /// </summary>
        FullWidth = 4,
        /// <summary>
        /// Converts wide (double-byte) characters in the string to narrow (single-byte) characters. Applies to Asian locales.
        /// </summary>
        HalfWidth = 8,
        /// <summary>
        /// Converts Hiragana characters in the string to Katakana characters. Applies to Japanese locale only.
        /// </summary>
        Katakana = 16,
        /// <summary>
        /// Converts Katakana characters in the string to Hiragana characters. Applies to Japanese locale only.
        /// </summary>
        Hiragana = 32,
        /// <summary>
        /// Converts the string to Simplified Chinese characters.
        /// </summary>
        SimplifiedChinese = 256,
        /// <summary>
        /// Converts the string to Traditional Chinese characters.
        /// </summary>
        TraditionalChinese = 512,
        /// <summary>
        /// Converts the string from file system rules for casing to linguistic rules.
        /// </summary>
        LinguisticCasing = 1024,
    }

    /// <summary>
    /// 区間の端点の扱いを示します。
    /// </summary>
    public enum Interval
    {
        /// <summary>閉区間 [min, max]</summary>
        Closed,
        /// <summary>開区間 (min, max)</summary>
        Open,
        /// <summary>左閉半開区間 [min, max)</summary>
        LeftClosedRightOpen,
        /// <summary>右閉半開区間 (min, max]</summary>
        LeftOpenRightClosed,
    }

    public static class Extension
    {
        #region where T : System.IComparable<T>

        /// <summary>
        /// 最小値、最大値を指定し、このインスタンスがその範囲外の場合は指定された最小値あるいは最大値を返します。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="val"></param>
        /// <param name="min">最小値</param>
        /// <param name="max">最大値</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"><paramref name="min"/> または <paramref name="max"/> が null です。</exception>
        /// <exception cref="ArgumentException"><paramref name="min"/> が <paramref name="max"/> よりも大きい値です。</exception>
        public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
        {
            if (val == null)
                throw new ArgumentNullException(nameof(val));
            if (min == null)
                throw new ArgumentNullException(nameof(min));
            if (max == null)
                throw new ArgumentNullException(nameof(max));
            if (min.CompareTo(max) > 0)
                throw new ArgumentException($"\"{nameof(min)}\" greater than \"{nameof(max)}\"");

            return val.CompareTo(min) < 0 ? min
                 : val.CompareTo(max) > 0 ? max
                 : val;
        }

        /// <summary>
        /// 最小値、最大値を指定し、このインスタンスがその範囲に含まれているかを示します。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="val"></param>
        /// <param name="min">最小値</param>
        /// <param name="max">最大値</param>
        /// <returns>最小値と最大値の範囲内に含まれている場合は true。それ以外の場合は false。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="min"/> または <paramref name="max"/> が null です。</exception>
        /// <exception cref="ArgumentException"><paramref name="min"/> が <paramref name="max"/> よりも大きい値です。</exception>
        public static bool InRange<T>(this T val, T min, T max) where T : IComparable<T> => InRange(val, min, max, Interval.Closed);

        /// <summary>
        /// 最小値、最大値を指定し、このインスタンスがその区間に含まれているかを示します。
{'fraction_non_alphanumeric': 0.1452084461288576, 'fraction_numerical': 0.004981050351922036, 'mean_word_length': 1.923710034821146, 'pattern_counts': {'":': 0, '<': 167, '<?xml version=': 0, '>': 171, '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': '4726173', 'n_tokens_mistral': 2934, 'n_tokens_neox': 2861, 'n_words': 689}