normalize pathnames and handle dirs as basenames

develop
myk002 2021-06-29 14:25:30 -07:00
parent 2a54b101bd
commit 367fdbd31c
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
2 changed files with 12 additions and 3 deletions

@ -587,11 +587,20 @@ static string get_tile_query(df::building* b)
return " ";
}
// can remove once we move to C++20
static bool ends_with(const string &str, const string &sv)
{
if (sv.size() > str.size())
return false;
return str.substr(str.size() - sv.size()) == sv;
}
// returns filename
static string init_stream(ofstream &out, string basename, string target)
{
std::ostringstream out_path;
out_path << basename << "-" << target << ".csv";
string separator = ends_with(basename, "/") ? "" : "-";
out_path << basename << separator << target << ".csv";
string path = out_path.str();
out.open(path, ofstream::trunc);
out << "#" << target << endl;

@ -69,8 +69,8 @@ local function parse_positionals(opts, args, start_argidx)
:format(args[argidx]))
end
argidx = argidx + 1
-- normalize paths to forward slashes
opts.name = name:gsub(package.config:sub(1,1), "/")
-- normalize paths and remove leading slashes
opts.name = utils.normalizePath(name):gsub('^/', '')
local auto_phase = true
local phase = args[argidx]