Emojione.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.emojione;
  2. import android.os.Build;
  3. import java.util.HashMap;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6. public abstract class Emojione
  7. {
  8. private static final HashMap<String, String> _shortNameToUnicode = new HashMap<String, String>();
  9. private static final Pattern SHORTNAME_PATTERN = Pattern.compile(":([-+\\w]+):");
  10. /**
  11. * Replace shortnames to unicode characters.
  12. */
  13. public static String shortnameToUnicode(String input, boolean removeIfUnsupported)
  14. {
  15. Matcher matcher = SHORTNAME_PATTERN.matcher(input);
  16. boolean supported = Build.VERSION.SDK_INT >= 16;
  17. while (matcher.find()) {
  18. String unicode = _shortNameToUnicode.get(matcher.group(1));
  19. if (unicode == null) {
  20. continue;
  21. }
  22. if (supported) {
  23. input = input.replace(":" + matcher.group(1) + ":", unicode);
  24. } else if (!supported && removeIfUnsupported) {
  25. input = input.replace(":" + matcher.group(1) + ":", "");
  26. }
  27. }
  28. return input;
  29. }
  30. static {
  31. <%= mapping %>
  32. }
  33. }