From 78b2aa459fd97e481e9942c4486e727f63f6af58 Mon Sep 17 00:00:00 2001
From: Ronny Gunawan <3048897+ronnygunawan@users.noreply.github.com>
Date: Sat, 7 Dec 2024 12:24:02 +0700
Subject: [PATCH] Clean up linter warnings
---
csharp/Pehape/PHP.cs | 1 +
csharp/Pehape/Pehape.csproj | 1 +
csharp/Pehape/String/Explode.cs | 1 +
csharp/Pehape/String/Implode.cs | 3 ++-
csharp/Pehape/String/Levenshtein.cs | 17 ++++++-----------
csharp/Pehape/String/Md5.cs | 12 ++++++------
csharp/Pehape/String/StrRot13.cs | 1 +
7 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/csharp/Pehape/PHP.cs b/csharp/Pehape/PHP.cs
index 184a6b8..1e498b1 100644
--- a/csharp/Pehape/PHP.cs
+++ b/csharp/Pehape/PHP.cs
@@ -2,5 +2,6 @@
///
/// Contains port of PHP functions.
///
+ // ReSharper disable once InconsistentNaming
public static partial class PHP { }
}
diff --git a/csharp/Pehape/Pehape.csproj b/csharp/Pehape/Pehape.csproj
index ff342aa..0a460c8 100644
--- a/csharp/Pehape/Pehape.csproj
+++ b/csharp/Pehape/Pehape.csproj
@@ -6,6 +6,7 @@
False
latest-all
true
+ true
diff --git a/csharp/Pehape/String/Explode.cs b/csharp/Pehape/String/Explode.cs
index d1fc805..7149746 100644
--- a/csharp/Pehape/String/Explode.cs
+++ b/csharp/Pehape/String/Explode.cs
@@ -2,6 +2,7 @@
using System.Linq;
namespace Pehape {
+ // ReSharper disable once InconsistentNaming
public static partial class PHP {
///
/// The Explode function breaks a string into an array.
diff --git a/csharp/Pehape/String/Implode.cs b/csharp/Pehape/String/Implode.cs
index 1f92a09..ee7868f 100644
--- a/csharp/Pehape/String/Implode.cs
+++ b/csharp/Pehape/String/Implode.cs
@@ -2,6 +2,7 @@
using System.Linq;
namespace Pehape {
+ // ReSharper disable once InconsistentNaming
public static partial class PHP {
///
/// The Implode function joins array elements with a string.
@@ -41,4 +42,4 @@ public static string Implode(string? separator, IEnumerable array) =>
public static string Implode(char separator, IEnumerable array) =>
string.Join(separator, array.SelectMany(x => x));
}
-}
\ No newline at end of file
+}
diff --git a/csharp/Pehape/String/Levenshtein.cs b/csharp/Pehape/String/Levenshtein.cs
index 68f33d6..acda299 100644
--- a/csharp/Pehape/String/Levenshtein.cs
+++ b/csharp/Pehape/String/Levenshtein.cs
@@ -1,6 +1,7 @@
using System;
namespace Pehape {
+ // ReSharper disable once InconsistentNaming
public static partial class PHP {
///
/// The Levenshtein function returns the Levenshtein distance between two strings.
@@ -30,22 +31,16 @@ public static int Levenshtein(string string1, string string2, int insertCost = 1
Span 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;
diff --git a/csharp/Pehape/String/Md5.cs b/csharp/Pehape/String/Md5.cs
index f2a9126..172fb64 100644
--- a/csharp/Pehape/String/Md5.cs
+++ b/csharp/Pehape/String/Md5.cs
@@ -2,6 +2,7 @@
using System.Text;
namespace Pehape {
+ // ReSharper disable once InconsistentNaming
public static partial class PHP {
///
/// The Md5Raw function calculates the md5 hash of a string
@@ -9,9 +10,10 @@ public static partial class PHP {
/// String to be calculated
/// 16 character binary format
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;
}
@@ -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();
}
}
-}
\ No newline at end of file
+}
diff --git a/csharp/Pehape/String/StrRot13.cs b/csharp/Pehape/String/StrRot13.cs
index 44f3f56..f554247 100644
--- a/csharp/Pehape/String/StrRot13.cs
+++ b/csharp/Pehape/String/StrRot13.cs
@@ -2,6 +2,7 @@
using System.Text;
namespace Pehape {
+ // ReSharper disable once InconsistentNaming
public static partial class PHP {
///
/// Performs the ROT13 encoding on the string argument and returns the resulting string.