summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/UrlUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/browser/UrlUtils.java')
-rw-r--r--src/com/android/browser/UrlUtils.java15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/com/android/browser/UrlUtils.java b/src/com/android/browser/UrlUtils.java
index c922e55..681b242 100644
--- a/src/com/android/browser/UrlUtils.java
+++ b/src/com/android/browser/UrlUtils.java
@@ -40,28 +40,29 @@ public class UrlUtils {
private final static String QUICKSEARCH_G = "http://www.google.com/m?q=%s";
private final static String QUERY_PLACE_HOLDER = "%s";
- // Regular expression which matches http://, followed by some stuff, followed by
- // optionally a trailing slash, all matched as separate groups.
- private static final Pattern STRIP_URL_PATTERN = Pattern.compile("^(http://)(.*?)(/$)?");
+ // Regular expression to strip http://, optionally www., and optionally
+ // the trailing slash
+ private static final Pattern STRIP_URL_PATTERN =
+ Pattern.compile("^http://(?:www\\.)?(.*?)/?$");
private UrlUtils() { /* cannot be instantiated */ }
/**
- * Strips the provided url of preceding "http://" and any trailing "/". Does not
+ * Strips the provided url of preceding "http://", "www.", and any trailing "/". Does not
* strip "https://". If the provided string cannot be stripped, the original string
* is returned.
*
* TODO: Put this in TextUtils to be used by other packages doing something similar.
*
* @param url a url to strip, like "http://www.google.com/"
- * @return a stripped url like "www.google.com", or the original string if it could
+ * @return a stripped url like "google.com", or the original string if it could
* not be stripped
*/
public static String stripUrl(String url) {
if (url == null) return null;
Matcher m = STRIP_URL_PATTERN.matcher(url);
- if (m.matches() && m.groupCount() == 3) {
- return m.group(2);
+ if (m.matches()) {
+ return m.group(1);
} else {
return url;
}