package cgeo.geocaching.utils;

import cgeo.geocaching.models.Geocache;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Patterns;

import java.util.regex.Matcher;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;

public final class CheckerUtils {
    private static final String[] CHECKERS = { "geocheck.org/geo_inputchkcoord.php?", "geochecker.com/index.php?", "certitudes.org/certitude?", "geochecker.gps-cache.de/check.aspx?", "gc-apps.com/geochecker" };

    private CheckerUtils() {
        // utility class
    }

    @Nullable
    public static String getCheckerUrl(@NonNull final Geocache cache) {
        final String description = cache.getDescription();
        final Matcher matcher = Patterns.WEB_URL.matcher(description);
        while (matcher.find()) {
            final String url = matcher.group();
            for (final String checker : CHECKERS) {
                if (StringUtils.containsIgnoreCase(url, checker)) {
                    return StringEscapeUtils.unescapeHtml4(url);
                }
            }
        }
        return null;
    }
}

@@ -394,16 +394,151 @@
 KERS = %7B
+%0A            %22certitudes.org/certitude?%22,%0A            %22gc-apps.com/geochecker%22,%0A            %22gccounter.com/gcchecker.php?%22,%0A           
  %22geoche
@@ -568,16 +568,28 @@
 d.php?%22,
+%0A           
  %22geoche
@@ -613,37 +613,20 @@
 p?%22,
- %22certitudes.org/certitude?%22,
+%0A           
  %22ge
@@ -664,33 +664,12 @@
 x?%22,
- %22gc-apps.com/geochecker%22
+%0A   
  %7D;%0A

add one more geochecker