Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <eiseljulian@gmail.com>2020-01-08 18:04:00 +0300
committerJulian Eisel <eiseljulian@gmail.com>2020-01-08 18:08:10 +0300
commitf52d9a878de95ca50788f1773d2c7c48301a6789 (patch)
treecc700146387dd8dc83d68a02f0c1b4b4167031d4 /source/blender/blenlib
parent525b0e0ccb088fc3e3d947de1376b570de3fb849 (diff)
Fix T72878: Alphabetical sorting in Outliner sorts shorter names last
E.g. "Cube" would be placed after "Cube.001", which is not what you'd expect. 2.80 handled this correctly. Loosely based on D6525 by @radcapricorn, but found a bug in that and prefered to do some further adjustments. Also activates test for this case.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/intern/string.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index 0b8ec44cbcd..1eed59e568e 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -685,6 +685,7 @@ int BLI_strcasecmp_natural(const char *s1, const char *s2)
return numcompare;
}
+ /* Some wasted work here, left_number_strcmp already consumes at least some digits. */
d1++;
while (isdigit(s1[d1])) {
d1++;
@@ -695,14 +696,22 @@ int BLI_strcasecmp_natural(const char *s1, const char *s2)
}
}
+ /* Test for end of strings first so that shorter strings are ordered in front. */
+ if (ELEM(0, s1[d1], s2[d2])) {
+ break;
+ }
+
c1 = tolower(s1[d1]);
c2 = tolower(s2[d2]);
- /* first check for '.' so "foo.bar" comes before "foo 1.bar" */
- if (c1 == '.' && c2 != '.') {
+ if (c1 == c2) {
+ /* Continue iteration */
+ }
+ /* Check for '.' so "foo.bar" comes before "foo 1.bar". */
+ else if (c1 == '.') {
return -1;
}
- if (c1 != '.' && c2 == '.') {
+ else if (c2 == '.') {
return 1;
}
else if (c1 < c2) {
@@ -711,9 +720,7 @@ int BLI_strcasecmp_natural(const char *s1, const char *s2)
else if (c1 > c2) {
return 1;
}
- else if (c1 == 0) {
- break;
- }
+
d1++;
d2++;
}