[Base] Make utf8 arguments consistent.
[Base] Make utf8 arguments consistent. Fix "sep" to "separator".
This commit is contained in:
parent
1f28ff5f18
commit
725f3ce17f
|
@ -485,7 +485,7 @@ std::vector<std::string_view> split_path(const std::string_view path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string join_paths(const std::string_view left_path,
|
std::string join_paths(const std::string_view left_path,
|
||||||
const std::string_view right_path, char32_t sep) {
|
const std::string_view right_path, char32_t separator) {
|
||||||
if (!left_path.length()) {
|
if (!left_path.length()) {
|
||||||
return std::string(right_path);
|
return std::string(right_path);
|
||||||
} else if (!right_path.length()) {
|
} else if (!right_path.length()) {
|
||||||
|
@ -495,31 +495,33 @@ std::string join_paths(const std::string_view left_path,
|
||||||
auto [it, end] = make_criter(left_path);
|
auto [it, end] = make_criter(left_path);
|
||||||
|
|
||||||
std::string result = std::string(left_path);
|
std::string result = std::string(left_path);
|
||||||
if (*it != static_cast<uint32_t>(sep)) {
|
if (*it != static_cast<uint32_t>(separator)) {
|
||||||
utfcpp::append(sep, result);
|
utfcpp::append(separator, result);
|
||||||
}
|
}
|
||||||
return result + std::string(right_path);
|
return result + std::string(right_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string join_paths(std::vector<std::string_view> paths, char32_t sep) {
|
std::string join_paths(std::vector<std::string_view> paths,
|
||||||
|
char32_t separator) {
|
||||||
std::string result;
|
std::string result;
|
||||||
auto it = paths.cbegin();
|
auto it = paths.cbegin();
|
||||||
if (it != paths.cend()) {
|
if (it != paths.cend()) {
|
||||||
result = *it++;
|
result = *it++;
|
||||||
for (; it != paths.cend(); ++it) {
|
for (; it != paths.cend(); ++it) {
|
||||||
result = join_paths(result, *it, sep);
|
result = join_paths(result, *it, separator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string fix_path_separators(const std::string_view path, char32_t new_sep) {
|
std::string fix_path_separators(const std::string_view path,
|
||||||
|
char32_t new_separator) {
|
||||||
if (path.empty()) {
|
if (path.empty()) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swap all separators to new_sep.
|
// Swap all separators to new_sep.
|
||||||
const char32_t old_sep = new_sep == U'\\' ? U'/' : U'\\';
|
const char32_t old_separator = new_separator == U'\\' ? U'/' : U'\\';
|
||||||
|
|
||||||
auto [path_begin, path_end] = make_citer(path);
|
auto [path_begin, path_end] = make_citer(path);
|
||||||
|
|
||||||
|
@ -527,7 +529,7 @@ std::string fix_path_separators(const std::string_view path, char32_t new_sep) {
|
||||||
auto it = path_begin;
|
auto it = path_begin;
|
||||||
auto last = it;
|
auto last = it;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
it = std::find(it, path_end, uint32_t(old_sep));
|
it = std::find(it, path_end, uint32_t(old_separator));
|
||||||
if (it == path_end) {
|
if (it == path_end) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -536,7 +538,7 @@ std::string fix_path_separators(const std::string_view path, char32_t new_sep) {
|
||||||
auto offset = byte_length(path_begin, last);
|
auto offset = byte_length(path_begin, last);
|
||||||
auto length = byte_length(path_begin, it) - offset;
|
auto length = byte_length(path_begin, it) - offset;
|
||||||
result += path.substr(offset, length);
|
result += path.substr(offset, length);
|
||||||
utfcpp::append(new_sep, result);
|
utfcpp::append(new_separator, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
++it;
|
++it;
|
||||||
|
@ -555,7 +557,8 @@ std::string fix_path_separators(const std::string_view path, char32_t new_sep) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string find_name_from_path(const std::string_view path, char32_t sep) {
|
std::string find_name_from_path(const std::string_view path,
|
||||||
|
char32_t separator) {
|
||||||
if (path.empty()) {
|
if (path.empty()) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
@ -564,7 +567,7 @@ std::string find_name_from_path(const std::string_view path, char32_t sep) {
|
||||||
|
|
||||||
auto it = begin;
|
auto it = begin;
|
||||||
size_t padding = 0;
|
size_t padding = 0;
|
||||||
if (*it == uint32_t(sep)) {
|
if (*it == uint32_t(separator)) {
|
||||||
++it;
|
++it;
|
||||||
padding = 1;
|
padding = 1;
|
||||||
}
|
}
|
||||||
|
@ -573,7 +576,7 @@ std::string find_name_from_path(const std::string_view path, char32_t sep) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
it = std::find(it, end, uint32_t(sep));
|
it = std::find(it, end, uint32_t(separator));
|
||||||
if (it == end) {
|
if (it == end) {
|
||||||
return std::string(path.substr(0, path.size() - padding));
|
return std::string(path.substr(0, path.size() - padding));
|
||||||
}
|
}
|
||||||
|
@ -584,8 +587,8 @@ std::string find_name_from_path(const std::string_view path, char32_t sep) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string find_base_name_from_path(const std::string_view path,
|
std::string find_base_name_from_path(const std::string_view path,
|
||||||
char32_t sep) {
|
char32_t separator) {
|
||||||
auto name = find_name_from_path(path, sep);
|
auto name = find_name_from_path(path, separator);
|
||||||
if (!name.size()) {
|
if (!name.size()) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
@ -606,7 +609,7 @@ std::string find_base_name_from_path(const std::string_view path,
|
||||||
return std::string(name.substr(0, length));
|
return std::string(name.substr(0, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string find_base_path(const std::string_view path, char32_t sep) {
|
std::string find_base_path(const std::string_view path, char32_t separator) {
|
||||||
if (path.empty()) {
|
if (path.empty()) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
@ -614,11 +617,11 @@ std::string find_base_path(const std::string_view path, char32_t sep) {
|
||||||
auto [begin, end] = make_criter(path);
|
auto [begin, end] = make_criter(path);
|
||||||
|
|
||||||
auto it = begin;
|
auto it = begin;
|
||||||
if (*it == uint32_t(sep)) {
|
if (*it == uint32_t(separator)) {
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
it = std::find(it, end, uint32_t(sep));
|
it = std::find(it, end, uint32_t(separator));
|
||||||
if (it == end) {
|
if (it == end) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
@ -632,12 +635,12 @@ std::string find_base_path(const std::string_view path, char32_t sep) {
|
||||||
return std::string(path.substr(0, length));
|
return std::string(path.substr(0, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string canonicalize_path(const std::string_view path, char32_t sep) {
|
std::string canonicalize_path(const std::string_view path, char32_t separator) {
|
||||||
if (path.empty()) {
|
if (path.empty()) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto is_rooted = starts_with(path, sep);
|
auto is_rooted = starts_with(path, separator);
|
||||||
|
|
||||||
auto parts = split_path(path);
|
auto parts = split_path(path);
|
||||||
for (auto it = parts.begin(); it != parts.end();) {
|
for (auto it = parts.begin(); it != parts.end();) {
|
||||||
|
@ -659,8 +662,8 @@ std::string canonicalize_path(const std::string_view path, char32_t sep) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return !is_rooted ? join_paths(parts, sep)
|
return !is_rooted ? join_paths(parts, separator)
|
||||||
: to_string(sep) + join_paths(parts, sep);
|
: to_string(separator) + join_paths(parts, separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace xe::utf8
|
} // namespace xe::utf8
|
||||||
|
|
|
@ -25,9 +25,9 @@ std::string upper_ascii(const std::string_view view);
|
||||||
size_t hash_fnv1a(const std::string_view view);
|
size_t hash_fnv1a(const std::string_view view);
|
||||||
size_t hash_fnv1a_case(const std::string_view view);
|
size_t hash_fnv1a_case(const std::string_view view);
|
||||||
|
|
||||||
// Splits the given string on any delimiters and returns all parts.
|
// Splits the given haystack on any delimiters (needles) and returns all parts.
|
||||||
std::vector<std::string_view> split(const std::string_view path,
|
std::vector<std::string_view> split(const std::string_view haystack,
|
||||||
const std::string_view delimiters,
|
const std::string_view needles,
|
||||||
bool remove_empty = false);
|
bool remove_empty = false);
|
||||||
|
|
||||||
bool equal_z(const std::string_view left, const std::string_view right);
|
bool equal_z(const std::string_view left, const std::string_view right);
|
||||||
|
@ -66,17 +66,17 @@ std::vector<std::string_view> split_path(const std::string_view path);
|
||||||
// Joins two path segments with the given separator.
|
// Joins two path segments with the given separator.
|
||||||
std::string join_paths(const std::string_view left_path,
|
std::string join_paths(const std::string_view left_path,
|
||||||
const std::string_view right_path,
|
const std::string_view right_path,
|
||||||
char32_t sep = kPathSeparator);
|
char32_t separator = kPathSeparator);
|
||||||
|
|
||||||
std::string join_paths(std::vector<std::string_view> paths,
|
std::string join_paths(std::vector<std::string_view> paths,
|
||||||
char32_t sep = kPathSeparator);
|
char32_t separator = kPathSeparator);
|
||||||
|
|
||||||
inline std::string join_paths(
|
inline std::string join_paths(
|
||||||
std::initializer_list<const std::string_view> paths,
|
std::initializer_list<const std::string_view> paths,
|
||||||
char32_t sep = kPathSeparator) {
|
char32_t separator = kPathSeparator) {
|
||||||
std::string result;
|
std::string result;
|
||||||
for (auto path : paths) {
|
for (auto path : paths) {
|
||||||
result = join_paths(result, path, sep);
|
result = join_paths(result, path, separator);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ inline std::string join_guest_paths(
|
||||||
// Replaces all path separators with the given value and removes redundant
|
// Replaces all path separators with the given value and removes redundant
|
||||||
// separators.
|
// separators.
|
||||||
std::string fix_path_separators(const std::string_view path,
|
std::string fix_path_separators(const std::string_view path,
|
||||||
char32_t new_sep = kPathSeparator);
|
char32_t new_separator = kPathSeparator);
|
||||||
|
|
||||||
inline std::string fix_guest_path_separators(const std::string_view path) {
|
inline std::string fix_guest_path_separators(const std::string_view path) {
|
||||||
return fix_path_separators(path, kGuestPathSeparator);
|
return fix_path_separators(path, kGuestPathSeparator);
|
||||||
|
@ -106,14 +106,14 @@ inline std::string fix_guest_path_separators(const std::string_view path) {
|
||||||
|
|
||||||
// Find the top directory name or filename from a path.
|
// Find the top directory name or filename from a path.
|
||||||
std::string find_name_from_path(const std::string_view path,
|
std::string find_name_from_path(const std::string_view path,
|
||||||
char32_t sep = kPathSeparator);
|
char32_t separator = kPathSeparator);
|
||||||
|
|
||||||
inline std::string find_name_from_guest_path(const std::string_view path) {
|
inline std::string find_name_from_guest_path(const std::string_view path) {
|
||||||
return find_name_from_path(path, kGuestPathSeparator);
|
return find_name_from_path(path, kGuestPathSeparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string find_base_name_from_path(const std::string_view path,
|
std::string find_base_name_from_path(const std::string_view path,
|
||||||
char32_t sep = kPathSeparator);
|
char32_t separator = kPathSeparator);
|
||||||
|
|
||||||
inline std::string find_base_name_from_guest_path(const std::string_view path) {
|
inline std::string find_base_name_from_guest_path(const std::string_view path) {
|
||||||
return find_base_name_from_path(path, kGuestPathSeparator);
|
return find_base_name_from_path(path, kGuestPathSeparator);
|
||||||
|
@ -121,7 +121,7 @@ inline std::string find_base_name_from_guest_path(const std::string_view path) {
|
||||||
|
|
||||||
// Get parent path of the given directory or filename.
|
// Get parent path of the given directory or filename.
|
||||||
std::string find_base_path(const std::string_view path,
|
std::string find_base_path(const std::string_view path,
|
||||||
char32_t sep = kPathSeparator);
|
char32_t separator = kPathSeparator);
|
||||||
|
|
||||||
inline std::string find_base_guest_path(const std::string_view path) {
|
inline std::string find_base_guest_path(const std::string_view path) {
|
||||||
return find_base_path(path, kGuestPathSeparator);
|
return find_base_path(path, kGuestPathSeparator);
|
||||||
|
@ -129,7 +129,7 @@ inline std::string find_base_guest_path(const std::string_view path) {
|
||||||
|
|
||||||
// Canonicalizes a path, removing ..'s.
|
// Canonicalizes a path, removing ..'s.
|
||||||
std::string canonicalize_path(const std::string_view path,
|
std::string canonicalize_path(const std::string_view path,
|
||||||
char32_t sep = kPathSeparator);
|
char32_t separator = kPathSeparator);
|
||||||
|
|
||||||
inline std::string canonicalize_guest_path(const std::string_view path) {
|
inline std::string canonicalize_guest_path(const std::string_view path) {
|
||||||
return canonicalize_path(path, kGuestPathSeparator);
|
return canonicalize_path(path, kGuestPathSeparator);
|
||||||
|
|
Loading…
Reference in New Issue