Skip to content

Commit

Permalink
add MakeRelativePath
Browse files Browse the repository at this point in the history
  • Loading branch information
weinand committed Feb 22, 2016
1 parent 56e901b commit 2ee0e4f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,14 @@ public static int FindFreePort(int fallback)

public static string ExpandVariables(string format, dynamic variables, bool underscoredOnly = true)
{
if (variables == null) {
variables = new { };
}
Type type = variables.GetType();
return VARIABLE.Replace(format, match => {
string name = match.Groups[1].Value;
if (!underscoredOnly || name.StartsWith("_")) {

PropertyInfo property = type.GetProperty(name);
if (property != null) {
object value = property.GetValue(variables, null);
Expand All @@ -130,5 +134,24 @@ public static string ExpandVariables(string format, dynamic variables, bool unde
return match.Groups[0].Value;
});
}

/**
* converts the given absPath into a path that is relative to the given dirPath.
*/
public static string MakeRelativePath(string dirPath, string absPath)
{
if (!dirPath.EndsWith("/")) {
dirPath += "/";
}
if (absPath.StartsWith(dirPath)) {
return absPath.Replace(dirPath, "");
}
return absPath;
/*
Uri uri1 = new Uri(path);
Uri uri2 = new Uri(dir_path);
return uri2.MakeRelativeUri(uri1).ToString();
*/
}
}
}

0 comments on commit 2ee0e4f

Please sign in to comment.