Use Ordinal comparisons

This commit is contained in:
Ottermandias 2022-06-20 18:26:40 +02:00
parent 47cfaf4da2
commit 6ebf550284
14 changed files with 19 additions and 20 deletions

@ -1 +1 @@
Subproject commit 6ce8ca816678e7a363f9f4a6f43f009f8d79c070
Subproject commit fa83386909ad0034f5ed7ea90d8bcedf6e8ba748

View file

@ -72,9 +72,9 @@ public readonly struct FullPath : IComparable, IEquatable< FullPath >
=> obj switch
{
FullPath p => InternalName?.CompareTo( p.InternalName ) ?? -1,
FileInfo f => string.Compare( FullName, f.FullName, StringComparison.InvariantCultureIgnoreCase ),
FileInfo f => string.Compare( FullName, f.FullName, StringComparison.OrdinalIgnoreCase ),
Utf8String u => InternalName?.CompareTo( u ) ?? -1,
string s => string.Compare( FullName, s, StringComparison.InvariantCultureIgnoreCase ),
string s => string.Compare( FullName, s, StringComparison.OrdinalIgnoreCase ),
_ => -1,
};

View file

@ -38,14 +38,14 @@ public sealed unsafe partial class Utf8String : IDisposable
// Can throw ArgumentOutOfRange if length is higher than max length.
// The Crc32 will be computed.
public static Utf8String FromByteStringUnsafe( byte* path, int length, bool isNullTerminated, bool? isLower = null, bool? isAscii = false )
=> FromSpanUnsafe( new ReadOnlySpan< byte >( path, length ), isNullTerminated, isLower, isAscii );
=> new Utf8String().Setup( path, length, null, isNullTerminated, false, isLower, isAscii );
// Same as above, just with a span.
public static Utf8String FromSpanUnsafe( ReadOnlySpan< byte > path, bool isNullTerminated, bool? isLower = null, bool? isAscii = false )
{
fixed( byte* ptr = path )
{
return new Utf8String().Setup( ptr, path.Length, null, isNullTerminated, false, isLower, isAscii );
return FromByteStringUnsafe( ptr, path.Length, isNullTerminated, isLower, isAscii );
}
}

View file

@ -70,8 +70,8 @@ public readonly struct GamePath : IComparable
{
return rhs switch
{
string path => string.Compare( _path, path, StringComparison.InvariantCulture ),
GamePath path => string.Compare( _path, path._path, StringComparison.InvariantCulture ),
string path => string.Compare( _path, path, StringComparison.Ordinal ),
GamePath path => string.Compare( _path, path._path, StringComparison.Ordinal ),
_ => -1,
};
}

View file

@ -48,7 +48,7 @@ public partial class ModCollection
// Obtain a collection case-independently by name.
public bool ByName( string name, [NotNullWhen( true )] out ModCollection? collection )
=> _collections.FindFirst( c => string.Equals( c.Name, name, StringComparison.InvariantCultureIgnoreCase ), out collection );
=> _collections.FindFirst( c => string.Equals( c.Name, name, StringComparison.OrdinalIgnoreCase ), out collection );
// Default enumeration skips the empty collection.
public IEnumerator< ModCollection > GetEnumerator()

View file

@ -89,7 +89,7 @@ public partial class ModCollection
}
var iterator = ResolvedFiles
.Where( f => string.Equals( f.Value.Path.FullName, needle, StringComparison.InvariantCultureIgnoreCase ) )
.Where( f => string.Equals( f.Value.Path.FullName, needle, StringComparison.OrdinalIgnoreCase ) )
.Select( kvp => kvp.Key );
// For files that are not rooted, try to add themselves.

View file

@ -88,7 +88,7 @@ public class ResourceLogger : IDisposable
private string? Match( Utf8String data )
{
var s = data.ToString();
return Filter.Length == 0 || ( _filterRegex?.IsMatch( s ) ?? s.Contains( Filter, StringComparison.InvariantCultureIgnoreCase ) )
return Filter.Length == 0 || ( _filterRegex?.IsMatch( s ) ?? s.Contains( Filter, StringComparison.OrdinalIgnoreCase ) )
? s
: null;
}

View file

