From 61c246f08321e7de4f4c8928dfdd64c390e90e78 Mon Sep 17 00:00:00 2001 From: bananeweizen Date: Sat, 20 Aug 2011 11:50:51 +0200 Subject: avoid getting NUMBER if it is not needed for logging, as discussed in #232 --- src/cgeo/geocaching/LogTemplateProvider.java | 43 ++++++++++++++++++++++++++-- src/cgeo/geocaching/cgBase.java | 31 -------------------- 2 files changed, 41 insertions(+), 33 deletions(-) (limited to 'src') 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 params = new HashMap(); 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*\\s*(\\d+)", 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*\\s*(\\d+)", 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 ""; -- cgit v1.1