/* 
 * Created on 2005/02/06 
 * Author aki@www.xucker.jpn.org 
 * License Apache2.0 or Common Public License 
 */ 
package org.jpn.xucker.commons.ipod; 
 
import org.apache.commons.lang.StringUtils; 
 
import java.io.UnsupportedEncodingException; 
 
/** 
 *  
 * 
 */ 
public class TextUtil { 
    public static final String UTF8="UTF-8"; 
    public static final String SJIS="Shift_JIS"; 
    public static final int MAX_LENGTH=4096; 
    public static final String LINE_N="\n"; 
    public static final String LINE_R="\r"; 
        public static final String LINE_RN="\r\n";; 
    public static int countText(String text,String encode){ 
        try { 
            return text.getBytes(encode).length; 
        } catch (UnsupportedEncodingException e) { 
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
        } 
        return -1; 
    } 
    public static int countUTF8(String text){ 
        try { 
            return text.getBytes("UTF-8").length; 
        } catch (UnsupportedEncodingException e) { 
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
        } 
        return -1; 
    } 
     
 
    public static String toTitle(String title){ 
        return "<title>"+title+"</title>"; 
    } 
 
    public static String toEncode(String encode){ 
        return "<?xml encoding=\""+encode+"\"?>"; 
    } 
 
    public static String toNowPlaying(boolean bool){ 
        return "<meta name=\"NowPlaying\" content=\""+bool+"\">"; 
    } 
 
    public static String toLink(String text,String url){ 
        return "<a href=\""+url+"\">"+text+"</a>"; 
    } 
    /** 
     * @param string 
     * @return 
     */ 
    public static String toFix(String string) { 
        string=StringUtils.replace(string,"\","-"); 
        return string; 
    } 
 
}
    
    |