@ -284,7 +284,7 @@ public sealed partial class Mod
var path = newName.RemoveInvalidPathSymbols();
if( path.Length == 0
|| mod.Groups.Any( o => !ReferenceEquals( o, group )
&& string.Equals( o.Name.RemoveInvalidPathSymbols(), path, StringComparison.InvariantCultureIgnoreCase ) ) )
&& string.Equals( o.Name.RemoveInvalidPathSymbols(), path, StringComparison.OrdinalIgnoreCase ) ) )
{
if( message )
{

View file

@ -26,7 +26,7 @@ public sealed partial class Mod
// Also checks if the directory is available and tries to create it if it is not.
private void SetBaseDirectory( string newPath, bool firstTime )
{
if( !firstTime && string.Equals( newPath, Penumbra.Config.ModDirectory, StringComparison.InvariantCultureIgnoreCase ) )
if( !firstTime && string.Equals( newPath, Penumbra.Config.ModDirectory, StringComparison.OrdinalIgnoreCase ) )
{
return;
}

View file

@ -78,7 +78,7 @@ public class MainClass : IDalamudPlugin
{
#if !DEBUG
var checkedDirectory = Dalamud.PluginInterface.AssemblyLocation.Directory?.Parent?.Parent?.Name;
var ret = checkedDirectory?.Equals( "installedPlugins", StringComparison.InvariantCultureIgnoreCase ) ?? false;
var ret = checkedDirectory?.Equals( "installedPlugins", StringComparison.OrdinalIgnoreCase ) ?? false;
if (!ret)
PluginLog.Error($"Penumbra is not correctly installed. Application loaded from \"{Dalamud.PluginInterface.AssemblyLocation.Directory!.FullName}\"." );
return !ret;
@ -310,12 +310,12 @@ public class Penumbra : IDisposable
ShutdownWebServer();
}
public bool SetCollection( string type, string collectionName )
public static bool SetCollection( string type, string collectionName )
{
type = type.ToLowerInvariant();
collectionName = collectionName.ToLowerInvariant();
var collection = string.Equals( collectionName, ModCollection.Empty.Name, StringComparison.InvariantCultureIgnoreCase )
var collection = string.Equals( collectionName, ModCollection.Empty.Name, StringComparison.OrdinalIgnoreCase )
? ModCollection.Empty
: CollectionManager[ collectionName ];
if( collection == null )

View file

@ -25,7 +25,7 @@ public partial class ModEditWindow
private int _folderSkip = 0;
private bool CheckFilter( Mod.Editor.FileRegistry registry )
=> _fileFilter.IsEmpty || registry.File.FullName.Contains( _fileFilter.Lower, StringComparison.InvariantCultureIgnoreCase );
=> _fileFilter.IsEmpty || registry.File.FullName.Contains( _fileFilter.Lower, StringComparison.OrdinalIgnoreCase );
private bool CheckFilter( (Mod.Editor.FileRegistry, int) p )
=> CheckFilter( p.Item1 );

View file

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
@ -22,7 +21,7 @@ public partial class ModFileSystemSelector
public ColorId Color;
}
private const StringComparison IgnoreCase = StringComparison.InvariantCultureIgnoreCase;
private const StringComparison IgnoreCase = StringComparison.OrdinalIgnoreCase;
private LowerString _modFilter = LowerString.Empty;
private int _filterType = -1;
private ModFilter _stateFilter = ModFilterExtensions.UnfilteredStateMods;

View file

@ -26,7 +26,7 @@ public partial class ConfigWindow
bool FilterChangedItem( KeyValuePair< string, (SingleArray< IMod >, object?) > item )
=> ( _changedItemFilter.IsEmpty
|| ChangedItemName( item.Key, item.Value.Item2 )
.Contains( _changedItemFilter.Lower, StringComparison.InvariantCultureIgnoreCase ) )
.Contains( _changedItemFilter.Lower, StringComparison.OrdinalIgnoreCase ) )
&& ( _changedItemModFilter.IsEmpty || item.Value.Item1.Any( m => m.Name.Contains( _changedItemModFilter ) ) );
void DrawChangedItemColumn( KeyValuePair< string, (SingleArray< IMod >, object?) > item )

View file

@ -87,7 +87,7 @@ public partial class ConfigWindow
{
// Filter unwanted names.
if( _resourceManagerFilter.Length != 0
&& !r->FileName.ToString().Contains( _resourceManagerFilter, StringComparison.InvariantCultureIgnoreCase ) )
&& !r->FileName.ToString().Contains( _resourceManagerFilter, StringComparison.OrdinalIgnoreCase ) )
{
return;
}