From 43c3dba112c202e2d0ff1a6909020c2b83e20dc3 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Mon, 5 Aug 2024 15:44:45 +0200 Subject: [PATCH] Add more Regex functions --- DataManagerExtensions.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/DataManagerExtensions.cs b/DataManagerExtensions.cs index bfdd0b1..8db0761 100644 --- a/DataManagerExtensions.cs +++ b/DataManagerExtensions.cs @@ -79,15 +79,9 @@ public static class DataManagerExtensions if (text == null) return null; - string regex = string.Join("", text.Payloads.Select(payload => - { - if (payload is TextPayload) - return Regex.Escape(payload.RawString); - else - return "(.*)"; - })); + Regex regex = text.ToRegex(); pluginLog?.Verbose($"{typeof(T).Name}.{rowId} => /{regex}/"); - return new Regex(regex); + return regex; } public static Regex? GetRegex(this T excelRow, Func mapper, IPluginLog? pluginLog) @@ -99,14 +93,20 @@ public static class DataManagerExtensions if (text == null) return null; - string regex = string.Join("", text.Payloads.Select(payload => + Regex regex = text.ToRegex(); + pluginLog?.Verbose($"{typeof(T).Name}.regex => /{regex}/"); + return regex; + } + + public static Regex ToRegex(this SeString? text) + { + ArgumentNullException.ThrowIfNull(text); + return new Regex(string.Join("", text.Payloads.Select(payload => { if (payload is TextPayload) return Regex.Escape(payload.RawString); else return "(.*)"; - })); - pluginLog?.Verbose($"{typeof(T).Name}.regex => /{regex}/"); - return new Regex(regex); + }))); } }