[Bf-blender-cvs] [511ae222647] master: BLI_path: only operate on native path slashes for BLI_path_name_at_index

Campbell Barton noreply at git.blender.org
Mon Oct 31 03:23:08 CET 2022


Commit: 511ae2226473df57e47b439392da387cd355abef
Author: Campbell Barton
Date:   Mon Oct 31 13:21:24 2022 +1100
Branches: master
https://developer.blender.org/rB511ae2226473df57e47b439392da387cd355abef

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.

===================================================================

M	source/blender/blenlib/intern/path_util.c
M	source/blender/blenlib/tests/BLI_path_util_test.cc

===================================================================

diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 4e3d9be6186..b16cf8ea161 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -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) {
diff --git a/source/blender/blenlib/tests/BLI_path_util_test.cc b/source/blender/blenlib/tests/BLI_path_util_test.cc
index 1120e85c959..1241c71cf94 100644
--- a/source/blender/blenlib/tests/BLI_path_util_test.cc
+++ b/source/blender/blenlib/tests/BLI_path_util_test.cc
@@ -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)



More information about the Bf-blender-cvs mailing list