Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up linter warnings #84

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions csharp/Pehape/PHP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
/// <summary>
/// Contains port of PHP functions.
/// </summary>
// ReSharper disable once InconsistentNaming
public static partial class PHP { }
}
1 change: 1 addition & 0 deletions csharp/Pehape/Pehape.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<EnforceCodeStyleInBuild>False</EnforceCodeStyleInBuild>
<AnalysisLevel>latest-all</AnalysisLevel>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions csharp/Pehape/String/Explode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;

namespace Pehape {
// ReSharper disable once InconsistentNaming
public static partial class PHP {
/// <summary>
/// The Explode function breaks a string into an array.
Expand Down
3 changes: 2 additions & 1 deletion csharp/Pehape/String/Implode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;

namespace Pehape {
// ReSharper disable once InconsistentNaming
public static partial class PHP {
/// <summary>
/// The Implode function joins array elements with a string.
Expand Down Expand Up @@ -41,4 +42,4 @@ public static string Implode<T>(string? separator, IEnumerable<T[]> array) =>
public static string Implode<T>(char separator, IEnumerable<T[]> array) =>
string.Join(separator, array.SelectMany(x => x));
}
}
}
17 changes: 6 additions & 11 deletions csharp/Pehape/String/Levenshtein.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;

namespace Pehape {
// ReSharper disable once InconsistentNaming
public static partial class PHP {
/// <summary>
/// The Levenshtein function returns the Levenshtein distance between two strings.
Expand Down Expand Up @@ -30,22 +31,16 @@ public static int Levenshtein(string string1, string string2, int insertCost = 1
Span<int> p2 = stackalloc int[string2.Length + 1];
var swap = false;

for (var i2 = 0; i2 <= string2.Length; i2++) {
p1[i2] = i2 * insertCost;
}
for (var i1 = 0; i1 < string1.Length; i1++) {
for (var i2 = 0; i2 <= string2.Length; i2++) p1[i2] = i2 * insertCost;
foreach (var c in string1) {
(swap ? p1 : p2)[0] = (swap ? p2 : p1)[0] + deleteCost;

for (var i2 = 0; i2 < string2.Length; i2++) {
var c0 = (swap ? p2 : p1)[i2] + (string1[i1] == string2[i2] ? 0 : replaceCost);
var c0 = (swap ? p2 : p1)[i2] + (c == string2[i2] ? 0 : replaceCost);
var c1 = (swap ? p2 : p1)[i2 + 1] + deleteCost;
if (c1 < c0) {
c0 = c1;
}
if (c1 < c0) c0 = c1;
var c2 = (swap ? p1 : p2)[i2] + insertCost;
if (c2 < c0) {
c0 = c2;
}
if (c2 < c0) c0 = c2;
(swap ? p1 : p2)[i2 + 1] = c0;
}
swap = !swap;
Expand Down
12 changes: 6 additions & 6 deletions csharp/Pehape/String/Md5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
using System.Text;

namespace Pehape {
// ReSharper disable once InconsistentNaming
public static partial class PHP {
/// <summary>
/// The Md5Raw function calculates the md5 hash of a string
/// </summary>
/// <param name="input">String to be calculated</param>
/// <returns>16 character binary format</returns>
public static byte[] Md5Raw(string input) {
using var md5 = System.Security.Cryptography.MD5.Create();
var inputBytes = Encoding.ASCII.GetBytes(input);
var hashBytes = md5.ComputeHash(inputBytes);
#pragma warning disable CA5351
var hashBytes = System.Security.Cryptography.MD5.HashData(inputBytes);
#pragma warning restore CA5351
return hashBytes;
}

Expand All @@ -23,11 +25,9 @@ public static byte[] Md5Raw(string input) {
public static string Md5(string input) {
var hashBytes = Md5Raw(input);
var sb = new StringBuilder();
foreach (var t in hashBytes) {
sb.Append(t.ToString("x2", CultureInfo.InvariantCulture));
}
foreach (var t in hashBytes) sb.Append(t.ToString("x2", CultureInfo.InvariantCulture));

return sb.ToString();
}
}
}
}
1 change: 1 addition & 0 deletions csharp/Pehape/String/StrRot13.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text;

namespace Pehape {
// ReSharper disable once InconsistentNaming
public static partial class PHP {
/// <summary>
/// Performs the ROT13 encoding on the string argument and returns the resulting string.
Expand Down
Loading