Skip to content

Commit

Permalink
template with multiple unknown placeholder -> stripped string : green
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkerde committed Apr 4, 2011
1 parent 758bbe9 commit 215ce8c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions KataStringReplacer/KataStringReplacer/StringRenderer.cs
Expand Up @@ -18,7 +18,7 @@ public string Render(string template)
if (_placeholders != null)
foreach (var keyValue in _placeholders)
template = template.Replace(GetPlaceholder(keyValue.Key), keyValue.Value);

template = RemoveUnrecognizedPlaceholders(template);

return template;
Expand All @@ -31,15 +31,21 @@ private string GetPlaceholder(string name)

private string RemoveUnrecognizedPlaceholders(string text)
{
int tokenStart = text.IndexOf('$');
int tokenStart, tokenEnd = -1;

if (tokenStart > -1)
do
{
int tokenEnd = text.IndexOf('$', tokenStart + 1);
tokenStart = text.IndexOf('$');

if (tokenStart > -1)
{
tokenEnd = text.IndexOf('$', tokenStart + 1);

if (tokenEnd > tokenStart)
text = text.Substring(0, tokenStart) + text.Substring(tokenEnd + 1);
if (tokenEnd > tokenStart)
text = text.Substring(0, tokenStart) + text.Substring(tokenEnd + 1);
}
}
while (tokenEnd > tokenStart && tokenStart > 0);

return text;
}
Expand Down

0 comments on commit 215ce8c

Please sign in to comment.