Skip to content

Commit

Permalink
Re-add files
Browse files Browse the repository at this point in the history
  • Loading branch information
tompazourek committed Dec 7, 2023
1 parent 4e636c4 commit f1c5df5
Show file tree
Hide file tree
Showing 29 changed files with 30,319 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
image: Visual Studio 2022

environment:
# Adds "+build.XXX" to MinVer's build metadata
MINVERBUILDMETADATA: build.%APPVEYOR_BUILD_NUMBER%
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true

# AppVeyor's displayed version, will get updated by MSBuild target
version: '{build}'

before_build:
- dotnet restore

build_script:
- dotnet build --no-restore --configuration Release -p:GeneratePackageOnBuild=true -p:ContinuousIntegrationBuild=true

test_script:
- dotnet test --no-build --configuration Release -p:CollectCoverage=true

after_test:
- choco install codecov
- pwsh: codecov --file @(Get-ChildItem -Path artifacts/coverage/*opencover*.xml -Recurse)

artifacts:
- path: artifacts/package/**/*.nupkg
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"jetbrains.resharper.globaltools": {
"version": "2023.3.0",
"commands": [
"jb"
]
}
}
}
412 changes: 412 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "nuget"
directory: "/"
schedule:
interval: "daily"
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
</PropertyGroup>
</Project>
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2022 Tomáš Pažourek

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
73 changes: 73 additions & 0 deletions NaturalSort.Extension.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31129.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NaturalSort.Extension", "src\NaturalSort.Extension\NaturalSort.Extension.csproj", "{805DAC58-665D-4154-8CE9-BC697BBAAB1E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NaturalSort.Extension.Tests", "tests\NaturalSort.Extension.Tests\NaturalSort.Extension.Tests.csproj", "{E293878F-BB7A-48EA-8116-84A0C97E8B89}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3CB395C4-6885-4C4A-8077-077B9A0DDE77}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{C76D3E79-B558-4F0E-99A8-029937E11337}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{58C86B88-A1B9-4654-818E-580B5B4AAACF}"
ProjectSection(SolutionItems) = preProject
.appveyor.yml = .appveyor.yml
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
format.ps1 = format.ps1
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{086BBC6C-34A8-44AC-8B22-8F7BA7C09790}"
ProjectSection(SolutionItems) = preProject
assets\logo_128.png = assets\logo_128.png
assets\logo_256.png = assets\logo_256.png
assets\logo_32.png = assets\logo_32.png
assets\logo_320.png = assets\logo_320.png
assets\logo_64.png = assets\logo_64.png
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NaturalSort.Extension.ConsoleSampleCore", "tests\NaturalSort.Extension.ConsoleSampleCore\NaturalSort.Extension.ConsoleSampleCore.csproj", "{BB20BD61-8CD6-418B-A8B5-F72FDE4872A7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NaturalSort.Extension.ConsoleSample", "tests\NaturalSort.Extension.ConsoleSample\NaturalSort.Extension.ConsoleSample.csproj", "{3E1D6E16-078C-43CB-9C8C-9D68143BC85A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{805DAC58-665D-4154-8CE9-BC697BBAAB1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{805DAC58-665D-4154-8CE9-BC697BBAAB1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{805DAC58-665D-4154-8CE9-BC697BBAAB1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{805DAC58-665D-4154-8CE9-BC697BBAAB1E}.Release|Any CPU.Build.0 = Release|Any CPU
{E293878F-BB7A-48EA-8116-84A0C97E8B89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E293878F-BB7A-48EA-8116-84A0C97E8B89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E293878F-BB7A-48EA-8116-84A0C97E8B89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E293878F-BB7A-48EA-8116-84A0C97E8B89}.Release|Any CPU.Build.0 = Release|Any CPU
{BB20BD61-8CD6-418B-A8B5-F72FDE4872A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BB20BD61-8CD6-418B-A8B5-F72FDE4872A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BB20BD61-8CD6-418B-A8B5-F72FDE4872A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BB20BD61-8CD6-418B-A8B5-F72FDE4872A7}.Release|Any CPU.Build.0 = Release|Any CPU
{3E1D6E16-078C-43CB-9C8C-9D68143BC85A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E1D6E16-078C-43CB-9C8C-9D68143BC85A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E1D6E16-078C-43CB-9C8C-9D68143BC85A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E1D6E16-078C-43CB-9C8C-9D68143BC85A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{805DAC58-665D-4154-8CE9-BC697BBAAB1E} = {3CB395C4-6885-4C4A-8077-077B9A0DDE77}
{E293878F-BB7A-48EA-8116-84A0C97E8B89} = {C76D3E79-B558-4F0E-99A8-029937E11337}
{BB20BD61-8CD6-418B-A8B5-F72FDE4872A7} = {C76D3E79-B558-4F0E-99A8-029937E11337}
{3E1D6E16-078C-43CB-9C8C-9D68143BC85A} = {C76D3E79-B558-4F0E-99A8-029937E11337}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B60C6359-6EC5-43C9-8D85-2506AFD1AE74}
EndGlobalSection
EndGlobal
4 changes: 4 additions & 0 deletions NaturalSort.Extension.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=NaturalSort_002EExtension_003A_0020Cleanup/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="NaturalSort.Extension: Cleanup"&gt;&lt;JsInsertSemicolon&gt;True&lt;/JsInsertSemicolon&gt;&lt;FormatAttributeQuoteDescriptor&gt;True&lt;/FormatAttributeQuoteDescriptor&gt;&lt;CorrectVariableKindsDescriptor&gt;True&lt;/CorrectVariableKindsDescriptor&gt;&lt;VariablesToInnerScopesDescriptor&gt;True&lt;/VariablesToInnerScopesDescriptor&gt;&lt;StringToTemplatesDescriptor&gt;True&lt;/StringToTemplatesDescriptor&gt;&lt;JsReformatCode&gt;True&lt;/JsReformatCode&gt;&lt;JsFormatDocComments&gt;True&lt;/JsFormatDocComments&gt;&lt;RemoveRedundantQualifiersTs&gt;True&lt;/RemoveRedundantQualifiersTs&gt;&lt;OptimizeImportsTs&gt;True&lt;/OptimizeImportsTs&gt;&lt;OptimizeReferenceCommentsTs&gt;True&lt;/OptimizeReferenceCommentsTs&gt;&lt;PublicModifierStyleTs&gt;True&lt;/PublicModifierStyleTs&gt;&lt;ExplicitAnyTs&gt;True&lt;/ExplicitAnyTs&gt;&lt;TypeAnnotationStyleTs&gt;True&lt;/TypeAnnotationStyleTs&gt;&lt;RelativePathStyleTs&gt;True&lt;/RelativePathStyleTs&gt;&lt;AsInsteadOfCastTs&gt;True&lt;/AsInsteadOfCastTs&gt;&lt;HtmlReformatCode&gt;True&lt;/HtmlReformatCode&gt;&lt;AspOptimizeRegisterDirectives&gt;True&lt;/AspOptimizeRegisterDirectives&gt;&lt;XMLReformatCode&gt;True&lt;/XMLReformatCode&gt;&lt;CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="False" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="True" ArrangeArgumentsStyle="False" ArrangeCodeBodyStyle="True" ArrangeVarStyle="True" /&gt;&lt;RemoveCodeRedundanciesVB&gt;True&lt;/RemoveCodeRedundanciesVB&gt;&lt;CssAlphabetizeProperties&gt;True&lt;/CssAlphabetizeProperties&gt;&lt;VBOptimizeImports&gt;True&lt;/VBOptimizeImports&gt;&lt;VBShortenReferences&gt;True&lt;/VBShortenReferences&gt;&lt;CSUseAutoProperty&gt;True&lt;/CSUseAutoProperty&gt;&lt;CSMakeFieldReadonly&gt;True&lt;/CSMakeFieldReadonly&gt;&lt;CSMakeAutoPropertyGetOnly&gt;True&lt;/CSMakeAutoPropertyGetOnly&gt;&lt;CSArrangeQualifiers&gt;True&lt;/CSArrangeQualifiers&gt;&lt;CSFixBuiltinTypeReferences&gt;True&lt;/CSFixBuiltinTypeReferences&gt;&lt;CssReformatCode&gt;True&lt;/CssReformatCode&gt;&lt;VBReformatCode&gt;True&lt;/VBReformatCode&gt;&lt;VBFormatDocComments&gt;True&lt;/VBFormatDocComments&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;CSharpFormatDocComments&gt;True&lt;/CSharpFormatDocComments&gt;&lt;/Profile&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue">NaturalSort.Extension: Cleanup</s:String>
</wpf:ResourceDictionary>
Binary file added NaturalSort.Extension.snk
Binary file not shown.
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# ![NaturalSort.Extension logo](https://raw.githubusercontent.com/tompazourek/NaturalSort.Extension/master/assets/logo_32.png) NaturalSort.Extension

*Extension method for `StringComparison` or any `IComparer<string>` that adds support for natural sorting (e.g. "abc1", "abc2", "abc10" instead of "abc1", "abc10", "abc2").*

[![Build status](https://img.shields.io/appveyor/ci/tompazourek/naturalsort-extension/master.svg)](https://ci.appveyor.com/project/tompazourek/naturalsort-extension)
[![Tests](https://img.shields.io/appveyor/tests/tompazourek/naturalsort-extension/master.svg)](https://ci.appveyor.com/project/tompazourek/naturalsort-extension/build/tests)
[![codecov](https://codecov.io/gh/tompazourek/NaturalSort.Extension/branch/master/graph/badge.svg?token=31JTU6543K)](https://codecov.io/gh/tompazourek/NaturalSort.Extension)
[![NuGet version](https://img.shields.io/nuget/v/NaturalSort.Extension.svg)](https://www.nuget.org/packages/NaturalSort.Extension/)
[![NuGet downloads](https://img.shields.io/nuget/dt/NaturalSort.Extension.svg)](https://www.nuget.org/packages/NaturalSort.Extension/)


The library is written in C# and released with an [MIT license](https://raw.githubusercontent.com/tompazourek/NaturalSort.Extension/master/LICENSE), so feel **free to fork** or **use commercially**.

**Any feedback is appreciated, please visit the [issues](https://github.com/tompazourek/NaturalSort.Extension/issues?state=open) page or send me an [e-mail](mailto:[email protected]).**

Download
--------

Binaries of the last build can be downloaded on the [AppVeyor CI page of the project](https://ci.appveyor.com/project/tompazourek/naturalsort-extension/build/artifacts).

The library is also [published on NuGet.org](https://www.nuget.org/packages/NaturalSort.Extension/), install using:

```
PM> Install-Package NaturalSort.Extension
```

<sup>NaturalSort.Extension is built for .NET Standard 1.3, .NET 6, and .NET 8 and is signed to allow use in projects that use strong names.</sup>

Usage
-----

The recommended method for best results is to create the comparer by using the `StringComparison` enum.

```csharp
var sequence = new[] { "img12.png", "img10.png", "img2.png", "img1.png" };
var ordered = sequence.OrderBy(x => x, StringComparison.OrdinalIgnoreCase.WithNaturalSort());
// ordered will be "img1.png", "img2.png", "img10.png", "img12.png"
```

For more information about natural sort order, see:

- [Natural sort order (Wikipedia)](https://en.wikipedia.org/wiki/Natural_sort_order)
- [Sorting for Humans: Natural Sort Order (Coding Horror)](https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/)

The `NaturalSortComparer` created using the extension method is a `IComparer<string>`, which you can use in all the places that accept `IComparer<string>` (e.g. `OrderBy`, `Array.Sort`, ...)

If you wish, you can be more explicit by not using the `.WithNaturalSort()` extension method, and using the constructor directly:

```csharp
new NaturalSortComparer(StringComparison.OrdinalIgnoreCase)
```

Note that if you are using a custom `IComparer<string>` (or `StringComparer`), you can also use that instead of the `StringComparison` enum. **However, if you use `StringComparison`, it should perform better as it avoids constructing substrings.**

Usage as collation in SQLite
----------------------------

If you're using [Microsoft.Data.Sqlite](https://docs.microsoft.com/en-us/dotnet/standard/data/sqlite/), it's also possible to use the extension as collation for use in your SQLite queries.

You can register the collation on a SQLite connection as follows (more info in [docs](https://docs.microsoft.com/en-us/dotnet/standard/data/sqlite/collation)):

```csharp
private static readonly NaturalSortComparer NaturalComparer = new(StringComparison.InvariantCultureIgnoreCase);

/* ... */

SqliteConnection conn;
conn.CreateCollation("NATURALSORT", (x, y) => NaturalComparer.Compare(x, y));
```

Then you can use the collation to achieve natural sorting in your SQL query:

```sql
SELECT * FROM Customers
ORDER BY Name COLLATE NATURALSORT;
```
Binary file added assets/logo_128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo_256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo_32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo_320.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo_64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions format.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dotnet tool restore
dotnet jb cleanupcode NaturalSort.Extension.sln --profile="NaturalSort.Extension: Cleanup"
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestFeature"
}
}
62 changes: 62 additions & 0 deletions src/NaturalSort.Extension/NaturalSort.Extension.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.0;net6.0;net8.0</TargetFrameworks>
<LangVersion>10</LangVersion>

<!-- Documents, symbols, validation -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AllowedOutputExtensionsInPackageBuildOutputFolder>.pdb;$(AllowedOutputExtensionsInPackageBuildOutputFolder)</AllowedOutputExtensionsInPackageBuildOutputFolder>
<EnablePackageValidation>true</EnablePackageValidation>

<!-- Strong-named assembly -->
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)../../NaturalSort.Extension.snk</AssemblyOriginatorKeyFile>

<!-- Package/Assembly metadata -->
<Authors>Tomáš Pažourek</Authors>
<Company>$(Authors)</Company>

<Copyright>Copyright $([System.DateTime]::Now.Year) $(Company)</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/tompazourek/NaturalSort.Extension</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
<PackageReleaseNotes>$(RepositoryUrl)/releases</PackageReleaseNotes>
<PackageIcon>logo_64.png</PackageIcon>
<PackageTags>natural-sort string-comparison stringcomparer sorting sort c-sharp extension-methods string comparer stringcomparison naturalsort</PackageTags>
<Description>Extension method for StringComparison that adds support for natural sorting (e.g. "abc1", "abc2", "abc10" instead of "abc1", "abc10", "abc2").</Description>
</PropertyGroup>

<ItemGroup>
<AssemblyAttribute Include="System.CLSCompliantAttribute">
<_Parameter1>true</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.InteropServices.ComVisibleAttribute">
<_Parameter1>false</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.InteropServices.GuidAttribute">
<_Parameter1>7828ef80-071e-4a8b-8a3a-d495ccb4214c</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MinVer" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<None Include="..\..\assets\logo_64.png" Pack="true" PackagePath="" />
<None Include="..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>

<Target Name="UpdateAppVeyorBuildVersion" AfterTargets="MinVer" Condition="'$(APPVEYOR)'=='true'">
<Exec Command="appveyor UpdateBuild -Version &quot;$(MinVerVersion)&quot;" />
</Target>
</Project>
Loading

0 comments on commit f1c5df5

Please sign in to comment.