Skip to content

Commit

Permalink
perf: add logging for match key extraction
Browse files Browse the repository at this point in the history
- Added logging to output the filename and pattern used for matching.
- Improved key extraction logic to handle unsuccessful matches.
- Added logging to output the matched key.
  • Loading branch information
qwqcode committed Sep 24, 2024
1 parent 49e53fe commit 28dfef2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions SubRenamer/Matcher/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@ public static string ExtractMatchKeyByDiff(DiffResult? diff, string filename)
: $"{Regex.Escape(diff.Prefix)}(.+?){Regex.Escape(diff.Suffix)}";
}

Logger.Out.WriteLine("[Diff.ExtractMatchKeyByDiff]\n\n Str=\"{0}\"\n MatchPattern=\"{1}\"", filename, pattern);

var key = "";
var match = Regex.Match(filename, pattern, RegexOptions.IgnoreCase);
if (!match.Success || match.Groups.Count == 0) return "";
key = (match.Success && match.Groups.Count > 0) ? match.Groups[1].Value.Trim() : "";

var key = match.Groups[1].Value.Trim();
Logger.Out.WriteLine(" MatchedKey=\"{0}\"\n", key);

return key;
}
Expand Down
8 changes: 6 additions & 2 deletions SubRenamer/Matcher/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ public static class Helper
{
public static string ExtractMatchKeyRegex(string pattern, string filename)
{
try {
try
{
var match = Regex.Match(filename, pattern, RegexOptions.IgnoreCase);
if (match.Success) return match.Groups[1].Value;
} catch (Exception e) {
}
catch (Exception e)
{
Logger.Out.WriteLine(e.Message);
}

return "";
}

Expand Down

0 comments on commit 28dfef2

Please sign in to comment.