Repository: files-community/Files
File: src/Files.App/Helpers/NaturalStringComparer.cs (C#)

Code before:
					if (charCompareResult != 0) return charCompareResult;
				}

				return x.Length.CompareTo(y.Length);
			}

			private static int GetExtensionPosition(ReadOnlySpan<char> text)
			{
				// Find the last period that's not at the beginning
				for (int i = text.Length - 1; i > 0; i--)
				{
					if (text[i] == '.')
						return i;
				}
				return -1;
			}

			private static bool IsIgnorableSeparator(ReadOnlySpan<char> span, int index)
			{
    			if (span[index] != '-' && span[index] != '_') return false;

    			// Check bounds before accessing span[index + 1] or span[index - 1]
    			if (index == 0) return span.Length > 1 && char.IsLetterOrDigit(span[index + 1]);
    			if (index == span.Length - 1) return span.Length > 1 && char.IsLetterOrDigit(span[index - 1]);

    			return char.IsLetterOrDigit(span[index - 1]) && char.IsLetterOrDigit(span[index + 1]);
			}


		    private static ReadOnlySpan<char> GetNumber(ReadOnlySpan<char> span, out ReadOnlySpan<char> number)
		    {
		        var i = 0;
		        while (i < span.Length && char.IsDigit(span[i]))
		        {
		            i++;
		        }

		        number = span.Slice(0, i);
		        return span.Slice(i);
		    }

		    private static int CompareNumValues(ReadOnlySpan<char> numValue1, ReadOnlySpan<char> numValue2)
		    {
		        var num1AsSpan = numValue1.TrimStart('0');
		        var num2AsSpan = numValue2.TrimStart('0');

		        if (num1AsSpan.Length < num2AsSpan.Length) return -1;

		        if (num1AsSpan.Length > num2AsSpan.Length) return 1;

		        var compareResult = num1AsSpan.CompareTo(num2AsSpan, StringComparison.Ordinal);

Review comment (suggestion):
```suggestion
				if (span[index] != '-' && span[index] != '_') return false;

				// Check bounds before accessing span[index + 1] or span[index - 1]
				if (index == 0) return span.Length > 1 && char.IsLetterOrDigit(span[index + 1]);
				if (index == span.Length - 1) return span.Length > 1 && char.IsLetterOrDigit(span[index - 1]);

				return char.IsLetterOrDigit(span[index - 1]) && char.IsLetterOrDigit(span[index + 1]);
```

Code after:
					if (charCompareResult != 0) return charCompareResult;
				}

				return x.Length.CompareTo(y.Length);
			}

			private static int GetExtensionPosition(ReadOnlySpan<char> text)
			{
				// Find the last period that's not at the beginning
				for (int i = text.Length - 1; i > 0; i--)
				{
					if (text[i] == '.')
						return i;
				}
				return -1;
			}

			private static bool IsIgnorableSeparator(ReadOnlySpan<char> span, int index)
			{
				if (span[index] != '-' && span[index] != '_') return false;

				// Check bounds before accessing span[index + 1] or span[index - 1]
				if (index == 0) return span.Length > 1 && char.IsLetterOrDigit(span[index + 1]);
				if (index == span.Length - 1) return span.Length > 1 && char.IsLetterOrDigit(span[index - 1]);

				return char.IsLetterOrDigit(span[index - 1]) && char.IsLetterOrDigit(span[index + 1]);
			}


		    private static ReadOnlySpan<char> GetNumber(ReadOnlySpan<char> span, out ReadOnlySpan<char> number)
		    {
		        var i = 0;
		        while (i < span.Length && char.IsDigit(span[i]))
		        {
		            i++;
		        }

		        number = span.Slice(0, i);
		        return span.Slice(i);
		    }

		    private static int CompareNumValues(ReadOnlySpan<char> numValue1, ReadOnlySpan<char> numValue2)
		    {
		        var num1AsSpan = numValue1.TrimStart('0');
		        var num2AsSpan = numValue2.TrimStart('0');

		        if (num1AsSpan.Length < num2AsSpan.Length) return -1;

		        if (num1AsSpan.Length > num2AsSpan.Length) return 1;

		        var compareResult = num1AsSpan.CompareTo(num2AsSpan, StringComparison.Ordinal);