1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2024-10-17 09:42:45 +02:00
TweetDuck/lib/TweetLib.Utils/Data/InjectedString.cs
2022-02-05 23:34:00 +01:00

46 lines
842 B
C#

using System;
namespace TweetLib.Utils.Data {
public sealed class InjectedString {
public enum Position {
Before,
After
}
private readonly Position position;
private readonly string search;
private readonly string html;
public InjectedString(Position position, string search, string html) {
this.position = position;
this.search = search;
this.html = html;
}
public string InjectInto(string targetHTML) {
int index = targetHTML.IndexOf(search, StringComparison.Ordinal);
if (index == -1) {
return targetHTML;
}
int cutIndex;
switch (position) {
case Position.Before:
cutIndex = index;
break;
case Position.After:
cutIndex = index + search.Length;
break;
default:
return targetHTML;
}
return targetHTML.Insert(cutIndex, html);
}
}
}