Skip to content

Commit

Permalink
Merge pull request #83 from teknologi-umum/dotnet-9
Browse files Browse the repository at this point in the history
Upgrade to .NET 9
  • Loading branch information
ronnygunawan authored Dec 2, 2024
2 parents 8e24813 + 0184961 commit e03757c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion csharp/Pehape/Pehape.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<EnforceCodeStyleInBuild>False</EnforceCodeStyleInBuild>
<AnalysisLevel>latest-all</AnalysisLevel>
Expand Down
4 changes: 2 additions & 2 deletions csharp/Pehape/String/Explode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static partial class PHP {
/// <returns>An array of strings.</returns>
public static string[] Explode(string? separator, string str, int? limit = null) {
if (separator is "") throw new ArgumentException("Separator cannot be empty.", nameof(separator));
if (str is null) throw new ArgumentNullException(nameof(str));
ArgumentNullException.ThrowIfNull(str);
return limit switch {
null => str.Split(separator),
> 0 => str.Split(separator).Take(limit.Value).ToArray(),
Expand All @@ -37,7 +37,7 @@ public static string[] Explode(string? separator, string str, int? limit = null)
/// one element is returned.</param>
/// <returns>An array of strings.</returns>
public static string[] Explode(char separator, string str, int? limit = null) {
if (str is null) throw new ArgumentNullException(nameof(str));
ArgumentNullException.ThrowIfNull(str);
return limit switch {
null => str.Split(separator),
> 0 => str.Split(separator).Take(limit.Value).ToArray(),
Expand Down
8 changes: 4 additions & 4 deletions csharp/Pehape/String/Levenshtein.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public static partial class PHP {
public static int Levenshtein(string string1, string string2, int insertCost = 1, int replaceCost = 1, int deleteCost = 1) {
// Ported from https://github.com/php/php-src/blob/master/ext/standard/levenshtein.c

if (string1 is null) throw new ArgumentNullException(nameof(string1));
if (string2 is null) throw new ArgumentNullException(nameof(string2));
ArgumentNullException.ThrowIfNull(string1);
ArgumentNullException.ThrowIfNull(string2);
if (insertCost < 0) throw new ArgumentException("InsertCost cannot be negative.", nameof(insertCost));
if (replaceCost < 0) throw new ArgumentException("ReplaceCost cannot be negative.", nameof(replaceCost));
if (deleteCost < 0) throw new ArgumentException("DeleteCost cannot be negative.", nameof(deleteCost));
Expand All @@ -28,7 +28,7 @@ public static int Levenshtein(string string1, string string2, int insertCost = 1

Span<int> p1 = stackalloc int[string2.Length + 1];
Span<int> p2 = stackalloc int[string2.Length + 1];
bool swap = false;
var swap = false;

for (var i2 = 0; i2 <= string2.Length; i2++) {
p1[i2] = i2 * insertCost;
Expand All @@ -42,7 +42,7 @@ public static int Levenshtein(string string1, string string2, int insertCost = 1
if (c1 < c0) {
c0 = c1;
}
int c2 = (swap ? p1 : p2)[i2] + insertCost;
var c2 = (swap ? p1 : p2)[i2] + insertCost;
if (c2 < c0) {
c0 = c2;
}
Expand Down
4 changes: 2 additions & 2 deletions csharp/Pehape/String/StrRot13.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public static partial class PHP {
/// <param name="str">The input string.</param>
/// <returns>Returns the ROT13 version of the given string.</returns>
public static string StrRot13(string str) {
if (str is null) throw new ArgumentNullException(nameof(str));
ArgumentNullException.ThrowIfNull(str);

var buffer = new StringBuilder();
foreach (char ch in str) {
foreach (var ch in str) {
buffer.Append((char)(ch switch {
>= 'a' and <= 'z' => ch > 'm' ? ch - 13 : ch + 13,
>= 'A' and <= 'Z' => ch > 'M' ? ch - 13 : ch + 13,
Expand Down

0 comments on commit e03757c

Please sign in to comment.