BLI_path: add BLI_path_slash_skip utility function

Avoids having to add inline loops that step over slashes.
This commit is contained in:
Campbell Barton 2023-06-13 14:36:32 +10:00
parent 508a2d8125
commit 57dc36fb98
2 changed files with 14 additions and 3 deletions

View File

@ -265,6 +265,10 @@ int BLI_path_slash_ensure(char *path, size_t path_maxncpy) ATTR_NONNULL(1);
* Removes the last slash and everything after it to the end of path, if there is one.
*/
void BLI_path_slash_rstrip(char *path) ATTR_NONNULL(1);
/**
* \return the next non-slash character or the null byte (when `path` only contains slashes).
*/
const char *BLI_path_slash_skip(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
/**
* Changes to the path separators to the native ones for this OS.
*/

View File

@ -1118,9 +1118,7 @@ bool BLI_path_abs(char path[FILE_MAX], const char *basepath)
BLI_assert(strlen(tmp) == root_dir_len);
/* Step over the slashes at the beginning of the path. */
while (BLI_path_slash_is_native_compat(*p)) {
p++;
}
p = (char *)BLI_path_slash_skip(p);
BLI_strncpy(tmp + root_dir_len, p, sizeof(tmp) - root_dir_len);
}
else {
@ -1958,6 +1956,15 @@ void BLI_path_slash_rstrip(char *path)
}
}
const char *BLI_path_slash_skip(const char *path)
{
/* This accounts for a null byte too. */
while (BLI_path_slash_is_native_compat(*path)) {
path++;
}
return path;
}
void BLI_path_slash_native(char *path)
{
#ifdef WIN32