Add more regex options

master
Liza 2023-10-21 12:32:21 +02:00
parent 7649b0d51b
commit 89448838a1
Signed by: liza
GPG Key ID: 7199F8D727D55F67
1 changed files with 20 additions and 2 deletions

View File

@ -40,7 +40,7 @@ public static class DataManagerExtensions
if (payload is TextPayload) if (payload is TextPayload)
return Regex.Escape(payload.RawString); return Regex.Escape(payload.RawString);
else else
return ".*"; return "(.*)";
})); }));
pluginLog?.Verbose($"{typeof(T).Name}.{key} => /{regex}/"); pluginLog?.Verbose($"{typeof(T).Name}.{key} => /{regex}/");
return new Regex(regex); return new Regex(regex);
@ -77,9 +77,27 @@ public static class DataManagerExtensions
if (payload is TextPayload) if (payload is TextPayload)
return Regex.Escape(payload.RawString); return Regex.Escape(payload.RawString);
else else
return ".*"; return "(.*)";
})); }));
pluginLog?.Verbose($"{typeof(T).Name}.{rowId} => /{regex}/"); pluginLog?.Verbose($"{typeof(T).Name}.{rowId} => /{regex}/");
return new Regex(regex); return new Regex(regex);
} }
public static Regex? GetRegex<T>(this T excelRow, Func<T, SeString?> mapper, IPluginLog? pluginLog)
where T : ExcelRow
{
SeString? text = mapper(excelRow);
if (text == null)
return null;
string 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);
}
} }