diff options
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/app/SearchDialog.java | 5 | ||||
-rw-r--r-- | core/java/android/provider/Gmail.java | 5 | ||||
-rw-r--r-- | core/java/android/provider/Telephony.java | 7 | ||||
-rw-r--r-- | core/java/android/text/util/Linkify.java | 10 | ||||
-rw-r--r-- | core/java/android/text/util/Regex.java | 204 |
5 files changed, 16 insertions, 215 deletions
diff --git a/core/java/android/app/SearchDialog.java b/core/java/android/app/SearchDialog.java index e5a769b..0757cb0 100644 --- a/core/java/android/app/SearchDialog.java +++ b/core/java/android/app/SearchDialog.java @@ -43,7 +43,6 @@ import android.text.Editable; import android.text.InputType; import android.text.TextUtils; import android.text.TextWatcher; -import android.text.util.Regex; import android.util.AndroidRuntimeException; import android.util.AttributeSet; import android.util.Log; @@ -69,6 +68,8 @@ import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemSelectedListener; +import com.android.common.Patterns; + import java.util.ArrayList; import java.util.WeakHashMap; import java.util.concurrent.atomic.AtomicLong; @@ -823,7 +824,7 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS // The user changed the query, check if it is a URL and if so change the search // button in the soft keyboard to the 'Go' button. int options = (mSearchAutoComplete.getImeOptions() & (~EditorInfo.IME_MASK_ACTION)); - if (Regex.WEB_URL_PATTERN.matcher(mUserQuery).matches()) { + if (Patterns.WEB_URL.matcher(mUserQuery).matches()) { options = options | EditorInfo.IME_ACTION_GO; } else { options = options | EditorInfo.IME_ACTION_SEARCH; diff --git a/core/java/android/provider/Gmail.java b/core/java/android/provider/Gmail.java index 073ae6c..8bb7adf 100644 --- a/core/java/android/provider/Gmail.java +++ b/core/java/android/provider/Gmail.java @@ -37,9 +37,10 @@ import android.text.Spanned; import android.text.TextUtils; import android.text.TextUtils.SimpleStringSplitter; import android.text.style.CharacterStyle; -import android.text.util.Regex; import android.util.Log; +import com.android.common.Patterns; + import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; @@ -192,7 +193,7 @@ public final class Gmail { */ public static String getEmailFromAddressString(String addressString) { String result = addressString; - Matcher match = Regex.EMAIL_ADDRESS_PATTERN.matcher(addressString); + Matcher match = Patterns.EMAIL_ADDRESS.matcher(addressString); if (match.find()) { result = addressString.substring(match.start(), match.end()); } diff --git a/core/java/android/provider/Telephony.java b/core/java/android/provider/Telephony.java index 9a72d93..6380a8d 100644 --- a/core/java/android/provider/Telephony.java +++ b/core/java/android/provider/Telephony.java @@ -28,10 +28,11 @@ import android.database.Cursor; import android.net.Uri; import android.telephony.SmsMessage; import android.text.TextUtils; -import android.text.util.Regex; import android.util.Config; import android.util.Log; +import com.android.common.Patterns; + import java.util.HashSet; import java.util.Set; import java.util.regex.Matcher; @@ -1290,7 +1291,7 @@ public final class Telephony { } String s = extractAddrSpec(address); - Matcher match = Regex.EMAIL_ADDRESS_PATTERN.matcher(s); + Matcher match = Patterns.EMAIL_ADDRESS.matcher(s); return match.matches(); } @@ -1305,7 +1306,7 @@ public final class Telephony { return false; } - Matcher match = Regex.PHONE_PATTERN.matcher(number); + Matcher match = Patterns.PHONE.matcher(number); return match.matches(); } diff --git a/core/java/android/text/util/Linkify.java b/core/java/android/text/util/Linkify.java index ce25c47..7f87365 100644 --- a/core/java/android/text/util/Linkify.java +++ b/core/java/android/text/util/Linkify.java @@ -25,6 +25,8 @@ import android.text.Spanned; import android.webkit.WebView; import android.widget.TextView; +import com.android.common.Patterns; + import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; @@ -133,7 +135,7 @@ public class Linkify { */ public static final TransformFilter sPhoneNumberTransformFilter = new TransformFilter() { public final String transformUrl(final Matcher match, String url) { - return Regex.digitsAndPlusOnly(match); + return Patterns.digitsAndPlusOnly(match); } }; @@ -207,19 +209,19 @@ public class Linkify { ArrayList<LinkSpec> links = new ArrayList<LinkSpec>(); if ((mask & WEB_URLS) != 0) { - gatherLinks(links, text, Regex.WEB_URL_PATTERN, + gatherLinks(links, text, Patterns.WEB_URL, new String[] { "http://", "https://", "rtsp://" }, sUrlMatchFilter, null); } if ((mask & EMAIL_ADDRESSES) != 0) { - gatherLinks(links, text, Regex.EMAIL_ADDRESS_PATTERN, + gatherLinks(links, text, Patterns.EMAIL_ADDRESS, new String[] { "mailto:" }, null, null); } if ((mask & PHONE_NUMBERS) != 0) { - gatherLinks(links, text, Regex.PHONE_PATTERN, + gatherLinks(links, text, Patterns.PHONE, new String[] { "tel:" }, sPhoneNumberMatchFilter, sPhoneNumberTransformFilter); } diff --git a/core/java/android/text/util/Regex.java b/core/java/android/text/util/Regex.java deleted file mode 100644 index a6844a4..0000000 --- a/core/java/android/text/util/Regex.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.text.util; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * @hide - */ -public class Regex { - /** - * Regular expression pattern to match all IANA top-level domains. - * List accurate as of 2007/06/15. List taken from: - * http://data.iana.org/TLD/tlds-alpha-by-domain.txt - * This pattern is auto-generated by //device/tools/make-iana-tld-pattern.py - */ - public static final Pattern TOP_LEVEL_DOMAIN_PATTERN - = Pattern.compile( - "((aero|arpa|asia|a[cdefgilmnoqrstuwxz])" - + "|(biz|b[abdefghijmnorstvwyz])" - + "|(cat|com|coop|c[acdfghiklmnoruvxyz])" - + "|d[ejkmoz]" - + "|(edu|e[cegrstu])" - + "|f[ijkmor]" - + "|(gov|g[abdefghilmnpqrstuwy])" - + "|h[kmnrtu]" - + "|(info|int|i[delmnoqrst])" - + "|(jobs|j[emop])" - + "|k[eghimnrwyz]" - + "|l[abcikrstuvy]" - + "|(mil|mobi|museum|m[acdghklmnopqrstuvwxyz])" - + "|(name|net|n[acefgilopruz])" - + "|(org|om)" - + "|(pro|p[aefghklmnrstwy])" - + "|qa" - + "|r[eouw]" - + "|s[abcdeghijklmnortuvyz]" - + "|(tel|travel|t[cdfghjklmnoprtvwz])" - + "|u[agkmsyz]" - + "|v[aceginu]" - + "|w[fs]" - + "|y[etu]" - + "|z[amw])"); - - /** - * Regular expression pattern to match RFC 1738 URLs - * List accurate as of 2007/06/15. List taken from: - * http://data.iana.org/TLD/tlds-alpha-by-domain.txt - * This pattern is auto-generated by //device/tools/make-iana-tld-pattern.py - */ - public static final Pattern WEB_URL_PATTERN - = Pattern.compile( - "((?:(http|https|Http|Https|rtsp|Rtsp):\\/\\/(?:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)" - + "\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_" - + "\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?" - + "((?:(?:[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}\\.)+" // named host - + "(?:" // plus top level domain - + "(?:aero|arpa|asia|a[cdefgilmnoqrstuwxz])" - + "|(?:biz|b[abdefghijmnorstvwyz])" - + "|(?:cat|com|coop|c[acdfghiklmnoruvxyz])" - + "|d[ejkmoz]" - + "|(?:edu|e[cegrstu])" - + "|f[ijkmor]" - + "|(?:gov|g[abdefghilmnpqrstuwy])" - + "|h[kmnrtu]" - + "|(?:info|int|i[delmnoqrst])" - + "|(?:jobs|j[emop])" - + "|k[eghimnrwyz]" - + "|l[abcikrstuvy]" - + "|(?:mil|mobi|museum|m[acdghklmnopqrstuvwxyz])" - + "|(?:name|net|n[acefgilopruz])" - + "|(?:org|om)" - + "|(?:pro|p[aefghklmnrstwy])" - + "|qa" - + "|r[eouw]" - + "|s[abcdeghijklmnortuvyz]" - + "|(?:tel|travel|t[cdfghjklmnoprtvwz])" - + "|u[agkmsyz]" - + "|v[aceginu]" - + "|w[fs]" - + "|y[etu]" - + "|z[amw]))" - + "|(?:(?:25[0-5]|2[0-4]" // or ip address - + "[0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(?:25[0-5]|2[0-4][0-9]" - + "|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1]" - + "[0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}" - + "|[1-9][0-9]|[0-9])))" - + "(?:\\:\\d{1,5})?)" // plus option port number - + "(\\/(?:(?:[a-zA-Z0-9\\;\\/\\?\\:\\@\\&\\=\\#\\~" // plus option query params - + "\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*)?" - + "(?:\\b|$)"); // and finally, a word boundary or end of - // input. This is to stop foo.sure from - // matching as foo.su - - public static final Pattern IP_ADDRESS_PATTERN - = Pattern.compile( - "((25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(25[0-5]|2[0-4]" - + "[0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]" - + "[0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}" - + "|[1-9][0-9]|[0-9]))"); - - public static final Pattern DOMAIN_NAME_PATTERN - = Pattern.compile( - "(((([a-zA-Z0-9][a-zA-Z0-9\\-]*)*[a-zA-Z0-9]\\.)+" - + TOP_LEVEL_DOMAIN_PATTERN + ")|" - + IP_ADDRESS_PATTERN + ")"); - - public static final Pattern EMAIL_ADDRESS_PATTERN - = Pattern.compile( - "[a-zA-Z0-9\\+\\.\\_\\%\\-]{1,256}" + - "\\@" + - "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + - "(" + - "\\." + - "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + - ")+" - ); - - /** - * This pattern is intended for searching for things that look like they - * might be phone numbers in arbitrary text, not for validating whether - * something is in fact a phone number. It will miss many things that - * are legitimate phone numbers. - * - * <p> The pattern matches the following: - * <ul> - * <li>Optionally, a + sign followed immediately by one or more digits. Spaces, dots, or dashes - * may follow. - * <li>Optionally, sets of digits in parentheses, separated by spaces, dots, or dashes. - * <li>A string starting and ending with a digit, containing digits, spaces, dots, and/or dashes. - * </ul> - */ - public static final Pattern PHONE_PATTERN - = Pattern.compile( // sdd = space, dot, or dash - "(\\+[0-9]+[\\- \\.]*)?" // +<digits><sdd>* - + "(\\([0-9]+\\)[\\- \\.]*)?" // (<digits>)<sdd>* - + "([0-9][0-9\\- \\.][0-9\\- \\.]+[0-9])"); // <digit><digit|sdd>+<digit> - - /** - * Convenience method to take all of the non-null matching groups in a - * regex Matcher and return them as a concatenated string. - * - * @param matcher The Matcher object from which grouped text will - * be extracted - * - * @return A String comprising all of the non-null matched - * groups concatenated together - */ - public static final String concatGroups(Matcher matcher) { - StringBuilder b = new StringBuilder(); - final int numGroups = matcher.groupCount(); - - for (int i = 1; i <= numGroups; i++) { - String s = matcher.group(i); - - System.err.println("Group(" + i + ") : " + s); - - if (s != null) { - b.append(s); - } - } - - return b.toString(); - } - - /** - * Convenience method to return only the digits and plus signs - * in the matching string. - * - * @param matcher The Matcher object from which digits and plus will - * be extracted - * - * @return A String comprising all of the digits and plus in - * the match - */ - public static final String digitsAndPlusOnly(Matcher matcher) { - StringBuilder buffer = new StringBuilder(); - String matchingRegion = matcher.group(); - - for (int i = 0, size = matchingRegion.length(); i < size; i++) { - char character = matchingRegion.charAt(i); - - if (character == '+' || Character.isDigit(character)) { - buffer.append(character); - } - } - return buffer.toString(); - } -} |