26 lines
557 B
C#
26 lines
557 B
C#
using System.Collections.Generic;
|
|
using zero.Core.Extensions;
|
|
|
|
namespace zero.Core.Renderer
|
|
{
|
|
public class TokenReplacement
|
|
{
|
|
const char BEGIN = '{';
|
|
|
|
const char END = '}';
|
|
|
|
public static string Apply(string text, Dictionary<string, string> tokens)
|
|
{
|
|
foreach ((string key, string value) in tokens)
|
|
{
|
|
string tokenKey = key.EnsureStartsWith(BEGIN).EnsureEndsWith(END);
|
|
string tokenValue = value; // TODO escape for HTML?
|
|
|
|
text = text.Replace(tokenKey, value);
|
|
}
|
|
|
|
return text;
|
|
}
|
|
}
|
|
}
|