summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Android.mk1
-rw-r--r--common/Android.mk23
-rw-r--r--common/src/com/android/common/Patterns.java (renamed from core/java/android/text/util/Regex.java)27
-rw-r--r--common/tests/Android.mk26
-rw-r--r--common/tests/AndroidManifest.xml30
-rw-r--r--common/tests/src/com/android/common/PatternsTest.java (renamed from tests/AndroidTests/src/com/android/unit_tests/RegexTest.java)33
-rw-r--r--core/java/android/app/SearchDialog.java5
-rw-r--r--core/java/android/provider/Gmail.java5
-rw-r--r--core/java/android/provider/Telephony.java7
-rw-r--r--core/java/android/text/util/Linkify.java10
-rw-r--r--preloaded-classes1
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/PdpConnection.java4
-rw-r--r--tests/CoreTests/android/core/RegexTest.java1
13 files changed, 130 insertions, 43 deletions
diff --git a/Android.mk b/Android.mk
index 0d377c2..bc8b145 100644
--- a/Android.mk
+++ b/Android.mk
@@ -175,6 +175,7 @@ LOCAL_INTERMEDIATE_SOURCES := \
LOCAL_NO_STANDARD_LIBRARIES := true
LOCAL_JAVA_LIBRARIES := core ext
+LOCAL_STATIC_JAVA_LIBRARIES := android-common
LOCAL_MODULE := framework
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
diff --git a/common/Android.mk b/common/Android.mk
new file mode 100644
index 0000000..b74eab3
--- /dev/null
+++ b/common/Android.mk
@@ -0,0 +1,23 @@
+# Copyright (C) 2009 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := android-common
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+# Include this library in the build server's output directory
+$(call dist-for-goals, droid, $(LOCAL_BUILT_MODULE):android-common.jar)
diff --git a/core/java/android/text/util/Regex.java b/common/src/com/android/common/Patterns.java
index a6844a4..2eab3e1 100644
--- a/core/java/android/text/util/Regex.java
+++ b/common/src/com/android/common/Patterns.java
@@ -14,22 +14,22 @@
* limitations under the License.
*/
-package android.text.util;
+package com.android.common;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
- * @hide
+ * Commonly used regular expression patterns.
*/
-public class Regex {
+public class Patterns {
/**
* 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
+ public static final Pattern TOP_LEVEL_DOMAIN
= Pattern.compile(
"((aero|arpa|asia|a[cdefgilmnoqrstuwxz])"
+ "|(biz|b[abdefghijmnorstvwyz])"
@@ -63,7 +63,7 @@ public class Regex {
* 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
+ public static final Pattern WEB_URL
= Pattern.compile(
"((?:(http|https|Http|Https|rtsp|Rtsp):\\/\\/(?:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)"
+ "\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_"
@@ -107,20 +107,20 @@ public class Regex {
// input. This is to stop foo.sure from
// matching as foo.su
- public static final Pattern IP_ADDRESS_PATTERN
+ public static final Pattern IP_ADDRESS
= 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
+ public static final Pattern DOMAIN_NAME
= Pattern.compile(
"(((([a-zA-Z0-9][a-zA-Z0-9\\-]*)*[a-zA-Z0-9]\\.)+"
- + TOP_LEVEL_DOMAIN_PATTERN + ")|"
- + IP_ADDRESS_PATTERN + ")");
+ + TOP_LEVEL_DOMAIN + ")|"
+ + IP_ADDRESS + ")");
- public static final Pattern EMAIL_ADDRESS_PATTERN
+ public static final Pattern EMAIL_ADDRESS
= Pattern.compile(
"[a-zA-Z0-9\\+\\.\\_\\%\\-]{1,256}" +
"\\@" +
@@ -145,7 +145,7 @@ public class Regex {
* <li>A string starting and ending with a digit, containing digits, spaces, dots, and/or dashes.
* </ul>
*/
- public static final Pattern PHONE_PATTERN
+ public static final Pattern PHONE
= Pattern.compile( // sdd = space, dot, or dash
"(\\+[0-9]+[\\- \\.]*)?" // +<digits><sdd>*
+ "(\\([0-9]+\\)[\\- \\.]*)?" // (<digits>)<sdd>*
@@ -201,4 +201,9 @@ public class Regex {
}
return buffer.toString();
}
+
+ /**
+ * Do not create this static utility class.
+ */
+ private Patterns() {}
}
diff --git a/common/tests/Android.mk b/common/tests/Android.mk
new file mode 100644
index 0000000..0f2c3e4
--- /dev/null
+++ b/common/tests/Android.mk
@@ -0,0 +1,26 @@
+# Copyright (C) 2009 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_CERTIFICATE := platform
+LOCAL_JAVA_LIBRARIES := android.test.runner
+LOCAL_MODULE_TAGS := tests
+LOCAL_PACKAGE_NAME := AndroidCommonTests
+LOCAL_SDK_VERSION := current
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_STATIC_JAVA_LIBRARIES := android-common
+
+include $(BUILD_PACKAGE)
diff --git a/common/tests/AndroidManifest.xml b/common/tests/AndroidManifest.xml
new file mode 100644
index 0000000..151ec20
--- /dev/null
+++ b/common/tests/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.common.tests"
+ android:sharedUserId="com.android.uid.test">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <!-- Run tests with "runtest common" -->
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.common.tests"
+ android:label="Android Common Library Tests" />
+
+</manifest>
diff --git a/tests/AndroidTests/src/com/android/unit_tests/RegexTest.java b/common/tests/src/com/android/common/PatternsTest.java
index 8f55044..a89ad62 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/RegexTest.java
+++ b/common/tests/src/com/android/common/PatternsTest.java
@@ -14,25 +14,24 @@
* limitations under the License.
*/
-package com.android.unit_tests;
+package com.android.common;
import android.test.suitebuilder.annotation.SmallTest;
-import android.text.util.Regex;
import junit.framework.TestCase;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-public class RegexTest extends TestCase {
+public class PatternsTest extends TestCase {
@SmallTest
public void testTldPattern() throws Exception {
boolean t;
- t = Regex.TOP_LEVEL_DOMAIN_PATTERN.matcher("com").matches();
+ t = Patterns.TOP_LEVEL_DOMAIN_PATTERN.matcher("com").matches();
assertTrue("Missed valid TLD", t);
- t = Regex.TOP_LEVEL_DOMAIN_PATTERN.matcher("xer").matches();
+ t = Patterns.TOP_LEVEL_DOMAIN_PATTERN.matcher("xer").matches();
assertFalse("Matched invalid TLD!", t);
}
@@ -40,19 +39,19 @@ public class RegexTest extends TestCase {
public void testUrlPattern() throws Exception {
boolean t;
- t = Regex.WEB_URL_PATTERN.matcher("http://www.google.com").matches();
+ t = Patterns.WEB_URL_PATTERN.matcher("http://www.google.com").matches();
assertTrue("Valid URL", t);
- t = Regex.WEB_URL_PATTERN.matcher("ftp://www.example.com").matches();
+ t = Patterns.WEB_URL_PATTERN.matcher("ftp://www.example.com").matches();
assertFalse("Matched invalid protocol", t);
- t = Regex.WEB_URL_PATTERN.matcher("http://www.example.com:8080").matches();
+ t = Patterns.WEB_URL_PATTERN.matcher("http://www.example.com:8080").matches();
assertTrue("Didn't match valid URL with port", t);
- t = Regex.WEB_URL_PATTERN.matcher("http://www.example.com:8080/?foo=bar").matches();
+ t = Patterns.WEB_URL_PATTERN.matcher("http://www.example.com:8080/?foo=bar").matches();
assertTrue("Didn't match valid URL with port and query args", t);
- t = Regex.WEB_URL_PATTERN.matcher("http://www.example.com:8080/~user/?foo=bar").matches();
+ t = Patterns.WEB_URL_PATTERN.matcher("http://www.example.com:8080/~user/?foo=bar").matches();
assertTrue("Didn't match valid URL with ~", t);
}
@@ -60,10 +59,10 @@ public class RegexTest extends TestCase {
public void testIpPattern() throws Exception {
boolean t;
- t = Regex.IP_ADDRESS_PATTERN.matcher("172.29.86.3").matches();
+ t = Patterns.IP_ADDRESS_PATTERN.matcher("172.29.86.3").matches();
assertTrue("Valid IP", t);
- t = Regex.IP_ADDRESS_PATTERN.matcher("1234.4321.9.9").matches();
+ t = Patterns.IP_ADDRESS_PATTERN.matcher("1234.4321.9.9").matches();
assertFalse("Invalid IP", t);
}
@@ -71,10 +70,10 @@ public class RegexTest extends TestCase {
public void testDomainPattern() throws Exception {
boolean t;
- t = Regex.DOMAIN_NAME_PATTERN.matcher("mail.example.com").matches();
+ t = Patterns.DOMAIN_NAME_PATTERN.matcher("mail.example.com").matches();
assertTrue("Valid domain", t);
- t = Regex.DOMAIN_NAME_PATTERN.matcher("__+&42.xer").matches();
+ t = Patterns.DOMAIN_NAME_PATTERN.matcher("__+&42.xer").matches();
assertFalse("Invalid domain", t);
}
@@ -82,10 +81,10 @@ public class RegexTest extends TestCase {
public void testPhonePattern() throws Exception {
boolean t;
- t = Regex.PHONE_PATTERN.matcher("(919) 555-1212").matches();
+ t = Patterns.PHONE_PATTERN.matcher("(919) 555-1212").matches();
assertTrue("Valid phone", t);
- t = Regex.PHONE_PATTERN.matcher("2334 9323/54321").matches();
+ t = Patterns.PHONE_PATTERN.matcher("2334 9323/54321").matches();
assertFalse("Invalid phone", t);
String[] tests = {
@@ -116,7 +115,7 @@ public class RegexTest extends TestCase {
};
for (String test : tests) {
- Matcher m = Regex.PHONE_PATTERN.matcher(test);
+ Matcher m = Patterns.PHONE_PATTERN.matcher(test);
assertTrue("Valid phone " + test, m.find());
}
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/preloaded-classes b/preloaded-classes
index 270c28f..67a4f65 100644
--- a/preloaded-classes
+++ b/preloaded-classes
@@ -733,7 +733,6 @@ android.text.style.UnderlineSpan
android.text.util.Linkify
android.text.util.Linkify$1
android.text.util.Linkify$4
-android.text.util.Regex
android.text.util.Rfc822Tokenizer
android.text.util.Rfc822Validator
android.util.AttributeSet
diff --git a/telephony/java/com/android/internal/telephony/gsm/PdpConnection.java b/telephony/java/com/android/internal/telephony/gsm/PdpConnection.java
index cb85002..02b061c 100644
--- a/telephony/java/com/android/internal/telephony/gsm/PdpConnection.java
+++ b/telephony/java/com/android/internal/telephony/gsm/PdpConnection.java
@@ -17,10 +17,10 @@
package com.android.internal.telephony.gsm;
import android.os.*;
-import android.text.util.Regex;
import android.util.EventLog;
import android.util.Log;
+import com.android.common.Patterns;
import com.android.internal.telephony.CommandException;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.DataConnection;
@@ -318,7 +318,7 @@ public class PdpConnection extends DataConnection {
private boolean isIpAddress(String address) {
if (address == null) return false;
- return Regex.IP_ADDRESS_PATTERN.matcher(apn.mmsProxy).matches();
+ return Patterns.IP_ADDRESS.matcher(apn.mmsProxy).matches();
}
public ApnSetting getApn() {
diff --git a/tests/CoreTests/android/core/RegexTest.java b/tests/CoreTests/android/core/RegexTest.java
index a7f79e8..743afc1 100644
--- a/tests/CoreTests/android/core/RegexTest.java
+++ b/tests/CoreTests/android/core/RegexTest.java
@@ -17,7 +17,6 @@
package android.core;
import android.test.suitebuilder.annotation.SmallTest;
-import android.text.util.Regex;
import junit.framework.TestCase;