package info.gnuhpc;
/**
* @author gnuhpc email: warmbupt@gmail.com blog: http://gnuhpc.info
* @date 2010-1-22
* @bugs ²»Ö§³Ö¶àÒô×Ö´¦Àí
*/
public class PinyinConv {
// ¼òÌåÖÐÎĵıàÂ뷶Χ´ÓB0A1£¨45217£©Ò»Ö±µ½F7FE£¨63486£©
private static int BEGIN = 45217;
private static int END = 63486;
// °´ÕÕÉùĸ±íʾ£¬Õâ¸ö±íÊÇÔÚGB2312ÖеijöÏֵĵÚÒ»¸öºº×Ö£¬Ò²¾ÍÊÇ˵“°¡”ÊÇ´ú±íÊ××ÖĸaµÄµÚÒ»¸öºº×Ö¡£
// i, u, v¶¼²»×öÉùĸ, ×Ô¶¨¹æÔò¸úËæÇ°ÃæµÄ×Öĸ
private static char[] chartable = { '°¡', '°Å', '²Á', '´î', '¶ê', '·¢', '¸Á', '¹þ',
'¹þ', '»÷', '¿¦', 'À¬', 'Âè', 'ÄÃ', 'Ŷ', 'ž', 'ÆÚ', 'È»', 'Èö', 'Ëú', 'Ëú',
'Ëú', 'ÍÚ', 'Îô', 'ѹ', 'ÔÑ', };
// ¶þÊ®Áù¸ö×ÖĸÇø¼ä¶ÔÓ¦¶þÊ®Æ߸ö¶Ëµã
// GB2312Â뺺×ÖÇø¼äÊ®½øÖƱíʾ
private static int[] table = new int[27];
// ¶ÔÓ¦Ê××ÖĸÇø¼ä±í
private static char[] initialtable = { 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'h', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
't', 't', 'w', 'x', 'y', 'z', };
// ³õʼ»¯
static {
for (int i = 0; i < 26; i++) {
table[i] = gbValue(chartable[i]);// µÃµ½GB2312ÂëµÄÊ××ÖĸÇø¼ä¶Ëµã±í£¬Ê®½øÖÆ¡£
}
table[26] = END;// Çø¼ä±í½áβ
}
// ------------------------public·½·¨Çø------------------------
/**
* ¸ù¾ÝÒ»¸ö°üº¬ºº×ÖµÄ×Ö·û´®·µ»ØÒ»¸öºº×ÖÆ´ÒôÊ××ÖĸµÄ×Ö·û´® ×îÖØÒªµÄÒ»¸ö·½·¨£¬Ë¼Â·ÈçÏ£ºÒ»¸ö¸ö×Ö·û¶ÁÈë¡¢Åжϡ¢Êä³ö
*/
public static String cn2py(String SourceStr) {
String Result = "";
int StrLength = SourceStr.length();
int i;
try {
for (i = 0; i < StrLength; i++) {
Result += Char2Initial(SourceStr.charAt(i));
}
} catch (Exception e) {
Result = "";
}
return Result;
}
// ------------------------private·½·¨Çø------------------------
/**
* ÊäÈë×Ö·û,µÃµ½ËûµÄÉùĸ,Ó¢ÎÄ×Öĸ·µ»Ø¶ÔÓ¦µÄ´óд×Öĸ,ÆäË