Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ded0e644 authored by Dan Egnor's avatar Dan Egnor
Browse files

Create android-common static library which gets included in frameworks.jar,

but can also be used by unbundled apps.  Move android.text.util.Regex there as
a starting example, renamed to a more sensible (?) com.android.common.Patterns.
Set up a corresponding test package, and move RegexTest (to PatternsTest).
Update clients.
parent a4fa107f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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

common/Android.mk

0 → 100644
+23 −0
Original line number Diff line number Diff line
# 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)
+16 −11
Original line number Diff line number Diff line
@@ -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() {}
}
+26 −0
Original line number Diff line number Diff line
# 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)
+30 −0
Original line number Diff line number Diff line
<?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>
Loading