<commit_before>﻿// Based on the C version by <NAME>.

using System;
using System.Collections.Generic;

using JetBrains.Annotations;

namespace CodeJam
{
	/// <summary>
	/// String comparisons using a "natural order" algorithm.
	/// </summary>
	[PublicAPI]
	public class NaturalOrderStringComparer : IComparer<string>
    {
		/// <summary>
		/// Gets a <see cref="NaturalOrderStringComparer"/> object
		/// that performs a string comparison using a "natural order" algorithm.
		/// </summary>
		/// <returns>
		/// A <see cref="NaturalOrderStringComparer"/> object
		/// that performs a string comparison using a "natural order" algorithm.
		/// </returns>
		[NotNull]
		public static NaturalOrderStringComparer Comparer => new NaturalOrderStringComparer(false);

		/// <summary>
		/// Gets a <see cref="NaturalOrderStringComparer"/> object
		/// that performs a case-insensitive string comparison using a "natural order" algorithm.
		/// </summary>
		/// <returns>
		/// A <see cref="NaturalOrderStringComparer"/> object
		/// that performs a case-insensitive string comparison using a "natural order" algorithm.
		/// </returns>
		[NotNull]
		public static NaturalOrderStringComparer IgnoreCaseComparer => new NaturalOrderStringComparer(true);

		/// <summary>
		/// Gets a <see cref="Comparison{T}"/> delegate that performs a string comparison using a "natural order" algorithm.
		/// </summary>
		/// <returns>
		/// A <see cref="Comparison{T}"/> delegate that performs a string comparison using a "natural order" algorithm.
		/// </returns>
		[NotNull]
		public static Comparison<string> Comparision => (a, b) => Compare(a, b, false);

		/// <summary>
		/// Gets a <see cref="Comparison{T}"/> delegate that performs a case-insensitive
		/// string comparison using a "natural order" algorithm.
		/// </summary>
		/// <returns>
		/// A <see cref="Comparison{T}"/> delegate that performs a case-insensitive
		/// string comparison using a "natural order" algorithm.
		/// </returns>
		[NotNull]
		public static Comparison<string> IgnoreCaseComparision => (a, b) => Compare(a, b, true);

		/// <summary>
		/// true to ignore case during the comparison; otherwise, false.
		/// </summary>
		private readonly bool _ignoreCase;

		/// <summary>
		/// Initializes a new instance of the <see cref="NaturalOrderStringComparer"/> class.
		/// </summary>
		private NaturalOrderStringComparer(bool ignoreCase)
		{
			_ignoreCase = ignoreCase;
		}

		/// <summary>
		/// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
		/// </summary>
		/// <param name="a">The first object to compare.</param>
		/// <param name="b">The second object to compare.</param>
		/// <returns>
		/// A signed integer that indicates the relative values of <paramref name="a"/> and <paramref name="b"/>,
		/// as shown in the following table.
		/// Value Meaning Less than zero <paramref name="a"/> is less than <paramref name="b"/>.
		/// Zero <paramref name="a"/> equals <paramref name="b"/>.
		/// Greater than zero <paramref name="a"/> is greater than <paramref name="b"/>.
		/// </returns>
		[Pure]
		public static int Compare([CanBeNull] string a, [CanBeNull] string b) => Compare(a, b, false);

