/
RemoveText.cs
31 lines (26 loc) · 962 Bytes
/
RemoveText.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using microObjectPizzaShop.Library.Numeric;
using MicroObjectPizzaShop.Library.Texts;
namespace microObjectPizzaShop.Library.Texts {
public class RemoveText : IText
{
private const int NotFound = -1;
private readonly IText _source;
private readonly IInteger _lastIndexOf;
private readonly IInteger _lengthOf;
public RemoveText(IText source, IText target) :
this(source, new LastIndexOf(source, target), new LengthOf(target))
{ }
public RemoveText(IText source, IInteger lastIndexOf, IInteger lengthOf)
{
_source = source;
_lastIndexOf = lastIndexOf;
_lengthOf = lengthOf;
}
public string String()
{
int lastIndexOf = _lastIndexOf.Value();
if (lastIndexOf == NotFound) return _source.String();
return _source.String().Remove(lastIndexOf, _lengthOf.Value());
}
}
}