mirror of https://github.com/Jackett/Jackett
cardigann: Convert to the GoTemplate standard the Range with Index statement.
This commit is contained in:
parent
d3c9328575
commit
6f33f34f46
|
@ -457,7 +457,7 @@ namespace Jackett.Common.Indexers
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle range expression
|
// handle range expression
|
||||||
var RangeRegex = new Regex(@"{{\s*range\s*(.+?)\s*}}(.*?){{\.}}(.*?){{end}}");
|
var RangeRegex = new Regex(@"{{\s*range\s*(((?<index>\$.+?),)((\s*(?<element>.+?)\s*(:=)\s*)))?(?<variable>.+?)\s*}}(?<prefix>.*?){{\.}}(?<postfix>.*?){{end}}");
|
||||||
var RangeRegexMatches = RangeRegex.Match(template);
|
var RangeRegexMatches = RangeRegex.Match(template);
|
||||||
|
|
||||||
while (RangeRegexMatches.Success)
|
while (RangeRegexMatches.Success)
|
||||||
|
@ -465,25 +465,29 @@ namespace Jackett.Common.Indexers
|
||||||
var expanded = string.Empty;
|
var expanded = string.Empty;
|
||||||
|
|
||||||
var all = RangeRegexMatches.Groups[0].Value;
|
var all = RangeRegexMatches.Groups[0].Value;
|
||||||
var variable = RangeRegexMatches.Groups[1].Value;
|
var index = RangeRegexMatches.Groups["index"].Value;
|
||||||
var prefix = RangeRegexMatches.Groups[2].Value;
|
var variable = RangeRegexMatches.Groups["variable"].Value;
|
||||||
var postfix = RangeRegexMatches.Groups[3].Value;
|
var prefix = RangeRegexMatches.Groups["prefix"].Value;
|
||||||
var hasArrayIndex = prefix.Contains("[*]");
|
var postfix = RangeRegexMatches.Groups["postfix"].Value;
|
||||||
var arrayIndex = -1;
|
|
||||||
if (hasArrayIndex)
|
var arrayIndex = 0;
|
||||||
prefix = prefix.Replace("[*]", "[-1]");
|
var indexReplace = "{{" + index + "}}";
|
||||||
|
|
||||||
foreach (var value in (ICollection<string>)variables[variable])
|
foreach (var value in (ICollection<string>)variables[variable])
|
||||||
{
|
{
|
||||||
var newvalue = value;
|
var newvalue = value;
|
||||||
if (modifier != null)
|
if (modifier != null)
|
||||||
newvalue = modifier(newvalue);
|
newvalue = modifier(newvalue);
|
||||||
if (hasArrayIndex)
|
var indexValue = arrayIndex++;
|
||||||
|
|
||||||
|
if (index != null)
|
||||||
{
|
{
|
||||||
prefix = prefix.Replace("[" + arrayIndex.ToString() + "]", "[" + (arrayIndex + 1).ToString() + "]");
|
expanded += prefix.Replace(indexReplace, indexValue.ToString()) + newvalue + postfix.Replace(indexReplace, indexValue.ToString());
|
||||||
arrayIndex++;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
expanded += prefix + newvalue + postfix;
|
||||||
}
|
}
|
||||||
expanded += prefix + newvalue + postfix;
|
|
||||||
}
|
}
|
||||||
template = template.Replace(all, expanded);
|
template = template.Replace(all, expanded);
|
||||||
RangeRegexMatches = RangeRegexMatches.NextMatch();
|
RangeRegexMatches = RangeRegexMatches.NextMatch();
|
||||||
|
|
Loading…
Reference in New Issue