package com.qmth.paper.library.common.util;

/**
 * 字符串工具类
 */
public class StrUtil {


    /**
     * 中文转换为unicode编码
     *
     * @param inStr 中文
     */
    public static String getStrUnicode(String inStr) {
        StringBuffer unicode = new StringBuffer();
        char c;
        int bit;
        String tmp;
        for (int i = 0; i < inStr.length(); i++) {
            c = inStr.charAt(i);
            if (c > 255) {
                unicode.append("\\u");
                bit = (c >>> 8);
                tmp = Integer.toHexString(bit);
                if (tmp.length() == 1) unicode.append("0");
                unicode.append(tmp);
                bit = (c & 0xFF);
                tmp = Integer.toHexString(bit);
                if (tmp.length() == 1) unicode.append("0");
                unicode.append(tmp);
            } else {
                unicode.append(c);
            }
        }
        return (new String(unicode));
    }
}