/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  net.sourceforge.pinyin4j.PinyinHelper
 *  net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat
 *  net.sourceforge.pinyin4j.format.HanyuPinyinToneType
 *  net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination
 */
package com.hst.framework.util;

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;

public class HstCnToSpellUtil {
    public static String getFirstSpell(String cnStr) {
        if (cnStr == null || "".equals(cnStr.trim())) {
            return cnStr;
        }
        char[] chars = cnStr.toCharArray();
        StringBuffer retuBuf = new StringBuffer();
        int i = 0;
        int len = chars.length;
        while (i < len) {
            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray((char)chars[i]);
            if (pinyinArray != null) {
                retuBuf.append(pinyinArray[0].charAt(0));
            } else {
                retuBuf.append(chars[i]);
            }
            ++i;
        }
        return retuBuf.toString().toUpperCase();
    }

    public static String getFullSpell(String cnStr) {
        if (cnStr == null || "".equals(cnStr.trim())) {
            return cnStr;
        }
        char[] chars = cnStr.toCharArray();
        StringBuffer retuBuf = new StringBuffer();
        int i = 0;
        int len = chars.length;
        while (i < len) {
            HanyuPinyinOutputFormat output = new HanyuPinyinOutputFormat();
            output.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
            String[] pinyinArray = null;
            try {
                pinyinArray = PinyinHelper.toHanyuPinyinStringArray((char)chars[i], (HanyuPinyinOutputFormat)output);
            }
            catch (BadHanyuPinyinOutputFormatCombination e) {
                e.printStackTrace();
            }
            if (pinyinArray != null) {
                retuBuf.append(pinyinArray[0]);
            } else {
                retuBuf.append(chars[i]);
            }
            ++i;
        }
        return retuBuf.toString().toUpperCase();
    }

    public static void main(String[] args) {
        String str = null;
        str = "\u8c22\u6d77101\u666e\u964d\u559c\u96e8";
        System.out.println("Spell=" + HstCnToSpellUtil.getFullSpell(str));
        str = "\u676d\u5dde\u946b\u6cf0\u5e7f\u544a\u8bbe\u8ba1\u5236\u4f5c\u6709\u9650\u516c\u53f8\uff0c";
        System.out.println("Spell=" + HstCnToSpellUtil.getFullSpell(str));
        str = "\u732a\u6cb9\uff0c\u732a\u516b\u6212\u3002";
        System.out.println("Spell=" + HstCnToSpellUtil.getFullSpell(str));
        str = "\u732a\u6cb9\uff0c\u732a\u516b\u6212\u3002";
        System.out.println("Spell=" + HstCnToSpellUtil.getFirstSpell(str));
        str = "\u676d\u5dde\u946b\u6cf0\u5e7f\u544a\u8bbe\u8ba1\u5236\u4f5c\u6709\u9650\u516c\u53f8";
        System.out.println("Spell=" + HstCnToSpellUtil.getFirstSpell(str));
    }
}
