2019-11-21 18:07:46 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
using BFR.Helpers;
|
|
|
|
|
|
|
|
|
|
namespace BFR.Operations
|
2019-11-17 15:22:19 +00:00
|
|
|
|
{
|
2019-11-21 18:07:46 +00:00
|
|
|
|
public class ReplaceOperationMode : OperationMode<ReplaceMode>
|
|
|
|
|
{
|
|
|
|
|
public bool IsPattern => Index == ReplaceMode.Pattern;
|
|
|
|
|
public bool IsCharacters => Index == ReplaceMode.Characters;
|
|
|
|
|
public bool IsFromNToN => Index == ReplaceMode.FromNToN;
|
|
|
|
|
public bool IsFirstN => Index == ReplaceMode.FirstN;
|
|
|
|
|
public bool IsLastN => Index == ReplaceMode.LastN;
|
|
|
|
|
|
|
|
|
|
public readonly static ReplaceOperationMode[] Modes = All();
|
|
|
|
|
|
|
|
|
|
protected ReplaceOperationMode(ReplaceMode index, string name, string description) :
|
|
|
|
|
base(index, name, description) { }
|
|
|
|
|
|
|
|
|
|
protected static ReplaceOperationMode[] All() => ((IEnumerable<ReplaceMode>)Enum.GetValues(typeof(ReplaceMode))).Select(x =>
|
|
|
|
|
new ReplaceOperationMode(
|
|
|
|
|
x,
|
2019-11-21 18:23:25 +00:00
|
|
|
|
x.GetAttribute<OperationModeAttribute>().DisplayName,
|
|
|
|
|
x.GetAttribute<OperationModeAttribute>().Description
|
2019-11-21 18:07:46 +00:00
|
|
|
|
)).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ReplaceMode
|
2019-11-17 15:22:19 +00:00
|
|
|
|
{
|
2019-11-21 18:23:25 +00:00
|
|
|
|
[OperationMode(nameof(Pattern), "Replaces the specified pattern.")]
|
2019-11-21 18:07:46 +00:00
|
|
|
|
Pattern,
|
2019-11-21 18:23:25 +00:00
|
|
|
|
[OperationMode(nameof(Characters), "Replaces each of the specified characters.")]
|
2019-11-21 18:07:46 +00:00
|
|
|
|
Characters,
|
2019-11-21 18:23:25 +00:00
|
|
|
|
[OperationMode("From N to N", "Replaces everything in the specified range (zero-based indeces).")]
|
2019-11-21 18:07:46 +00:00
|
|
|
|
FromNToN,
|
2019-11-21 18:23:25 +00:00
|
|
|
|
[OperationMode("First N", "Replaces the first N characters.")]
|
2019-11-21 18:07:46 +00:00
|
|
|
|
FirstN,
|
2019-11-21 18:23:25 +00:00
|
|
|
|
[OperationMode("Last N", "Replaces the last N characters.")]
|
2019-11-21 18:07:46 +00:00
|
|
|
|
LastN,
|
2019-11-17 15:22:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|