diff options
| author | Bananeweizen <Bananeweizen@gmx.de> | 2013-07-28 21:18:23 +0200 |
|---|---|---|
| committer | Bananeweizen <Bananeweizen@gmx.de> | 2013-07-28 21:18:23 +0200 |
| commit | 19b8392a73ed4655e6c6aa03b511ba7c70c7b177 (patch) | |
| tree | 0464dd862423e5b72f21de92c0074c0d8b6c1e8e /main/src/cgeo/geocaching/Geocache.java | |
| parent | 24413415dd85f5c4da3f86c98ec6c78fec0f257d (diff) | |
| download | cgeo-19b8392a73ed4655e6c6aa03b511ba7c70c7b177.zip cgeo-19b8392a73ed4655e6c6aa03b511ba7c70c7b177.tar.gz cgeo-19b8392a73ed4655e6c6aa03b511ba7c70c7b177.tar.bz2 | |
fix #3061: name sorting wrong for certain number combinations
Diffstat (limited to 'main/src/cgeo/geocaching/Geocache.java')
| -rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index 77efd7e..f229af8 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -834,12 +834,15 @@ public class Geocache implements ICache, IWaypoint { @Override public String getNameForSorting() { if (null == nameForSorting) { - final MatcherWrapper matcher = new MatcherWrapper(NUMBER_PATTERN, name); - if (matcher.find()) { - nameForSorting = name.replace(matcher.group(), StringUtils.leftPad(matcher.group(), 6, '0')); - } - else { - nameForSorting = name; + nameForSorting = name; + // pad each number part to a fixed size of 6 digits, so that numerical sorting becomes equivalent to string sorting + MatcherWrapper matcher = new MatcherWrapper(NUMBER_PATTERN, nameForSorting); + int start = 0; + while (matcher.find(start)) { + final String number = matcher.group(); + nameForSorting = StringUtils.substring(nameForSorting, 0, matcher.start()) + StringUtils.leftPad(number, 6, '0') + StringUtils.substring(nameForSorting, matcher.start() + number.length()); + start = matcher.start() + Math.max(6, number.length()); + matcher = new MatcherWrapper(NUMBER_PATTERN, nameForSorting); } } return nameForSorting; |
