BLI_path: only operate on native path slashes for BLI_path_name_at_index

Prefer using the native path separator for low level path functions.
This commit is contained in:
Campbell Barton 2022-10-31 13:21:24 +11:00
parent 8f7ab1bf46
commit 511ae22264
Notes: blender-bot 2023-02-14 07:17:43 +01:00
Referenced by commit a16ef95ff6, Fix T102914: bpy.ops.wm.append no longer supports / in paths for  WIN32
2 changed files with 16 additions and 12 deletions

View File

@ -1563,7 +1563,7 @@ bool BLI_path_name_at_index(const char *__restrict path,
int i = 0;
while (true) {
const char c = path[i];
if (ELEM(c, SEP, ALTSEP, '\0')) {
if (ELEM(c, SEP, '\0')) {
if (prev + 1 != i) {
prev += 1;
if (index_step == index) {
@ -1590,7 +1590,7 @@ bool BLI_path_name_at_index(const char *__restrict path,
int i = prev - 1;
while (true) {
const char c = i >= 0 ? path[i] : '\0';
if (ELEM(c, SEP, ALTSEP, '\0')) {
if (ELEM(c, SEP, '\0')) {
if (prev - 1 != i) {
i += 1;
if (index_step == index) {

View File

@ -72,6 +72,10 @@ TEST(path_util, Clean)
#define AT_INDEX(str_input, index_input, str_expect) \
{ \
char path[] = str_input; \
/* Test input assumes forward slash, support back-slash on WIN32. */ \
if (SEP == '\\') { \
BLI_str_replace_char(path, '/', '\\'); \
} \
const char *expect = str_expect; \
int index_output, len_output; \
const bool ret = BLI_path_name_at_index(path, index_input, &index_output, &len_output); \
@ -166,21 +170,21 @@ TEST(path_util, NameAtIndex_MiscNeg)
TEST(path_util, NameAtIndex_MiscComplex)
{
AT_INDEX("how//now/brown/cow", 0, "how");
AT_INDEX("//how///now\\/brown/cow", 1, "now");
AT_INDEX("/how/now\\//brown\\/cow", 2, "brown");
AT_INDEX("/how/now/brown/cow//\\", 3, "cow");
AT_INDEX("/how/now/brown/\\cow", 4, nullptr);
AT_INDEX("how/now/brown/\\cow\\", 4, nullptr);
AT_INDEX("//how///now//brown/cow", 1, "now");
AT_INDEX("/how/now///brown//cow", 2, "brown");
AT_INDEX("/how/now/brown/cow///", 3, "cow");
AT_INDEX("/how/now/brown//cow", 4, nullptr);
AT_INDEX("how/now/brown//cow/", 4, nullptr);
}
TEST(path_util, NameAtIndex_MiscComplexNeg)
{
AT_INDEX("how//now/brown/cow", -4, "how");
AT_INDEX("//how///now\\/brown/cow", -3, "now");
AT_INDEX("/how/now\\//brown\\/cow", -2, "brown");
AT_INDEX("/how/now/brown/cow//\\", -1, "cow");
AT_INDEX("/how/now/brown/\\cow", -5, nullptr);
AT_INDEX("how/now/brown/\\cow\\", -5, nullptr);
AT_INDEX("//how///now//brown/cow", -3, "now");
AT_INDEX("/how/now///brown//cow", -2, "brown");
AT_INDEX("/how/now/brown/cow///", -1, "cow");
AT_INDEX("/how/now/brown//cow", -5, nullptr);
AT_INDEX("how/now/brown//cow/", -5, nullptr);
}
TEST(path_util, NameAtIndex_NoneComplex)