<commit_before>﻿using System.Text;
using System.Text.RegularExpressions;

namespace Discord
{
    public static class Format
	{
		private static readonly Regex _escapeRegex;
		private static readonly MatchEvaluator _escapeEvaluator;

		static Format()
		{
			const string innerPattern = "[_*]|~~";
			_escapeRegex = new Regex($@"(?:^|\W)(?:{innerPattern})|(?:{innerPattern})(?:\W|$)|\\", RegexOptions.Compiled);
			_escapeEvaluator = new MatchEvaluator(e => '\\' + e.Value);
		}

		/// <summary> Removes all special formatting characters from the provided text. </summary>
		private static string Escape(string text)
			=> _escapeRegex.Replace(text, _escapeEvaluator);

		/// <summary> Returns a markdown-formatted string with no formatting, optionally escaping the contents. </summary>
		public static string Normal(string text, bool escape = true)
			=> escape ? Escape(text) : text;
		/// <summary> Returns a markdown-formatted string with bold formatting, optionally escaping the contents. </summary>
		public static string Bold(string text, bool escape = true)
			=> escape ? $"**{Escape(text)}**" : $"**{text}**";
		/// <summary> Returns a markdown-formatted string with italics formatting, optionally escaping the contents. </summary>
		public static string Italics(string text, bool escape = true)
			=> escape ? $"*{Escape(text)}*" : $"*{text}*";
		/// <summary> Returns a markdown-formatted string with underline formatting, optionally escaping the contents. </summary>
		public static string Underline(string text, bool escape = true)
			=> escape ? $"__{Escape(text)}__" : $"__{text}__";
		/// <summary> Returns a markdown-formatted string with strikeout formatting, optionally escaping the contents. </summary>
		public static string Strikeout(string text, bool escape = true)
			=> escape ? $"~~{Escape(text)}~~" : $"~~{text}~~";

		/// <summary> Returns a markdown-formatted string with multiple formatting, optionally escaping the contents. </summary>
		public static string Multiple(string text, bool escape = true, bool bold = false, bool italics = false, bool underline = false, bool strikeout = false)
		{
			string result = text;
			if (escape) result = Escape(result);
			if (bold) result = Bold(result, false);
			if (italics) result = Italics(result, false);
			if (underline) result = Underline(result, false);
			if (strikeout) result = Strikeout(result, false);
			return result;
		}
	}
}
<commit_msg>There goes my regex crown<commit_after>﻿using System.Text;
using System.Text.RegularExpressions;

namespace Discord
{
    public static class Format
	{
		private static readonly Regex _escapeRegex;
		private static readonly MatchEvaluator _escapeEvaluator;

		static Format()
		{
			const string innerPattern = "[_*]|~~";
			_escapeRegex = new Regex($@"(?<=^|\W)(?:{innerPattern})|(?:{innerPattern})(?=\W|$)|\\", RegexOptions.Compiled);
			_escapeEvaluator = new MatchEvaluator(e => '\\' + e.Value);
		}

		/// <summary> Removes all special formatting characters from the provided text. </summary>
		private static string Escape(string text)
			=> _escapeRegex.Replace(text, _escapeEvaluator);

		/// <summary> Returns a markdown-formatted string with no formatting, optionally escaping the contents. </summary>
		public static string Normal(string text, bool escape = true)
			=> escape ? Escape(text) : text;
		/// <summary> Returns a markdown-formatted string with bold formatting, optionally escaping the contents. </summary>
		public static string Bold(string text, bool escape = true)
			=> escape ? $"**{Escape(text)}**" : $"**{text}**";
		/// <summary> Returns a markdown-formatted string with italics formatting, optionally escaping the contents. </summary>
		public static string Italics(string text, bool escape = true)
			=> escape ? $"*{Escape(text)}*" : $"*{text}*";
		/// <summary> Returns a markdown-formatted string with underline formatting, optionally escaping the contents. </summary>
		public static string Underline(string text, bool escape = true)
			=> escape ? $"__{Escape(text)}__" : $"__{text}__";
		/// <summary> Returns a markdown-formatted string with strikeout formatting, optionally escaping the contents. </summary>
		public static string Strikeout(string text, bool escape = true)
			=> escape ? $"~~{Escape(text)}~~" : $"~~{text}~~";

		/// <summary> Returns a markdown-formatted string with multiple formatting, optionally escaping the contents. </summary>
		public static string Multiple(string text, bool escape = true, bool bold = false, bool italics = false, bool underline = false, bool strikeout = false)
		{
			string result = text;
			if (escape) result = Escape(result);
			if (bold) result = Bold(result, false);
			if (italics) result = Italics(result, false);
			if (underline) result = Underline(result, false);
			if (strikeout) result = Strikeout(result, false);
			return result;
		}
	}
}

{'fraction_non_alphanumeric': 0.1361675908810844, 'fraction_numerical': 0.0, 'mean_word_length': 4.490417136414882, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 45, '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': '88196', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1377, 'n_words': 470}