John_R_Ellis's profile
Champion

Champion

 • 

6K Messages

 • 

103.7K Points

Wed, Apr 19, 2017 7:07 AM

Closed

Solved

Lightroom SDK: LrStringUtils.compareStrings() doesn't compare strings with digits correctly

LrStringUtils.compareStrings() doesn't compare strings containing digits correctly.  For example, it says that "a9b" comes before "a10b":



It appears that compareStrings() is comparing sequences of digits numerically, e.g. as the numbers 9 and 10 in the example above.   While that definition can be useful in some cases, such as ordering filenames containing sequence numbers, it is not generally useful for sorting.  

The SDK should restore the traditional meaning to compareStrings() and optionally provide a second compare function for the current functionality.

Official Solution

Adobe Administrator

 • 

109 Messages

 • 

2.9K Points

4 y ago

Hi all,

This issue should be fixed in today's Lightroom Classic CC 7.2 version. Please update your application and let us know if you still see this issue!

Lightroom Classic CC 7.2 is now available!

Thanks,
Melissa

Adobe Administrator

 • 

563 Messages

 • 

10.2K Points

5 y ago

Thanks for reporting this.
Let us look into it.

Thanks,
Sunil

42 Messages

 • 

866 Points

5 y ago

Currently LrStringUtils provides only single comparison function to compare 2 strings, which does numeric string search.
E.g.,, image_7 < image_15.
This is because all the filenames or timing data follow this natural order. So, for practical scenarios, this function should suffice. image_7 is supposed to come before image_15 in sorted order.

But, yes the SDK should provide a comparison function similar to C's strcmp().
We'll look into it. And also try to describe the APIs in documentation a bit more.

Thanks for reporting.

Thanks,
Abhishek

Champion

 • 

6K Messages

 • 

103.7K Points

Thanks.

Champion

 • 

6K Messages

 • 

103.7K Points

4 y ago

Absent updated SDK documentation, some reverse engineering suggests the following new definition of compareStrings() in LR 7.2:

LrStringUtils.compareStrings (string x, string y [, boolean strictAlphanumeric])

Returns true iff the string "x" precedes the string "y" in the user's locale. 

If "strictAlphanumeric" is true, the strings are compared using normal alphanumeric comparisons.

If "strictAlphanumeric" is false (the default), sequences of digits within the strings are interpreted as numbers and compared as numbers rather than strings, similar to how Mac Finder and Windows File Explorer sort filenames. For example, "a9x" < "a10x". 

More precisely, the strings "x" and "y" are parsed into maximal sequences of non-digits and digits, and the corresponding sequences compared in turn.  If corresponding sequences both contain digits only, they are compared as numbers, not strings; otherwise, they are compared as strings.

Adobe Administrator

 • 

563 Messages

 • 

10.2K Points

4 y ago

Thanks, John. We will revisit the documentation.

Thanks,
Sunil