Skip to content
Snippets Groups Projects
Commit 33a780e9 authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

FormatExpander

parent 49831294
Branches
No related tags found
No related merge requests found
...@@ -20,6 +20,44 @@ using Config; ...@@ -20,6 +20,44 @@ using Config;
namespace i3csstatus; namespace i3csstatus;
class FormatExpander
{
static public string Expand(string f, Func<string, string> callback)
{
StringBuilder sb = new();
StringBuilder arg = null;
bool freeClosing = false;
foreach(char c in f)
{
if(arg == null && c == '{') arg = new();
else
if(arg != null && c == '{')
{
sb.Append('{');
arg = null;
}
else
if(arg == null && c == '}')
{
if(freeClosing) sb.Append('}');
freeClosing = !freeClosing;
}
else
if(arg != null && c == '}')
{
sb.Append(callback(arg.ToString()));
arg = null;
}
else
if(arg != null)
arg.Append(c);
else
sb.Append(c);
}
return sb.ToString();
}
}
class ModuleException: Exception class ModuleException: Exception
{ {
} }
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment