Made Replace fail conditions depend on the correct modes
This commit is contained in:
parent
ab604877be
commit
04b18f8140
|
@ -38,14 +38,14 @@ namespace BFR.Operations
|
||||||
{
|
{
|
||||||
// Fail conditions: Various out-of-bounds
|
// Fail conditions: Various out-of-bounds
|
||||||
var shortestLength = files.Min(x => FullName ? x.FullName.Length : x.Name.Length);
|
var shortestLength = files.Min(x => FullName ? x.FullName.Length : x.Name.Length);
|
||||||
if (FirstN > shortestLength) throw new OperationException($"First N can't be greater than the shortest file name length ({shortestLength}).");
|
if (Mode == ReplaceMode.FirstN && FirstN > shortestLength) throw new OperationException($"First N can't be greater than the shortest file name length ({shortestLength}).");
|
||||||
if (LastN > shortestLength) throw new OperationException($"Last N can't be greater than the shortest file name length ({shortestLength}).");
|
if (Mode == ReplaceMode.LastN && LastN > shortestLength) throw new OperationException($"Last N can't be greater than the shortest file name length ({shortestLength}).");
|
||||||
if (FromN > shortestLength) throw new OperationException($"From N can't be greater than the shortest file name length ({shortestLength}).");
|
if (Mode == ReplaceMode.FromNToN && FromN > shortestLength) throw new OperationException($"From N can't be greater than the shortest file name length ({shortestLength}).");
|
||||||
if (ToN > shortestLength) throw new OperationException($"To N can't be greater than the shortest file name length ({shortestLength}).");
|
if (Mode == ReplaceMode.FromNToN && ToN > shortestLength) throw new OperationException($"To N can't be greater than the shortest file name length ({shortestLength}).");
|
||||||
if (FromN > ToN) throw new OperationException("From N can't be greater than To N.");
|
if (Mode == ReplaceMode.FromNToN && FromN > ToN) throw new OperationException("From N can't be greater than To N.");
|
||||||
|
|
||||||
// Regex Failure
|
// Regex Failure
|
||||||
if(Modes[(int)Mode].IsPattern && UseRegex)
|
if(Mode == ReplaceMode.Pattern && UseRegex)
|
||||||
try { "".Replace(Pattern, Replacement, true, false); }
|
try { "".Replace(Pattern, Replacement, true, false); }
|
||||||
catch(Exception) { throw new OperationException("Invalid Regex Pattern."); }
|
catch(Exception) { throw new OperationException("Invalid Regex Pattern."); }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user