diff options
| author | bananeweizen <bananeweizen@gmx.de> | 2011-08-20 11:50:51 +0200 |
|---|---|---|
| committer | bananeweizen <bananeweizen@gmx.de> | 2011-08-20 11:50:51 +0200 |
| commit | 61c246f08321e7de4f4c8928dfdd64c390e90e78 (patch) | |
| tree | 7624f5d5f2ddc8d3eb0bbfd8d0a8b0547ff0e29e | |
| parent | 5fe847e37890d415eb43591e1b41a61a59926d70 (diff) | |
| download | cgeo-61c246f08321e7de4f4c8928dfdd64c390e90e78.zip cgeo-61c246f08321e7de4f4c8928dfdd64c390e90e78.tar.gz cgeo-61c246f08321e7de4f4c8928dfdd64c390e90e78.tar.bz2 | |
avoid getting NUMBER if it is not needed for logging, as discussed in
#232
| -rw-r--r-- | src/cgeo/geocaching/LogTemplateProvider.java | 43 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgBase.java | 31 |
2 files changed, 41 insertions, 33 deletions
diff --git a/src/cgeo/geocaching/LogTemplateProvider.java b/src/cgeo/geocaching/LogTemplateProvider.java index 09acd0d..05d1341 100644 --- a/src/cgeo/geocaching/LogTemplateProvider.java +++ b/src/cgeo/geocaching/LogTemplateProvider.java @@ -1,6 +1,10 @@ package cgeo.geocaching;
import java.util.HashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import android.util.Log;
/**
@@ -32,7 +36,10 @@ public class LogTemplateProvider { }
protected String apply(String input, cgBase base) {
- return input.replaceAll("\\[" + template + "\\]", getValue(base));
+ if (input.contains("[" + template + "]")) {
+ return input.replaceAll("\\[" + template + "\\]", getValue(base));
+ }
+ return input;
}
}
@@ -69,7 +76,7 @@ public class LogTemplateProvider { String findCount = "";
final HashMap<String, String> params = new HashMap<String, String>();
final String page = base.request(false, "www.geocaching.com", "/my/", "GET", params, false, false, false).getData();
- int current = cgBase.parseFindCount(page);
+ int current = parseFindCount(page);
if (current >= 0) {
findCount = String.valueOf(current + 1);
@@ -101,5 +108,37 @@ public class LogTemplateProvider { }
return result;
}
+
+ private static int parseFindCount(String page) {
+ if (page == null || page.length() == 0) {
+ return -1;
+ }
+
+ int findCount = -1;
+
+ try {
+ final Pattern findPattern = Pattern.compile("Finds\\s*</strong>\\s*<span class=\"statcount\">(\\d+)</span>", Pattern.CASE_INSENSITIVE);
+ final Matcher findMatcher = findPattern.matcher(page);
+ if (findMatcher.find()) {
+ if (findMatcher.groupCount() > 0) {
+ String count = findMatcher.group(1);
+
+ if (count != null) {
+ if (count.length() == 0) {
+ findCount = 0;
+ } else {
+ findCount = Integer.parseInt(count);
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ Log.w(cgSettings.tag, "cgBase.parseFindCount: " + e.toString());
+ }
+
+ return findCount;
+ }
+
+
}
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index a5b93a1..38e2d9e 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -2576,37 +2576,6 @@ public class cgBase { return trackables; } - public static int parseFindCount(String page) { - if (page == null || page.length() == 0) { - return -1; - } - - int findCount = -1; - - try { - final Pattern findPattern = Pattern.compile("Finds\\s*</strong>\\s*<span class=\"statcount\">(\\d+)</span>", Pattern.CASE_INSENSITIVE); - final Matcher findMatcher = findPattern.matcher(page); - if (findMatcher.find()) { - if (findMatcher.groupCount() > 0) { - String count = findMatcher.group(1); - - if (count != null) { - if (count.length() == 0) { - findCount = 0; - } else { - findCount = Integer.parseInt(count); - } - } - } - } - } catch (Exception e) { - Log.w(cgSettings.tag, "cgBase.parseFindCount: " + e.toString()); - } - - return findCount; - } - - public static String stripParagraphs(String text) { if (text == null) { return ""; |
