Skip to content

Commit

Permalink
chore: update build and code for new language features
Browse files Browse the repository at this point in the history
  • Loading branch information
coder2000 committed Jun 30, 2024
1 parent 53d7fb2 commit efca915
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 175 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[*.cs]

# SA1010: Opening square brackets should be spaced correctly
dotnet_diagnostic.SA1010.severity = none

# SA1009: Closing parenthesis should be spaced correctly
dotnet_diagnostic.SA1009.severity = none
5 changes: 3 additions & 2 deletions Ubiety.Stringprep.Core.sln
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28315.86
# Visual Studio Version 17
VisualStudioVersion = 17.10.35013.160
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{4B9462B8-7C12-4FF8-B198-420A37AD1C34}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ubiety.Stringprep.Core", "src\Ubiety.Stringprep.Core\Ubiety.Stringprep.Core.csproj", "{4C27CBA0-8F85-4755-B426-182892E8B3AF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C669F553-ECC0-4C36-ACD2-35216BE7E292}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
CHANGELOG.md = CHANGELOG.md
README.md = README.md
Expand Down
31 changes: 15 additions & 16 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using Nuke.Common;
using Nuke.Common.CI;
Expand All @@ -11,36 +10,36 @@
using Nuke.Common.Tooling;
using Nuke.Common.Tools.Coverlet;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.SonarScanner;
using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Utilities.Collections;
using Nuke.Common.Tools.SonarScanner;
using Nuke.Common.Utilities;
using Nuke.Common.Utilities.Collections;
using System.Collections.Generic;
using static Nuke.Common.ChangeLog.ChangelogTasks;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.SonarScanner.SonarScannerTasks;

[GitHubActions(
"release",
GitHubActionsImage.WindowsLatest,
OnPushBranches = new[] { MasterBranch, ReleaseBranchPrefix + "/*"},
InvokedTargets = new[] { nameof(Test), nameof(Publish) },
ImportSecrets = new[] { nameof(NuGetKey) },
OnPushBranches = [MasterBranch, ReleaseBranchPrefix + "/*"],
InvokedTargets = [nameof(Test), nameof(Publish)],
ImportSecrets = [nameof(NuGetKey)],
EnableGitHubToken = true)]
[GitHubActions(
"continuous",
GitHubActionsImage.WindowsLatest,
GitHubActionsImage.UbuntuLatest,
GitHubActionsImage.MacOsLatest,
OnPushBranchesIgnore = new[] { MasterBranch, ReleaseBranchPrefix + "/*"},
OnPullRequestBranches = new[] { DevelopBranch },
OnPushBranchesIgnore = [MasterBranch, ReleaseBranchPrefix + "/*"],
OnPullRequestBranches = [DevelopBranch],
PublishArtifacts = false,
InvokedTargets = new[] { nameof(Test), nameof(Publish) },
InvokedTargets = [nameof(Test), nameof(Publish)],
EnableGitHubToken = true)]
[AppVeyor(
AppVeyorImage.UbuntuLatest,
AppVeyorImage.VisualStudioLatest,
InvokedTargets = new[] { nameof(Test), nameof(SonarEnd)},
InvokedTargets = [nameof(Test), nameof(SonarEnd)],
SkipTags = true,
AutoGenerate = true)]
[UnsetVisualStudioEnvironmentVariables]
Expand Down Expand Up @@ -70,9 +69,9 @@ class Build : NukeBuild
.Before(Restore)
.Executes(() =>
{
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
TestsDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
EnsureCleanDirectory(ArtifactsDirectory);
SourceDirectory.GlobDirectories("**/bin", "**/obj").DeleteDirectories();
TestsDirectory.GlobDirectories("**/bin", "**/obj").DeleteDirectories();
ArtifactsDirectory.CreateOrCleanDirectory();
});

Target Restore => _ => _
Expand Down Expand Up @@ -108,7 +107,7 @@ class Build : NukeBuild
.SetVersion(GitVersion.NuGetVersionV2)
.SetOpenCoverPaths(ArtifactsDirectory / "coverage.opencover.xml")
.SetProcessArgumentConfigurator(args => args.Add("/o:ubiety"))
.SetFramework("net5.0"));
.SetFramework("net8.0"));
});

Target SonarEnd => _ => _
Expand All @@ -119,7 +118,7 @@ class Build : NukeBuild
.Executes(() =>
{
SonarScannerEnd(_ => _
.SetFramework("net5.0"));
.SetFramework("net8.0"));
});

[Parameter] readonly bool Cover = true;
Expand Down
4 changes: 2 additions & 2 deletions build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<ItemGroup>
<PackageReference Include="Nuke.Common" Version="8.0.0" />
<PackageDownload Include="GitVersion.Tool" Version="[5.10.3]" />
<PackageDownload Include="dotnet-sonarscanner" Version="[5.7.2]" />
<PackageDownload Include="GitVersion.Tool" Version="[6.0.0-rc.1]" />
<PackageDownload Include="dotnet-sonarscanner" Version="[6.2.0]" />
</ItemGroup>

</Project>
27 changes: 10 additions & 17 deletions src/Ubiety.Stringprep.Core/Bidirectional/BidirectionalStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,17 @@ namespace Ubiety.Stringprep.Core.Bidirectional
/// <summary>
/// Bidirectional stringprep step.
/// </summary>
public class BidirectionalStep : IPreparationProcess
/// <remarks>
/// Initializes a new instance of the <see cref="BidirectionalStep" /> class.
/// </remarks>
/// <param name="prohibitedTable">Prohibited character table.</param>
/// <param name="ralTable">RandAL character table.</param>
/// <param name="lTable">L character table.</param>
public class BidirectionalStep(IValueRangeTable prohibitedTable, IValueRangeTable ralTable, IValueRangeTable lTable) : IPreparationProcess
{
private readonly IValueRangeTable _lTable;
private readonly IValueRangeTable _prohibitedTable;
private readonly IValueRangeTable _ralTable;

/// <summary>
/// Initializes a new instance of the <see cref="BidirectionalStep" /> class.
/// </summary>
/// <param name="prohibitedTable">Prohibited character table.</param>
/// <param name="ralTable">RandAL character table.</param>
/// <param name="lTable">L character table.</param>
public BidirectionalStep(IValueRangeTable prohibitedTable, IValueRangeTable ralTable, IValueRangeTable lTable)
{
_prohibitedTable = prohibitedTable;
_ralTable = ralTable;
_lTable = lTable;
}
private readonly IValueRangeTable _lTable = lTable;
private readonly IValueRangeTable _prohibitedTable = prohibitedTable;
private readonly IValueRangeTable _ralTable = ralTable;

/// <summary>
/// Run the stringprep step.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
*/

using System;
using System.Runtime.Serialization;

namespace Ubiety.Stringprep.Core.Exceptions
{
/// <summary>
/// Bidirectional format exception.
/// </summary>
[Serializable]
public class BidirectionalFormatException : Exception
{
/// <summary>
Expand Down Expand Up @@ -60,15 +58,5 @@ public BidirectionalFormatException(string message, Exception innerException)
: base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="BidirectionalFormatException" /> class.
/// </summary>
/// <param name="info">Serialization info.</param>
/// <param name="context">Streaming context.</param>
protected BidirectionalFormatException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
12 changes: 0 additions & 12 deletions src/Ubiety.Stringprep.Core/Exceptions/ProhibitedValueException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
*/

using System;
using System.Runtime.Serialization;

namespace Ubiety.Stringprep.Core.Exceptions
{
/// <summary>
/// Prohibited value exception.
/// </summary>
/// <inheritdoc />
[Serializable]
public class ProhibitedValueException : Exception
{
/// <summary>
Expand Down Expand Up @@ -70,15 +68,5 @@ public ProhibitedValueException(string message, Exception innerException)
: base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ProhibitedValueException"/> class.
/// </summary>
/// <param name="info">Serialization info.</param>
/// <param name="context">Streaming context.</param>
protected ProhibitedValueException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
17 changes: 3 additions & 14 deletions src/Ubiety.Stringprep.Core/MappingStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,8 @@ namespace Ubiety.Stringprep.Core
/// <summary>
/// Mapping processing step.
/// </summary>
public class MappingStep : IPreparationProcess
public class MappingStep(IMappingTable table) : IPreparationProcess
{
private readonly IMappingTable _table;

/// <summary>
/// Initializes a new instance of the <see cref="MappingStep"/> class.
/// </summary>
/// <param name="table">Mapping table to use for processing.</param>
public MappingStep(IMappingTable table)
{
_table = table;
}

/// <summary>
/// Run the step.
/// </summary>
Expand All @@ -55,9 +44,9 @@ public string Run(string input)
var sb = new StringBuilder();
foreach (var c in input)
{
if (_table.HasReplacement(c))
if (table.HasReplacement(c))
{
foreach (var r in _table.GetReplacement(c))
foreach (var r in table.GetReplacement(c))
{
sb.Append(Convert.ToChar(r));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Ubiety.Stringprep.Core/MappingTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class MappingTable : IMappingTable
/// <returns>Mapping table instance.</returns>
public static IMappingTable Create(int[] valueTable, int replacement)
{
return Create(valueTable, new[] { replacement });
return Create(valueTable, [replacement]);
}

/// <summary>
Expand Down Expand Up @@ -73,7 +73,7 @@ public static IMappingTable Create(params IDictionary<int, int[]>[] baseTables)
/// <returns>Mapping table builder instance.</returns>
public static IMappingTableBuilder Build(int[] valueTable, int replacement)
{
return Build(valueTable, new[] { replacement });
return Build(valueTable, [replacement]);
}

/// <summary>
Expand Down
38 changes: 15 additions & 23 deletions src/Ubiety.Stringprep.Core/MappingTableBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,16 @@ namespace Ubiety.Stringprep.Core
/// <summary>
/// Mapping table builder.
/// </summary>
internal class MappingTableBuilder : IMappingTableBuilder
/// <remarks>
/// Initializes a new instance of the <see cref="MappingTableBuilder"/> class.
/// </remarks>
/// <param name="baseTables">Base value tables.</param>
internal class MappingTableBuilder(params IDictionary<int, int[]>[] baseTables) : IMappingTableBuilder
{
private readonly List<IDictionary<int, int[]>> _baseTables;
private readonly List<IDictionary<int, int[]>> _inclusions;
private readonly List<int> _removals;
private readonly List<(List<int> values, int[] replacements)> _valueRangeBaseTables;

/// <summary>
/// Initializes a new instance of the <see cref="MappingTableBuilder"/> class.
/// </summary>
/// <param name="baseTables">Base value tables.</param>
public MappingTableBuilder(params IDictionary<int, int[]>[] baseTables)
{
_baseTables = baseTables.ToList();
_valueRangeBaseTables = new List<(List<int>, int[])>();
_inclusions = new List<IDictionary<int, int[]>>();
_removals = new List<int>();
}
private readonly List<IDictionary<int, int[]>> _baseTables = [.. baseTables];
private readonly List<IDictionary<int, int[]>> _inclusions = [];
private readonly List<int> _removals = [];
private readonly List<(List<int> values, int[] replacements)> _valueRangeBaseTables = [];

/// <summary>
/// Add value range table to mapping.
Expand All @@ -60,7 +52,7 @@ public MappingTableBuilder(params IDictionary<int, int[]>[] baseTables)
/// <returns>Mapping table builder instance.</returns>
public IMappingTableBuilder WithValueRangeTable(int[] values, int replacement)
{
return WithValueRangeTable(values, new[] { replacement });
return WithValueRangeTable(values, [replacement]);
}

/// <summary>
Expand Down Expand Up @@ -115,22 +107,22 @@ public IMappingTableBuilder Remove(int removeValue)
/// <exception cref="InvalidOperationException">Thrown when no tables are provided.</exception>
public IMappingTable Compile()
{
if (!_baseTables.Any() && !_inclusions.Any() && !_valueRangeBaseTables.Any())
if (_baseTables.Count == 0 && _inclusions.Count == 0 && _valueRangeBaseTables.Count == 0)
{
throw new InvalidOperationException("At least one table must be provided");
}

var mappingTables = new List<IMappingTable>
{
new DictionaryMappingTable(MappingTableCompiler.Compile(
_baseTables.ToArray(),
_inclusions.ToArray(),
_removals.ToArray())),
[.. _baseTables],
[.. _inclusions],
[.. _removals])),
};

mappingTables.AddRange(
from t in _valueRangeBaseTables
let valueRangeTable = ValueRangeCompiler.Compile(new[] { t.values }, Array.Empty<int>().ToList(), _removals)
let valueRangeTable = ValueRangeCompiler.Compile([t.values], [], _removals)
select new ValueRangeMappingTable(new ValueRangeTable(valueRangeTable), t.replacements));

return new CompositeMappingTable(mappingTables);
Expand Down
10 changes: 5 additions & 5 deletions src/Ubiety.Stringprep.Core/MappingTableCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static IDictionary<int, int[]> Compile(
return DoRemove(DoInclude(DoCombine(baseTables), inclusions), removals);
}

private static IDictionary<int, int[]> DoRemove(IDictionary<int, int[]> dict, IEnumerable<int> removals)
private static SortedDictionary<int, int[]> DoRemove(SortedDictionary<int, int[]> dict, IEnumerable<int> removals)
{
foreach (var key in removals)
{
Expand All @@ -63,8 +63,8 @@ private static IDictionary<int, int[]> DoRemove(IDictionary<int, int[]> dict, IE
return dict;
}

private static IDictionary<int, int[]> DoInclude(
IDictionary<int, int[]> dict,
private static SortedDictionary<int, int[]> DoInclude(
SortedDictionary<int, int[]> dict,
IEnumerable<IDictionary<int, int[]>> inclusions)
{
foreach (var t in inclusions)
Expand All @@ -83,11 +83,11 @@ private static IDictionary<int, int[]> DoInclude(
return dict;
}

private static IDictionary<int, int[]> DoCombine(IReadOnlyList<IDictionary<int, int[]>> baseTables)
private static SortedDictionary<int, int[]> DoCombine(IReadOnlyList<IDictionary<int, int[]>> baseTables)
{
if (baseTables.Count == 0)
{
return new SortedDictionary<int, int[]>();
return [];
}

var combined = new SortedDictionary<int, int[]>(baseTables[0]);
Expand Down
Loading

0 comments on commit efca915

Please sign in to comment.