<commit_before>﻿namespace Swan.Extensions
{
    using Swan.Formatters;
    using Swan.Reflection;
    using System;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;

    /// <summary>
    /// String related extension methods.
    /// </summary>
    public static class StringExtensions
    {
        #region Private Declarations

        private const RegexOptions StandardRegexOptions =
            RegexOptions.Multiline | RegexOptions.Compiled | RegexOptions.CultureInvariant;

        private static readonly string[] ByteSuffixes = { "B", "KB", "MB", "GB", "TB" };

        private static readonly Lazy<Regex> SplitLinesRegex =
            new(() => new Regex("\r\n|\r|\n", StandardRegexOptions));

        private static readonly Lazy<Regex> UnderscoreRegex =
            new(() => new Regex(@"_", StandardRegexOptions));

        private static readonly Lazy<Regex> CamelCaseRegEx =
            new(() => new Regex(@"[a-z][A-Z]", StandardRegexOptions));

        private static readonly Lazy<MatchEvaluator> SplitCamelCaseString = new(() => m =>
        {
            var x = m.ToString();
            return x[0] + " " + x.Substring(1, x.Length - 1);
        });

        private static readonly Lazy<char[]> InvalidFilenameChars =
            new(() => Path.GetInvalidFileNameChars().ToArray());

        #endregion

        /// <summary>
        /// Returns a string that represents the given item
        /// It tries to use InvariantCulture if the ToString(IFormatProvider)
        /// overload exists.
        /// </summary>
        /// <param name="this">The item.</param>
        /// <returns>A <see cref="string" /> that represents the current object.</returns>
        public static string ToStringInvariant(this object? @this)
        {
            return @this switch
            {
                null => string.Empty,
                string stringValue => stringValue,<commit_msg>indexing<commit_after>﻿namespace Swan.Extensions
{
    using Swan.Formatters;
    using Swan.Reflection;
    using System;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;

    /// <summary>
    /// String related extension methods.
    /// </summary>
    public static class StringExtensions
    {
        #region Private Declarations

        private const RegexOptions StandardRegexOptions =
            RegexOptions.Multiline | RegexOptions.Compiled | RegexOptions.CultureInvariant;

        private static readonly string[] ByteSuffixes = { "B", "KB", "MB", "GB", "TB" };

        private static readonly Lazy<Regex> SplitLinesRegex =
            new(() => new Regex("\r\n|\r|\n", StandardRegexOptions));

        private static readonly Lazy<Regex> UnderscoreRegex =
            new(() => new Regex(@"_", StandardRegexOptions));

        private static readonly Lazy<Regex> CamelCaseRegEx =
            new(() => new Regex(@"[a-z][A-Z]", StandardRegexOptions));

        private static readonly Lazy<MatchEvaluator> SplitCamelCaseString = new(() => m =>
        {
            var x = m.ToString();
            return x[0] + " " + x[1..];
        });

        private static readonly Lazy<char[]> InvalidFilenameChars =
            new(() => Path.GetInvalidFileNameChars().ToArray());

        #endregion

        /// <summary>
        /// Returns a string that represents the given item
        /// It tries to use InvariantCulture if the ToString(IFormatProvider)
        /// overload exists.
        /// </summary>
        /// <param name="this">The item.</param>
        /// <returns>A <see cref="string" /> that represents the current object.</returns>
        public static string ToStringInvariant(this object? @this)
        {
            return @this switch
            {
                null => string.Empty,
                string stringValue => stringValue,
{'fraction_non_alphanumeric': 0.12169448010269576, 'fraction_numerical': 0.0012836970474967907, 'mean_word_length': 2.2385702410640067, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 47, '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': '7477480', 'n_tokens_mistral': 1043, 'n_tokens_neox': 993, 'n_words': 279}