Skip to content

Exiv2::XmpData::sortByKey does not sort numerically correct #1424

@phako

Description

@phako

Describe the bug
sortByKey() does not sort numerically correct, i.e. 10, 11, 1, 2, instead of the expected 1, 2, 10, 11:

Xmp.xmpMM.History
Xmp.xmpMM.History[10]
Xmp.xmpMM.History[10]/stEvt:action
Xmp.xmpMM.History[10]/stEvt:parameters
Xmp.xmpMM.History[11]
Xmp.xmpMM.History[11]/stEvt:action
Xmp.xmpMM.History[11]/stEvt:changed
Xmp.xmpMM.History[11]/stEvt:instanceID
Xmp.xmpMM.History[11]/stEvt:softwareAgent
Xmp.xmpMM.History[11]/stEvt:when
Xmp.xmpMM.History[1]
Xmp.xmpMM.History[1]/stEvt:action
Xmp.xmpMM.History[1]/stEvt:parameters
Xmp.xmpMM.History[2]
Xmp.xmpMM.History[2]/stEvt:action
Xmp.xmpMM.History[2]/stEvt:changed
Xmp.xmpMM.History[2]/stEvt:instanceID
Xmp.xmpMM.History[2]/stEvt:softwareAgent
Xmp.xmpMM.History[2]/stEvt:when
Xmp.xmpMM.History[3]
Xmp.xmpMM.History[3]/stEvt:action
Xmp.xmpMM.History[3]/stEvt:parameters
Xmp.xmpMM.History[4]
Xmp.xmpMM.History[4]/stEvt:action
Xmp.xmpMM.History[4]/stEvt:changed
Xmp.xmpMM.History[4]/stEvt:instanceID
Xmp.xmpMM.History[4]/stEvt:softwareAgent
Xmp.xmpMM.History[4]/stEvt:when
Xmp.xmpMM.History[5]
Xmp.xmpMM.History[5]/stEvt:action
Xmp.xmpMM.History[5]/stEvt:changed
Xmp.xmpMM.History[5]/stEvt:instanceID
Xmp.xmpMM.History[5]/stEvt:softwareAgent
Xmp.xmpMM.History[5]/stEvt:when
Xmp.xmpMM.History[6]
Xmp.xmpMM.History[6]/stEvt:action
Xmp.xmpMM.History[6]/stEvt:parameters
Xmp.xmpMM.History[7]
Xmp.xmpMM.History[7]/stEvt:action
Xmp.xmpMM.History[7]/stEvt:parameters
Xmp.xmpMM.History[8]
Xmp.xmpMM.History[8]/stEvt:action
Xmp.xmpMM.History[8]/stEvt:changed
Xmp.xmpMM.History[8]/stEvt:instanceID
Xmp.xmpMM.History[8]/stEvt:softwareAgent
Xmp.xmpMM.History[8]/stEvt:when
Xmp.xmpMM.History[9]
Xmp.xmpMM.History[9]/stEvt:action
Xmp.xmpMM.History[9]/stEvt:parameters

To Reproduce

    auto xmp_data = image->xmpData();
    xmp_data.sortByKey();

    for(auto k: xmp_data) {
        std::cout << k.key() << std::endl;
    }

Steps to reproduce the behaviour:

  1. Provide the image with which you observed the issue (commonly named PoC)
  2. Provide exact command to reproduce the issue
  3. Mention the branch/commit in which you observed the issue (i.e: master or 0.27-maintenance)

Expected behavior
10 and 11 are sorted after 9:

Xmp.xmpMM.History
Xmp.xmpMM.History[1]
Xmp.xmpMM.History[1]/stEvt:action
Xmp.xmpMM.History[1]/stEvt:parameters
Xmp.xmpMM.History[2]
Xmp.xmpMM.History[2]/stEvt:action
Xmp.xmpMM.History[2]/stEvt:changed
Xmp.xmpMM.History[2]/stEvt:instanceID
Xmp.xmpMM.History[2]/stEvt:softwareAgent
Xmp.xmpMM.History[2]/stEvt:when
Xmp.xmpMM.History[3]
Xmp.xmpMM.History[3]/stEvt:action
Xmp.xmpMM.History[3]/stEvt:parameters
Xmp.xmpMM.History[4]
Xmp.xmpMM.History[4]/stEvt:action
Xmp.xmpMM.History[4]/stEvt:changed
Xmp.xmpMM.History[4]/stEvt:instanceID
Xmp.xmpMM.History[4]/stEvt:softwareAgent
Xmp.xmpMM.History[4]/stEvt:when
Xmp.xmpMM.History[5]
Xmp.xmpMM.History[5]/stEvt:action
Xmp.xmpMM.History[5]/stEvt:changed
Xmp.xmpMM.History[5]/stEvt:instanceID
Xmp.xmpMM.History[5]/stEvt:softwareAgent
Xmp.xmpMM.History[5]/stEvt:when
Xmp.xmpMM.History[6]
Xmp.xmpMM.History[6]/stEvt:action
Xmp.xmpMM.History[6]/stEvt:parameters
Xmp.xmpMM.History[7]
Xmp.xmpMM.History[7]/stEvt:action
Xmp.xmpMM.History[7]/stEvt:parameters
Xmp.xmpMM.History[8]
Xmp.xmpMM.History[8]/stEvt:action
Xmp.xmpMM.History[8]/stEvt:changed
Xmp.xmpMM.History[8]/stEvt:instanceID
Xmp.xmpMM.History[8]/stEvt:softwareAgent
Xmp.xmpMM.History[8]/stEvt:when
Xmp.xmpMM.History[9]
Xmp.xmpMM.History[9]/stEvt:action
Xmp.xmpMM.History[9]/stEvt:parameters
Xmp.xmpMM.History[10]
Xmp.xmpMM.History[10]/stEvt:action
Xmp.xmpMM.History[10]/stEvt:parameters
Xmp.xmpMM.History[11]
Xmp.xmpMM.History[11]/stEvt:action
Xmp.xmpMM.History[11]/stEvt:changed
Xmp.xmpMM.History[11]/stEvt:instanceID
Xmp.xmpMM.History[11]/stEvt:softwareAgent
Xmp.xmpMM.History[11]/stEvt:when

I've written a port of Shotwell's collate function (https://gitlab.gnome.org/GNOME/shotwell/-/blob/master/src/NaturalCollate.vala) to C++. The port completely ignores the existence of UTF8 but I think this is not an issue for keys of meta-data.

I am using this this in gexiv2 here:

https://gitlab.gnome.org/GNOME/gexiv2/-/blob/wip/58/gexiv2/gexiv2-metadata.cpp#L244

Desktop (please complete the following information):

  • OS: Fedora Linux 33
  • Compiler & Version: GCC 10.2.1

Metadata

Metadata

Assignees

Labels

enhancementfeature / functionality enhancements

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions