• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

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

LEGEND ,
Apr 19, 2017 Apr 19, 2017

Copy link to clipboard

Copied

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

RackMultipart201704191286841nk-b41ef8e9-131e-47d1-94e5-e06871821976-651874383.pngRackMultipart201704191286841nk-b41ef8e9-131e-47d1-94e5-e06871821976-651874383.png

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.

Bug Fixed
TOPICS
SDK

Views

137

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , Feb 12, 2018 Feb 12, 2018
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

Votes

Translate

Translate
8 Comments
Adobe Employee ,
Apr 19, 2017 Apr 19, 2017

Copy link to clipboard

Copied

Thanks for reporting this.
Let us look into it.

Thanks,
Sunil

Votes

Translate

Translate

Report

Report
Community Beginner ,
Apr 19, 2017 Apr 19, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
LEGEND ,
Apr 19, 2017 Apr 19, 2017

Copy link to clipboard

Copied

Thanks.

Votes

Translate

Translate

Report

Report
Adobe Employee ,
Feb 12, 2018 Feb 12, 2018

Copy link to clipboard

Copied

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
Melissa Rios, Product Manager, Community Experiences & Platforms | Adobe

Votes

Translate

Translate

Report

Report
LEGEND ,
Mar 08, 2018 Mar 08, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
LEGEND ,
Mar 08, 2018 Mar 08, 2018

Copy link to clipboard

Copied

Prior to LR 7.2, LrStringUtils.compareStrings() compared numbers embedded in the middle of strings as numbers, not as strings, e.g. "a9x" < "a10x", similar to how Mac Finder and Windows File Explorer sort filenames.  LR 7.2 enhances that functionality to provide traditional string compare:

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

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.

Votes

Translate

Translate

Report

Report
Adobe Employee ,
Mar 09, 2018 Mar 09, 2018

Copy link to clipboard

Copied

Thanks, John. We will revisit the documentation.

Thanks,
Sunil

Votes

Translate

Translate

Report

Report
LEGEND ,
Aug 30, 2022 Aug 30, 2022

Copy link to clipboard

Copied

LATEST

Votes

Translate

Translate

Report

Report