diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2012-03-10 21:46:32 +0100 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2012-03-10 21:46:32 +0100 |
| commit | 491fdefaf2ab8adff5c62898fa00f9af2220b214 (patch) | |
| tree | 9091734e7f8786b8fcc5f1adc3cf23e822c9eae8 /main/src/cgeo/geocaching/connector/gc/UTFGridPosition.java | |
| parent | d40313cf48a9956487afd2b591b34d588bb4ae82 (diff) | |
| download | cgeo-491fdefaf2ab8adff5c62898fa00f9af2220b214.zip cgeo-491fdefaf2ab8adff5c62898fa00f9af2220b214.tar.gz cgeo-491fdefaf2ab8adff5c62898fa00f9af2220b214.tar.bz2 | |
fix #1262: icon decoding does not work well
Diffstat (limited to 'main/src/cgeo/geocaching/connector/gc/UTFGridPosition.java')
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/UTFGridPosition.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/UTFGridPosition.java b/main/src/cgeo/geocaching/connector/gc/UTFGridPosition.java index e88a425..1aae560 100644 --- a/main/src/cgeo/geocaching/connector/gc/UTFGridPosition.java +++ b/main/src/cgeo/geocaching/connector/gc/UTFGridPosition.java @@ -1,5 +1,8 @@ package cgeo.geocaching.connector.gc; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Representation of a position inside an UTFGrid @@ -11,6 +14,7 @@ public final class UTFGridPosition { public final int x; public final int y; + private final static Pattern PATTERN_JSON_KEY = Pattern.compile("[^\\d]*" + "(\\d+),\\s*(\\d+)" + "[^\\d]*"); // (12, 34) public UTFGridPosition(final int x, final int y) { assert x >= 0 && x <= UTFGrid.GRID_MAXX : "x outside bounds"; @@ -28,4 +32,22 @@ public final class UTFGridPosition { return y; } + /** + * @param key + * Key in the format (xx, xx) + * @return + */ + static UTFGridPosition fromString(String key) { + final Matcher matcher = UTFGridPosition.PATTERN_JSON_KEY.matcher(key); + try { + if (matcher.matches()) { + final int x = Integer.parseInt(matcher.group(1)); + final int y = Integer.parseInt(matcher.group(2)); + return new UTFGridPosition(x, y); + } + } catch (NumberFormatException e) { + } + return new UTFGridPosition(0, 0); + } + } |
