TextUtilsCompat.java
/*
* Copyright (C) 2013 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 androidx.core.text;
import static android.os.Build.VERSION.SDK_INT;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import java.util.Locale;
/**
* Backwards compatible version of {@link TextUtils}.
*/
public final class TextUtilsCompat {
private static final Locale ROOT = new Locale("", "");
private static final String ARAB_SCRIPT_SUBTAG = "Arab";
private static final String HEBR_SCRIPT_SUBTAG = "Hebr";
/**
* Html-encode the string.
*
* @param s the string to be encoded
* @return the encoded string
*/
@NonNull
public static String htmlEncode(@NonNull String s) {
if (SDK_INT >= 17) {
return TextUtils.htmlEncode(s);
} else {
StringBuilder sb = new StringBuilder();
char c;
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
switch (c) {
case '<':
sb.append("<"); //$NON-NLS-1$
break;
case '>':
sb.append(">"); //$NON-NLS-1$
break;
case '&':
sb.append("&"); //$NON-NLS-1$
break;
case '