diff options
Diffstat (limited to 'main/src/cgeo/geocaching/files/GPXParser.java')
| -rw-r--r-- | main/src/cgeo/geocaching/files/GPXParser.java | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index 01929c6..c1cc1a3 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -260,12 +260,18 @@ public abstract class GPXParser extends FileParser { @Override public void end() { + // try to find geocode somewhere else if (StringUtils.isBlank(cache.getGeocode())) { - // try to find geocode somewhere else findGeoCode(name); findGeoCode(desc); findGeoCode(cmt); } + // take the name as code, if nothing else is available + if (StringUtils.isBlank(cache.getGeocode())) { + if (StringUtils.isNotBlank(name)) { + cache.setGeocode(name.trim()); + } + } if (StringUtils.isNotBlank(cache.getGeocode()) && cache.getCoords() != null @@ -772,11 +778,15 @@ public abstract class GPXParser extends FileParser { if (input == null || StringUtils.isNotBlank(cache.getGeocode())) { return; } - final Matcher matcherGeocode = patternGeocode.matcher(input); + final String trimmed = input.trim(); + final Matcher matcherGeocode = patternGeocode.matcher(trimmed); if (matcherGeocode.find()) { final String geocode = matcherGeocode.group(1); - if (ConnectorFactory.canHandle(geocode)) { - cache.setGeocode(geocode); + // a geocode should not be part of a word + if (geocode.length() == trimmed.length() || Character.isWhitespace(trimmed.charAt(geocode.length()))) { + if (ConnectorFactory.canHandle(geocode)) { + cache.setGeocode(geocode); + } } } } |
