List of usage examples for java.lang Character isSurrogatePair
public static boolean isSurrogatePair(char high, char low)
From source file:Main.java
public static void main(String[] args) { System.out.println("A valid Unicode surrogate pair: " + Character.isSurrogatePair('\ud800', '\udc00')); }
From source file:Main.java
public static boolean isUnicodeSurrogate(String word) { // emoji icons are within these surrogate areas if (word != null && word.length() == 2) { char[] chArray = word.toCharArray(); return Character.isSurrogatePair(chArray[0], chArray[1]); }// www. j a v a2s .c o m return false; }
From source file:mobisocial.musubi.ui.util.EmojiSpannableFactory.java
public void updateSpannable(Spannable span) { Spannable source = span;//from www . ja v a2s. c o m for (int i = 0; i < source.length(); i++) { char high = source.charAt(i); if (high <= 127) { // fast exit ascii continue; } // Block until we're initialized waitForEmoji(); long codePoint = high; if (Character.isHighSurrogate(high)) { char low = source.charAt(++i); codePoint = Character.toCodePoint(high, low); if (Character.isSurrogatePair(high, low)) { // from BMP if (!mEmojiMap.containsKey(codePoint)) { if (i >= source.length() - 2) { continue; } high = source.charAt(++i); if (!Character.isHighSurrogate(high)) { Log.w(TAG, "bad unicode character? " + high); continue; } low = source.charAt(++i); if (!Character.isSurrogatePair(high, low)) { Log.d(TAG, "Bogus unicode surrogate " + high + ", " + low); continue; } int codePoint2 = Character.toCodePoint(high, low); //String label = String.format("U+%X U+%X", codePoint, codePoint2); codePoint = ((long) codePoint << 16) | codePoint2; } } else { Log.d(TAG, "Bogus unicode"); } } if (mEmojiMap.containsKey(codePoint)) { Bitmap b = mStickerCache.get(codePoint); if (b != null) { DynamicDrawableSpan im = createStickerSpan(b); span.setSpan(im, i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { Log.d(TAG, "failed to decode bitmap for codepoints: " + codePoint); } } } }
From source file:com.liferay.events.global.mobile.Utils.java
public static String removeUnicode(String input) { if (Validator.isNull(input)) { return null; }//from w ww .j a v a 2s . c o m StringBuilder sb = new StringBuilder(); for (int i = 0; i < input.length(); i++) { if (i < (input.length() - 1)) { // Emojis are two characters long in java, e.g. a rocket emoji is "\uD83D\uDE80"; if (Character.isSurrogatePair(input.charAt(i), input.charAt(i + 1))) { i += 1; //also skip the second character of the emoji continue; } } sb.append(input.charAt(i)); } return sb.toString(); }