From d86a3c9c3cb06b44e84c4526a8f28262d6d10abf Mon Sep 17 00:00:00 2001 From: CWX Date: Wed, 22 Jan 2025 13:33:10 +0000 Subject: [PATCH] add regex anno alex asked for --- SptCommon/Extensions/StringExtensions.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SptCommon/Extensions/StringExtensions.cs b/SptCommon/Extensions/StringExtensions.cs index d8edecf0..ce5bd992 100644 --- a/SptCommon/Extensions/StringExtensions.cs +++ b/SptCommon/Extensions/StringExtensions.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using System.Text.RegularExpressions; namespace SptCommon.Extensions; @@ -7,7 +8,7 @@ public static class StringExtensions private static readonly Dictionary RegexCache = new(); private static readonly object RegexCacheLock = new(); - public static string RegexReplace(this string source, string regexString, string newValue) + public static string RegexReplace(this string source, [StringSyntax(StringSyntaxAttribute.Regex)] string regexString, string newValue) { Regex regex; lock (RegexCacheLock) @@ -21,7 +22,7 @@ public static class StringExtensions return regex.Replace(source, newValue); } - public static bool RegexMatch(this string source, string regexString, out Match? matchedString) + public static bool RegexMatch(this string source, [StringSyntax(StringSyntaxAttribute.Regex)] string regexString, out Match? matchedString) { Regex regex; lock (RegexCacheLock)