Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.dialer.util;
     18 
     19 /**
     20  * Static utility methods for Strings.
     21  */
     22 public class MoreStrings {
     23 
     24     public static String toSafeString(String value) {
     25         if (value == null) {
     26             return null;
     27         }
     28 
     29         // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
     30         // sanitized phone numbers.
     31         final StringBuilder builder = new StringBuilder();
     32         for (int i = 0; i < value.length(); i++) {
     33             final char c = value.charAt(i);
     34             if (c == '-' || c == '@' || c == '.') {
     35                 builder.append(c);
     36             } else {
     37                 builder.append('x');
     38             }
     39         }
     40         return builder.toString();
     41     }
     42 
     43 }
     44