The expression of JAVA tool class and special character filter __java

Source: Internet
Author: User
Tags reserved stringbuffer
Emojiutils
Package com.lh.wx.utils;
Import Java.util.regex.Matcher;

Import Java.util.regex.Pattern;

Import Org.apache.http.util.TextUtils;
            public class Emojiutils {public static string filter (String str) {if (str = NULL | | str.length () = 0) {
        Return "";
        StringBuffer sb = new StringBuffer ();
            for (int i=0;i<str.length (); i++) {int ch = str.charat (i);
            int min = integer.parseint ("E001", 16);
            int max = Integer.parseint ("E537", 16);
            if (ch >= min && ch <= max) {sb.append ("");
            }else{Sb.append ((char) ch);
    } return sb.tostring ();
            /** * Filter Nickname SPECIAL expression * * public static string FilterName (String name) {if (name==null) {

        return null;
        } if ("". Equals (Name.trim ()) {return "";
    Pattern patter = Pattern.compile ("[A-za-z0-9\u4e00-\u9fa5]");    Matcher match = patter.matcher (name);
        StringBuffer buffer = new StringBuffer ();
        Boolean flag=false;
        while (Match.find ()) {Buffer.append (Match.group ());
        } if (!name.equals (buffer.tostring ())) {flag=true; } if (flag) return "?"   
        +buffer.tostring ();
    else return buffer.tostring (); /** * Converts the emoji expression in the string to Unicode encoding * @param src * @return/public static string Emoji2unicod

        E (String src) {stringbuffer unicode = new StringBuffer ();
            for (int i = 0; i < src.length (); i++) {char c = src.charat (i);
            int codepoint = Src.codepointat (i);
            if (Isemojicharacter (codepoint)) {unicode.append ("\\u"). Append (Integer.tohexstring (c));
            else {unicode.append (c);
    } return unicode.tostring (); /** * Determine whether to include emoji symbol * @param codEpoint * @return/public static Boolean isemojicharacter (int codepoint) {return (codepoint >= 0x2600 && codepoint <= 0x27bf)//miscellaneous symbols and symbols fonts | | Codepoint = = 0x303d | | Codepoint = = 0x2049 | | Codepoint = = 0X203C | | (codepoint >= 0x2000 && codepoint <=)//| | (codepoint >= 0x2028 && codepoint <=)//| | Codepoint = = 0x205f//| | (codepoint >= 0x2065 && codepoint <= 0x206f)/* Punctuation area * (codepoint >= 0x2100 && codepoint <= 0x214f)//Letter Symbols | | (codepoint >= 0x2300 && codepoint <= 0x23ff)//various technical symbols | | (codepoint >= 0x2b00 && codepoint <= 0X2BFF)//arrow A | | (codepoint >= 0x2900 && codepoint <= 0x297f)//arrow B | | (Codepoint >= 0x3200 && Codepoint <= 0x32ff)//Chinese Symbols | | (codepoint >= 0xd800 && codepoint <= 0xDFFF)//high/low position substitution reserved Area | | (codepoint >= 0xe000 && codepoint <= 0xf8ff)//private reserved Area | | (codepoint >= 0xfe00 && codepoint <= 0xfe0f)//mutation Selector | | Codepoint >= 0x10000; Plane in the second plane, Char can not save, all turn}/** * Convert Unicode characters to Chinese * @param src * @return/public static
       String Unicode2emoji (String src) {if (Textutils.isempty (src)) {return ";
       } stringbuffer retbuf = new StringBuffer ();
       int maxloop = Src.length (); for (int i = 0; i < Maxloop i++) {if (Src.charat (i) = = ' \ ') {if ((I < maxLoop-5) &am p;& ((Src.charat (i + 1) = = ' u ') | | (Src.charat (i + 1) = = ' U ')) 
                       {try {retbuf.append ((char) integer.parseint (src.substring (i + 2, i + 6), 16)); i + 5;
                   The catch (NumberFormatException localnumberformatexception) {retbuf.append (src).
                   CharAt (i));
               } else {retbuf.append (Src.charat (i));
           } else {retbuf.append (Src.charat (i));
   } return retbuf.tostring ();
 }
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.