		/// <summary>
		/// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
		/// </summary>
		/// <param name="a">The first object to compare.</param>
		/// <param name="b">The second object to compare.</param>
		/// <param name="ignoreCase">true to ignore case during the comparison; otherwise, false.</param>
		/// <returns>
		/// A signed integer that indicates the relative values of <paramref name="a"/> and <paramref name="b"/>,
		/// as shown in the following table.
		/// Value Meaning Less than zero <paramref name="a"/> is less than <paramref name="b"/>.
		/// Zero <paramref name="a"/> equals <paramref name="b"/>.
		/// Greater than zero <paramref name="a"/> is greater than <paramref name="b"/>.
		/// </returns>
		[Pure]
		public static int Compare([CanBeNull] string a, [CanBeNull] string b, bool ignoreCase)
		{
			if (ReferenceEquals(a, b))
				return 0;

			if (a == null)
				return -1;

			if (b == null)
				return 1;

			// only count the number of zeroes leading the last number compared
			var ia = SkipLeadingZeroesAndWhitespaces(a, 0);
			var ib = SkipLeadingZeroesAndWhitespaces(b, 0);

			while (true)
			{
				var ca = CharAt(a, ia);
				var cb = CharAt(b, ib);

				// process run of digits
				if (ca.IsDigit() && cb.IsDigit())
				{
					var result = CompareNumerical(a, b, ignoreCase, ref ia, ref ib);
					if (result != 0)<commit_msg>Cleanup<commit_after>﻿// Based on the C version by <NAME>.

using System;
using System.Collections.Generic;

using JetBrains.Annotations;

namespace CodeJam
{
	/// <summary>
	/// String comparisons using a "natural order" algorithm.
	/// </summary>
	[PublicAPI]
	public class NaturalOrderStringComparer : IComparer<string>
    {
		/// <summary>
		/// Gets a <see cref="NaturalOrderStringComparer"/> object
		/// that performs a string comparison using a "natural order" algorithm.
		/// </summary>
		/// <returns>
		/// A <see cref="NaturalOrderStringComparer"/> object
		/// that performs a string comparison using a "natural order" algorithm.
		/// </returns>
		[NotNull]
		public static NaturalOrderStringComparer Comparer => new NaturalOrderStringComparer(false);

		/// <summary>
		/// Gets a <see cref="NaturalOrderStringComparer"/> object
		/// that performs a case-insensitive string comparison using a "natural order" algorithm.
		/// </summary>
		/// <returns>
		/// A <see cref="NaturalOrderStringComparer"/> object
		/// that performs a case-insensitive string comparison using a "natural order" algorithm.
		/// </returns>
		[NotNull]
		public static NaturalOrderStringComparer IgnoreCaseComparer => new NaturalOrderStringComparer(true);

		/// <summary>
		/// Gets a <see cref="Comparison{T}"/> delegate that performs a string comparison using a "natural order" algorithm.
		/// </summary>
		/// <returns>
		/// A <see cref="Comparison{T}"/> delegate that performs a string comparison using a "natural order" algorithm.
		/// </returns>
		[NotNull]
		public static Comparison<string> Comparision => (a, b) => Compare(a, b, false);

		/// <summary>
		/// Gets a <see cref="Comparison{T}"/> delegate that performs a case-insensitive
		/// string comparison using a "natural order" algorithm.
		/// </summary>
		/// <returns>
		/// A <see cref="Comparison{T}"/> delegate that performs a case-insensitive
		/// string comparison using a "natural order" algorithm.
		/// </returns>
		[NotNull]
		public static Comparison<string> IgnoreCaseComparision => (a, b) => Compare(a, b, true);

		/// <summary>
		/// true to ignore case during the comparison; otherwise, false.
		/// </summary>
		private readonly bool _ignoreCase;

		/// <summary>
		/// Initializes a new instance of the <see cref="NaturalOrderStringComparer"/> class.
		/// </summary>
		private NaturalOrderStringComparer(bool ignoreCase)
		{
			_ignoreCase = ignoreCase;
		}

		/// <summary>
		/// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
		/// </summary>
		/// <param name="a">The first object to compare.</param>
		/// <param name="b">The second object to compare.</param>
		/// <returns>
		/// A signed integer that indicates the relative values of <paramref name="a"/> and <paramref name="b"/>,
		/// as shown in the following table.
		/// Value Meaning Less than zero <paramref name="a"/> is less than <paramref name="b"/>.
		/// Zero <paramref name="a"/> equals <paramref name="b"/>.
		/// Greater than zero <paramref name="a"/> is greater than <paramref name="b"/>.
		/// </returns>
		[Pure]
		public static int Compare([CanBeNull] string a, [CanBeNull] string b) => Compare(a, b, false);

		/// <summary>
		/// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
		/// </summary>
		/// <param name="a">The first object to compare.</param>
		/// <param name="b">The second object to compare.</param>
		/// <param name="ignoreCase">true to ignore case during the comparison; otherwise, false.</param>
		/// <returns>
		/// A signed integer that indicates the relative values of <paramref name="a"/> and <paramref name="b"/>,
		/// as shown in the following table.
		/// Value Meaning Less than zero <paramref name="a"/> is less than <paramref name="b"/>.
		/// Zero <paramref name="a"/> equals <paramref name="b"/>.
		/// Greater than zero <paramref name="a"/> is greater than <paramref name="b"/>.
		/// </returns>
		[Pure]
		public static int Compare([CanBeNull] string a, [CanBeNull] string b, bool ignoreCase)
		{
			if (a == b)
				return 0;

			if (a == null)
				return -1;

			if (b == null)
				return 1;

			// only count the number of zeroes leading the last number compared
			var ia = SkipLeadingZeroesAndWhitespaces(a, 0);
			var ib = SkipLeadingZeroesAndWhitespaces(b, 0);

			while (true)
			{
				var ca = CharAt(a, ia);
				var cb = CharAt(b, ib);

				// process run of digits
				if (ca.IsDigit() && cb.IsDigit())
				{
					var result = CompareNumerical(a, b, ignoreCase, ref ia, ref ib);
					if (result != 0)
{'fraction_non_alphanumeric': 0.1485659039639059, 'fraction_numerical': 0.0012890750886239124, 'mean_word_length': 3.1674127126230975, 'pattern_counts': {'":': 0, '<': 141, '<?xml version=': 0, '>': 155, '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': '4901062', 'n_tokens_mistral': 3021, 'n_tokens_neox': 2677, 'n_words': 993}