aboutsummaryrefslogtreecommitdiff
path: root/Emby.Naming/Video
diff options
context:
space:
mode:
authorClaus Vium <cvium@users.noreply.github.com>2021-10-26 12:10:57 +0200
committerGitHub <noreply@github.com>2021-10-26 12:10:57 +0200
commitdc72d90703eab626f5241755251fa97c9b854604 (patch)
treea287c0fda2fcd182437d6a57b4152865739ed9cb /Emby.Naming/Video
parentdeb349f4c5125dc9118279d52d9460aadc994eda (diff)
parent6bc7d78f6fbef9e47731a4991ca72d3ba4c23bce (diff)
Merge pull request #6383 from sushilicious/master
Made default parser a tiny bit mroe robust
Diffstat (limited to 'Emby.Naming/Video')
-rw-r--r--Emby.Naming/Video/CleanStringParser.cs23
1 files changed, 16 insertions, 7 deletions
diff --git a/Emby.Naming/Video/CleanStringParser.cs b/Emby.Naming/Video/CleanStringParser.cs
index 4eef3ebc5..99cb289a2 100644
--- a/Emby.Naming/Video/CleanStringParser.cs
+++ b/Emby.Naming/Video/CleanStringParser.cs
@@ -25,26 +25,35 @@ namespace Emby.Naming.Video
return false;
}
- var len = expressions.Count;
- for (int i = 0; i < len; i++)
+ // Iteratively apply the regexps to clean the string.
+ bool cleaned = false;
+ for (int i = 0; i < expressions.Count; i++)
{
if (TryClean(name, expressions[i], out newName))
{
- return true;
+ cleaned = true;
+ name = newName.ToString();
}
}
- newName = ReadOnlySpan<char>.Empty;
- return false;
+ newName = cleaned ? name.AsSpan() : ReadOnlySpan<char>.Empty;
+ return cleaned;
}
private static bool TryClean(string name, Regex expression, out ReadOnlySpan<char> newName)
{
var match = expression.Match(name);
int index = match.Index;
- if (match.Success && index != 0)
+ if (match.Success)
{
- newName = name.AsSpan().Slice(0, match.Index);
+ var found = match.Groups.TryGetValue("cleaned", out var cleaned);
+ if (!found || cleaned == null)
+ {
+ newName = ReadOnlySpan<char>.Empty;
+ return false;
+ }
+
+ newName = name.AsSpan().Slice(cleaned.Index, cleaned.Length);
return true;
}