public static void chineseStringToPinyinUnit(String chineseString,List<PinyinUnit> pinyinUnit){
  if ((null == chineseString) || (null == pinyinUnit)) {
    return;
  }
  String chineseStr=chineseString.toLowerCase();
  if (null == format) {
    format=new HanyuPinyinOutputFormat();
  }
  format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
  int chineseStringLength=chineseStr.length();
  StringBuffer nonPinyinString=new StringBuffer();
  PinyinUnit pyUnit=null;
  String originalString=null;
  String[] pinyinStr=null;
  boolean lastChineseCharacters=true;
  int startPosition=-1;
  for (int i=0; i < chineseStringLength; i++) {
    char ch=chineseStr.charAt(i);
    try {
      pinyinStr=PinyinHelper.toHanyuPinyinStringArray(ch,format);
    }
 catch (    BadHanyuPinyinOutputFormatCombination e) {
      e.printStackTrace();
    }
    if (null == pinyinStr) {
      if (true == lastChineseCharacters) {
        pyUnit=new PinyinUnit();
        lastChineseCharacters=false;
        startPosition=i;
        nonPinyinString.delete(0,nonPinyinString.length());
      }
      nonPinyinString.append(ch);
    }
 else {
      if (false == lastChineseCharacters) {
        originalString=nonPinyinString.toString();
        String[] str={nonPinyinString.toString()};
        addPinyinUnit(pinyinUnit,pyUnit,false,originalString,str,startPosition);
        nonPinyinString.delete(0,nonPinyinString.length());
        lastChineseCharacters=true;
      }
      pyUnit=new PinyinUnit();
      startPosition=i;
      originalString=String.valueOf(ch);
      addPinyinUnit(pinyinUnit,pyUnit,true,originalString,pinyinStr,startPosition);
    }
  }
  if (false == lastChineseCharacters) {
    originalString=nonPinyinString.toString();
    String[] str={nonPinyinString.toString()};
    addPinyinUnit(pinyinUnit,pyUnit,false,originalString,str,startPosition);
    nonPinyinString.delete(0,nonPinyinString.length());
    lastChineseCharacters=true;
  }
}

public static void chineseStringToPinyinUnit ( String chineseString , List < PinyinUnit > pinyinUnit ) { if ( ( null == chineseString ) || ( null == pinyinUnit ) ) { return ; } String chineseStr = chineseString . toLowerCase ( ) ; if ( null == format ) { format = new HanyuPinyinOutputFormat ( ) ; } format . setToneType ( HanyuPinyinToneType . WITHOUT_TONE ) ; int chineseStringLength = chineseStr . length ( ) ; StringBuffer nonPinyinString = new StringBuffer ( ) ; PinyinUnit pyUnit = null ; String originalString = null ; String [ ] pinyinStr = null ; boolean lastChineseCharacters = true ; int startPosition = - 1 ; for ( int i = 0 ; i < chineseStringLength ; i ++ ) { char ch = chineseStr . charAt ( i ) ; try { pinyinStr = PinyinHelper . toHanyuPinyinStringArray ( ch , format ) ; } catch ( BadHanyuPinyinOutputFormatCombination e ) { e . printStackTrace ( ) ; } if ( null == pinyinStr ) { if ( true == lastChineseCharacters ) { pyUnit = new PinyinUnit ( ) ; lastChineseCharacters = false ; startPosition = i ; nonPinyinString . delete ( 0 , nonPinyinString . length ( ) ) ; } nonPinyinString . append ( ch ) ; } else { if ( false == lastChineseCharacters ) { originalString = nonPinyinString . toString ( ) ; String [ ] str = { nonPinyinString . toString ( ) } ; addPinyinUnit ( pinyinUnit , pyUnit , false , originalString , str , startPosition ) ; nonPinyinString . delete ( 0 , nonPinyinString . length ( ) ) ; lastChineseCharacters = true ; } pyUnit = new PinyinUnit ( ) ; startPosition = i ; originalString = String . valueOf ( ch ) ; addPinyinUnit ( pinyinUnit , pyUnit , true , originalString , pinyinStr , startPosition ) ; } } if ( false == lastChineseCharacters ) { originalString = nonPinyinString . toString ( ) ; String [ ] str = { nonPinyinString . toString ( ) } ; addPinyinUnit ( pinyinUnit , pyUnit , false , originalString , str , startPosition ) ; nonPinyinString . delete ( 0 , nonPinyinString . length ( ) ) ; lastChineseCharacters = true ; } }
convert from chinese string to a series of pinyinunit
