mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-08-17 00:31:42 +02:00
.github
.idea
bld
lib
TweetLib.Browser
TweetLib.Browser.CEF
TweetLib.Communication
TweetLib.Core
TweetLib.Utils
Collections
Data
InjectedString.cs
Result.cs
WindowState.cs
Dialogs
Globalization
IO
Serialization
Startup
Static
Lib.cs
TweetLib.Utils.csproj
TweetTest.Browser.CEF
TweetTest.Core
TweetTest.Utils
linux
resources
windows
.gitattributes
.gitignore
LICENSE.md
README.md
TweetDuck.sln
TweetDuck.sln.DotSettings
Version.cs
global.json
46 lines
842 B
C#
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);
|
|
}
|
|
}
|
|
}
|