Migrate a bunch of code out of common.h

Put it into wcstringutil, path, or a new file null_terminated_array.
This commit is contained in:
ridiculousfish
2020-01-15 13:16:43 -08:00
parent 273afca3da
commit 6705a2efc6
25 changed files with 425 additions and 394 deletions

View File

@@ -442,3 +442,21 @@ bool paths_are_same_file(const wcstring &path1, const wcstring &path2) {
return false;
}
void append_path_component(wcstring &path, const wcstring &component) {
if (path.empty() || component.empty()) {
path.append(component);
} else {
size_t path_len = path.size();
bool path_slash = path.at(path_len - 1) == L'/';
bool comp_slash = component.at(0) == L'/';
if (!path_slash && !comp_slash) {
// Need a slash
path.push_back(L'/');
} else if (path_slash && comp_slash) {
// Too many slashes.
path.erase(path_len - 1, 1);
}
path.append(component);
}
}