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

ConfigParser: AsPath

It look line there is no c# library to expand linux style env variable in path.
Let's write it  myself!
parent 241675d0
No related branches found
No related tags found
No related merge requests found
......@@ -180,6 +180,38 @@ class ConfigValue
if(Value == null) throw new ConfigNoValueException(this);
return Value;
}
public string AsPath()
{
string s = AsString();
StringBuilder output = new();
for(int i=0;i<s.Length;i++)
{
if(i == 0 && s[i]=='~')
{
output.Append(Environment.GetEnvironmentVariable("HOME") ?? "");
}
else if(s[i]=='$')
{
int start, end;
if(s[i+1]=='{')
{
start = i+2;
while(i<s.Length && s[i]!='}') i++;
end = i;
}
else
{
start = i+1;
while(i+1<s.Length && "qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM_".Contains(s[i+1])) i++;
end = i+1;
}
output.Append(Environment.GetEnvironmentVariable(s[start..end]) ?? "");
}
else
output.Append(s[i]);
}
return output.ToString();
}
public Color AsColor()
{
try
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment