Skip to content

Commit

Permalink
Changed the language version to the latest
Browse files Browse the repository at this point in the history
  • Loading branch information
YohDeadfall committed Apr 14, 2024
1 parent 90a9a1d commit 326c8e3
Show file tree
Hide file tree
Showing 15 changed files with 446 additions and 458 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Build
run: |
dotnet build --configuration Release
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>

<LangVersion>9.0</LangVersion>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<TargetFramework>netstandard2.0</TargetFramework>
Expand Down
41 changes: 20 additions & 21 deletions benches/Benchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

namespace Yoh.Text.Json.NamingPolicies.Benchmarks
namespace Yoh.Text.Json.NamingPolicies.Benchmarks;

[MemoryDiagnoser]
public class Benchmarks
{
[MemoryDiagnoser]
public class Benchmarks
{
public static void Main(string[] args) =>
BenchmarkRunner.Run<Benchmarks>();
public static void Main(string[] args) =>
BenchmarkRunner.Run<Benchmarks>();

[Params("XMLHttpRequest", "ATowelItSaysIsAboutTheMostMassivelyUsefulThingAnInterstellarHitchhikerCanHave_PartlyItHasGreatPracticalValue_YouCanWrapItAroundYouForWarmthAsYouBoundAcrossTheColdMoonsOfJaglanBeta_YouCanLieOnItOnTheBrilliantMarbleSandedBeachesOfSantraginusVInhalingTheHeadySeaVapors_YouCanSleepUnderItBeneathTheStarsWhichShineSoRedlyOnTheDesertWorldOfKakrafoon_UseItToSailAMiniraftDownTheSlowHeavyRiverMoth_WetItForUseInHandToHandCombat_WrapItRoundYourHeadToWardOffNoxiousFumesOrAvoidTheGazeOfTheRavenousBugblatterBeastOfTraalAMindBogglinglyStupidAnimal_ItAssumesThatIfYouCantSeeItItCantSeeYouDaftAsABrushButVeryVeryRavenous_YouCanWaveYourTowelInEmergenciesAsADistressSignalAndOfCourseDryYourselfOfWithItIfItStillSeemsToBeCleanEnough")]
public string Name { get; set; } = string.Empty;
[Params("XMLHttpRequest", "ATowelItSaysIsAboutTheMostMassivelyUsefulThingAnInterstellarHitchhikerCanHave_PartlyItHasGreatPracticalValue_YouCanWrapItAroundYouForWarmthAsYouBoundAcrossTheColdMoonsOfJaglanBeta_YouCanLieOnItOnTheBrilliantMarbleSandedBeachesOfSantraginusVInhalingTheHeadySeaVapors_YouCanSleepUnderItBeneathTheStarsWhichShineSoRedlyOnTheDesertWorldOfKakrafoon_UseItToSailAMiniraftDownTheSlowHeavyRiverMoth_WetItForUseInHandToHandCombat_WrapItRoundYourHeadToWardOffNoxiousFumesOrAvoidTheGazeOfTheRavenousBugblatterBeastOfTraalAMindBogglinglyStupidAnimal_ItAssumesThatIfYouCantSeeItItCantSeeYouDaftAsABrushButVeryVeryRavenous_YouCanWaveYourTowelInEmergenciesAsADistressSignalAndOfCourseDryYourselfOfWithItIfItStillSeemsToBeCleanEnough")]
public string Name { get; set; } = string.Empty;

[Benchmark]
public string SnakeLowerCase() =>
JsonNamingPolicies.SnakeCaseLower.ConvertName(Name);
[Benchmark]
public string SnakeLowerCase() =>
JsonNamingPolicies.SnakeCaseLower.ConvertName(Name);

[Benchmark]
public string SnakeUpperCase() =>
JsonNamingPolicies.SnakeCaseUpper.ConvertName(Name);
[Benchmark]
public string SnakeUpperCase() =>
JsonNamingPolicies.SnakeCaseUpper.ConvertName(Name);

[Benchmark]
public string KebabLowerCase() =>
JsonNamingPolicies.KebabCaseLower.ConvertName(Name);
[Benchmark]
public string KebabLowerCase() =>
JsonNamingPolicies.KebabCaseLower.ConvertName(Name);

[Benchmark]
public string KebabUpperCase() =>
JsonNamingPolicies.KebabCaseUpper.ConvertName(Name);
}
[Benchmark]
public string KebabUpperCase() =>
JsonNamingPolicies.KebabCaseUpper.ConvertName(Name);
}
19 changes: 9 additions & 10 deletions src/JsonCamelCaseNamingPolicy.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
using System;

namespace Yoh.Text.Json.NamingPolicies
namespace Yoh.Text.Json.NamingPolicies;

internal sealed class JsonCamelCaseNamingPolicy : JsonNamingPolicyBase
{
internal sealed class JsonCamelCaseNamingPolicy : JsonNamingPolicyBase
protected override int TryWriteWord(bool first, ReadOnlySpan<char> word, Span<char> destination)
{
protected override int TryWriteWord(bool first, ReadOnlySpan<char> word, Span<char> destination)
var written = word.ToLowerInvariant(destination);
if (written > 0 && !first)
{
var written = word.ToLowerInvariant(destination);
if (written > 0 && !first)
{
destination[0] = char.ToUpperInvariant(destination[0]);
}

return written;
destination[0] = char.ToUpperInvariant(destination[0]);
}

return written;
}
}
11 changes: 5 additions & 6 deletions src/JsonConstants.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace Yoh.Text.Json.NamingPolicies
namespace Yoh.Text.Json.NamingPolicies;

internal static class JsonConstants
{
internal static class JsonConstants
{
public const int StackallocByteThreshold = 256;
public const int StackallocCharThreshold = StackallocByteThreshold / 2;
}
public const int StackallocByteThreshold = 256;
public const int StackallocCharThreshold = StackallocByteThreshold / 2;
}
11 changes: 5 additions & 6 deletions src/JsonKebabCaseLowerNamingPolicy.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace Yoh.Text.Json.NamingPolicies
namespace Yoh.Text.Json.NamingPolicies;

internal sealed class JsonKebabCaseLowerNamingPolicy : JsonSeparatorNamingPolicy
{
internal sealed class JsonKebabCaseLowerNamingPolicy : JsonSeparatorNamingPolicy
public JsonKebabCaseLowerNamingPolicy()
: base(lowercase: true, separator: '-')
{
public JsonKebabCaseLowerNamingPolicy()
: base(lowercase: true, separator: '-')
{
}
}
}
11 changes: 5 additions & 6 deletions src/JsonKebabCaseUpperNamingPolicy.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace Yoh.Text.Json.NamingPolicies
namespace Yoh.Text.Json.NamingPolicies;

internal sealed class JsonKebabCaseUpperNamingPolicy : JsonSeparatorNamingPolicy
{
internal sealed class JsonKebabCaseUpperNamingPolicy : JsonSeparatorNamingPolicy
public JsonKebabCaseUpperNamingPolicy()
: base(lowercase: false, separator: '-')
{
public JsonKebabCaseUpperNamingPolicy()
: base(lowercase: false, separator: '-')
{
}
}
}
31 changes: 15 additions & 16 deletions src/JsonNamingPolicies.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
using System.Text.Json;

namespace Yoh.Text.Json.NamingPolicies
namespace Yoh.Text.Json.NamingPolicies;

public static class JsonNamingPolicies
{
public static class JsonNamingPolicies
{
private static JsonCamelCaseNamingPolicy? _camelCase;
private static JsonPascalCaseNamingPolicy? _pascalCase;
private static JsonSnakeCaseLowerNamingPolicy? _snakeCaseLower;
private static JsonSnakeCaseUpperNamingPolicy? _snakeCaseUpper;
private static JsonKebabCaseLowerNamingPolicy? _kebabCaseLower;
private static JsonKebabCaseUpperNamingPolicy? _kebabCaseUpper;
private static JsonCamelCaseNamingPolicy? _camelCase;
private static JsonPascalCaseNamingPolicy? _pascalCase;
private static JsonSnakeCaseLowerNamingPolicy? _snakeCaseLower;
private static JsonSnakeCaseUpperNamingPolicy? _snakeCaseUpper;
private static JsonKebabCaseLowerNamingPolicy? _kebabCaseLower;
private static JsonKebabCaseUpperNamingPolicy? _kebabCaseUpper;

public static JsonNamingPolicy CamelCase => _camelCase ??= new JsonCamelCaseNamingPolicy();
public static JsonNamingPolicy CamelCase => _camelCase ??= new JsonCamelCaseNamingPolicy();

public static JsonNamingPolicy PascalCase => _pascalCase ??= new JsonPascalCaseNamingPolicy();
public static JsonNamingPolicy PascalCase => _pascalCase ??= new JsonPascalCaseNamingPolicy();

public static JsonNamingPolicy SnakeCaseLower => _snakeCaseLower ??= new JsonSnakeCaseLowerNamingPolicy();
public static JsonNamingPolicy SnakeCaseLower => _snakeCaseLower ??= new JsonSnakeCaseLowerNamingPolicy();

public static JsonNamingPolicy SnakeCaseUpper => _snakeCaseUpper ??= new JsonSnakeCaseUpperNamingPolicy();
public static JsonNamingPolicy SnakeCaseUpper => _snakeCaseUpper ??= new JsonSnakeCaseUpperNamingPolicy();

public static JsonNamingPolicy KebabCaseLower => _kebabCaseLower ??= new JsonKebabCaseLowerNamingPolicy();
public static JsonNamingPolicy KebabCaseLower => _kebabCaseLower ??= new JsonKebabCaseLowerNamingPolicy();

public static JsonNamingPolicy KebabCaseUpper => _kebabCaseUpper ??= new JsonKebabCaseUpperNamingPolicy();
}
public static JsonNamingPolicy KebabCaseUpper => _kebabCaseUpper ??= new JsonKebabCaseUpperNamingPolicy();
}
Loading

0 comments on commit 326c8e3

Please sign in to comment.