compat/src/main/java/androidx/core/text/TextUtilsCompat.java
@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("&lt;"); //$NON-NLS-1$
                        break;
                    case '>':
                        sb.append("&gt;"); //$NON-NLS-1$
                        break;
                    case '&':
                        sb.append("&amp;"); //$NON-NLS-1$
                        break;
                    case '\'':
                        //http://www.w3.org/TR/xhtml1
                        // The named character reference &apos; (the apostrophe, U+0027) was
                        // introduced in XML 1.0 but does not appear in HTML. Authors should
                        // therefore use &#39; instead of &apos; to work as expected in HTML 4
                        // user agents.
                        sb.append("&#39;"); //$NON-NLS-1$
                        break;
                    case '"':
                        sb.append("&quot;"); //$NON-NLS-1$
                        break;
                    default:
                        sb.append(c);
                }
            }
            return sb.toString();
        }
    }
/**
     * Html-encode the string.
     *
     * @param s the string to be encoded
     * @return the encoded string
     */
Html-encode the string.
@param s the string to be encoded
@return the encoded string
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("&lt;"); 
                        break;
                    case '>':
                        sb.append("&gt;"); 
                        break;
                    case '&':
                        sb.append("&amp;"); 
                        break;
                    case '\'':
                        sb.append("&#39;"); 
                        break;
                    case '"':
                        sb.append("&quot;"); 
                        break;
                    default:
                        sb.append(c);
                }
            }
            return sb.toString();
        }
    }
@ 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 ( "&lt;" ) ; break ; case '>' : sb . append ( "&gt;" ) ; break ; case '&' : sb . append ( "&amp;" ) ; break ; case '\'' : sb . append ( "&#39;" ) ; break ; case '"' : sb . append ( "&quot;" ) ; break ; default : sb . append ( c ) ; } } return sb . toString ( ) ; } }
Html-encode the string.
Html - encode the string .
//$NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-1$ //http://www.w3.org/TR/xhtml1 // The named character reference &apos; (the apostrophe, U+0027) was // introduced in XML 1.0 but does not appear in HTML. Authors should // therefore use &#39; instead of &apos; to work as expected in HTML 4 // user agents. //$NON-NLS-1$ //$NON-NLS-1$