package jp.sourceforge.mailagent;

/**
 * 暥帤僄儞僐乕僪張棟
 */
final class Encode{
   private Encode(){}
   /**
    * Unicode(cp932) 偐傜 JIS 傊暥帤僐乕僪曄姺傪偟傑偡丅
    * <PRE>
    *   亸丗0xff3c[FULLWIDTH REVERSE SOLIDUS] -> 0x005c[REVERSE SOLIDUS]
    *   乣丗0xff5e[FULLWIDTH TILDE]           -> 0x301c[WAVE DASH]
    *   乤丗0x2225[PARALLEL TO]               -> 0x2016[DOUBLE VERTICAL LINE]
    *   亅丗0xff0d[FULLWIDTH HYPHEN-MINUS]    -> 0x2212[MINUS SIGN]
    *   亼丗0xffe0[FULLWIDTH CENT SIGN]       -> 0x00a2[CENT SIGN]
    *   亽丗0xffe1[FULLWIDTH POUND SIGN]      -> 0x00a3[POUND SIGN]
    *   伿丗0xffe2[FULLWIDTH NOT SIGN]        -> 0x00ac[NOT SIGN]
    * </PRE>
    * @param s 曄姺慜暥帤楍<code>String</code>
    * @return 曄姺屻暥帤楍<code>String</code>
    */
   protected static String convCp932toJIS(String s) {
       if (s == null) return s;
       StringBuffer buffer = new StringBuffer();
       for (int i = 0; i < s.length(); i++) {
           char c  = s.charAt(i);
           switch (c) {
           case 0xff3c:    // FULLWIDTH REVERSE SOLIDUS ->
               c = 0x005c; // REVERSE SOLIDUS
               break;
           case 0xff5e:    // FULLWIDTH TILDE ->
               c = 0x301c; // WAVE DASH
               break;
           case 0x2225:    // PARALLEL TO ->
               c = 0x2016; // DOUBLE VERTICAL LINE
               break;
           case 0xff0d:    // FULLWIDTH HYPHEN-MINUS ->
               c = 0x2212; // MINUS SIGN
               break;
           case 0xffe0:    // FULLWIDTH CENT SIGN ->
               c = 0x00a2; // CENT SIGN
               break;
           case 0xffe1:    // FULLWIDTH POUND SIGN ->
               c = 0x00a3; // POUND SIGN
               break;
           case 0xffe2:    // FULLWIDTH NOT SIGN ->
               c = 0x00ac; // NOT SIGN
               break;
           }
           buffer.append(c);
       }
       return buffer.toString();
   }
 
   /**
    * ProphibitCode丂偺曄姺.
    * 儘乕儅悢帤丄娵悢帤摍偺暥帤
    * @param s 曄姺慜暥帤楍<code>String</code>
    * @return 曄姺屻暥帤楍<code>String</code>
    */
   protected static String convProphibitCode(String s){
      if (s == null) return s;
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < s.length(); i++) {
          char c  = s.charAt(i);
          switch (c) {
          case 0x2160:    // 嘥->I
             c = 0x0049; 
             break;
          case 0x2161:    // 嘦->II
             c = 0x0049;   sb.append(c);  c = 0x0049;
             break;
          case 0x2162:    // 嘨->III
             c = 0x0049;   sb.append(c);  c = 0x0049;  sb.append(c);  c = 0x0049;
             break;
          case 0x2163:    // 嘩->IV
             c = 0x0049;   sb.append(c);  c = 0x0056;
             break;
          case 0x2164:    // 嘪->V
             c = 0x0056;
             break;
          case 0x2165:    // 嘫->VI
             c = 0x0056;   sb.append(c);  c = 0x0049;
             break;
          case 0x2166:    // 嘮->VII
             c = 0x0056;   sb.append(c);  c = 0x0049;  sb.append(c);  c = 0x0049;
             break;
          case 0x2167:    // 嘯->VIII
             c = 0x0056;   sb.append(c);  c = 0x0049;  sb.append(c);  c = 0x0049;  sb.append(c);  c = 0x0049;
             break;
          case 0x2168:    // 嘰->IX
             c = 0x0049;   sb.append(c);  c = 0x0058;
             break;
          case 0x2169:    // 嘳->X
             c = 0x0058;
             break;
          case 0x2170:    // 鶣->i
             c = 0x0069;
             break;
          case 0x2171:    // 鶤->ii
             c = 0x0069;   sb.append(c);  c = 0x0069;
             break;
          case 0x2172:    // 鶥->iii
             c = 0x0069;   sb.append(c);  c = 0x0069;  sb.append(c);  c = 0x0069;
             break;
          case 0x2173:    // 鶦->iv
             c = 0x0069;   sb.append(c);  c = 0x0076;
             break;
          case 0x2174:    // 鶧->v
             c = 0x0076;
             break;
          case 0x2175:    // 鶨->vi
             c = 0x0076;   sb.append(c);  c = 0x0069;
             break;
          case 0x2176:    // 鶩->vii
             c = 0x0076;   sb.append(c);  c = 0x0069;  sb.append(c);  c = 0x0069;
             break;
          case 0x2177:    // 鶪->viii
             c = 0x0076;   sb.append(c);  c = 0x0069;  sb.append(c);  c = 0x0069;  sb.append(c);  c = 0x0069;
             break;
          case 0x2178:    // 鶫->ix
             c = 0x0069;   sb.append(c);  c = 0x0078;
             break;
          case 0x2179:    // 鶬->x
             c = 0x0078;
             break;
          case 0x2460:    // 嘆->(1)
             sb.append("(1");   c = ')';
             break;
          case 0x2461:    // 嘇->(2)
             sb.append("(2");   c = ')';
             break;
          case 0x2462:    // 嘊->(3)
             sb.append("(3");   c = ')';
             break;
          case 0x2463:    // 嘋->(4)
             sb.append("(4");   c = ')';
             break;
          case 0x2464:    // 嘍->(5)
             sb.append("(5");   c = ')';
             break;
          case 0x2465:    // 嘐->(6)
             sb.append("(6");   c = ')'; 
             break;
          case 0x2466:    // 嘑->(7)
             sb.append("(7");   c = ')';
             break;
          case 0x2467:    // 嘒->(8)
             sb.append("(8");   c = ')';
             break;
          case 0x2468:    // 嘓->(9)
             sb.append("(9");   c = ')';
             break;
          case 0x2469:    // 嘔->(10)
             sb.append("(10");  c = ')';
             break;
          case 0x246a:    // 嘕>(11)
             sb.append("(11");  c = ')';
             break;
          case 0x246b:    // 嘖->(1)
             sb.append("(12");  c = ')';
             break;
          case 0x246c:    // 嘗->(1)
             sb.append("(13");  c = ')';
             break;
          case 0x246d:    // 嘙->(1)
             sb.append("(14");  c = ')';
             break;
          case 0x246e:    // 嘚->(1)
             sb.append("(15");  c = ')';
             break;
          case 0x246f:    // 嘜->(1)
             sb.append("(16");  c = ')';
             break;
          case 0x2470:    // 嘝->(1)
             sb.append("(17");  c = ')';
             break;
          case 0x2471:    // 嘠->(1)
             sb.append("(18");  c = ')';
             break;
          case 0x2472:    // 嘡->(1)
             sb.append("(19");  c = ')';
             break;
          case 0x2473:    // 嘢->(1)
             sb.append("(20");  c = ')';
             break;
          }
          sb.append(c);
      }
      return sb.toString();
   }

}
