filter UCS4 via Character.isSupplementaryCodePoint - Android java.lang

Android examples for java.lang:Character

Description

filter UCS4 via Character.isSupplementaryCodePoint

Demo Code

import android.text.TextUtils;
import java.util.Locale;
import java.util.UUID;

public class Main{

    public static final String filterUCS4(String str) {
        if (TextUtils.isEmpty(str)) {
            return str;
        }/*from w  w  w.ja  v a2s  . com*/

        if (str.codePointCount(0, str.length()) == str.length()) {
            return str;
        }

        StringBuilder sb = new StringBuilder();

        int index = 0;
        while (index < str.length()) {
            int codePoint = str.codePointAt(index);
            index += Character.charCount(codePoint);
            if (Character.isSupplementaryCodePoint(codePoint)) {
                continue;
            }

            sb.appendCodePoint(codePoint);
        }

        return sb.toString();
    }

}

Related Tutorials