Files
fish-shell/src/path.cpp
2024-01-02 01:59:02 +08:00

35 lines
1.0 KiB
C++

// Directory utilities. This library contains functions for locating configuration directories, for
// testing if a command with a given name can be found in the PATH, and various other path-related
// issues.
#include "config.h" // IWYU pragma: keep
#include "path.h"
#include <cstring>
#include <string>
#include <utility>
#include <vector>
#include "common.h"
#include "fallback.h" // IWYU pragma: keep
#include "wcstringutil.h"
#include "wutil.h" // IWYU pragma: keep
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);
}
}