mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-20 22:21:16 -03:00
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:
18
src/path.cpp
18
src/path.cpp
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user