/*
 * Created on 19.04.2005
 */
package basics.encoding;

import basics.testing.Test;
import basics.utl.SysUtl;

/**
 * @author ks
 */
public class UTF8AsciiUtl
{
private UTF8AsciiUtl()
{
}

/**
 * Replaces some common non-ascii-characters by an ascii substitute.
 * <p>
 * If s == null, the String "" is returned.
 */
public static String transcribe(String s)
{
   if(s == null)
      return "";
   StringBuilder buf = new StringBuilder();
   int length = s.length();
   char c;
   for(int i = 0; i < length; ++i)
   {
      c = s.charAt(i);
      switch(c)
      {
      case 160:
         buf.append(" ");
         break; // Erzwungenes Leerzeichen
      case 161:
         buf.append("!");
         break; // � umgekehrtes Ausrufezeichen
      case 162:
         buf.append("Cent");
         break; // � Cent-Zeichen
      case 163:
         buf.append("BP");
         break; // � Pfund-Zeichen
      // case 164: buf.append("&curren;"); break; //� W�hrungs-Zeichen
      case 165:
         buf.append("Yen");
         break; // � Yen-Zeichen
      // case 166: buf.append("&brvbar;"); break; //� durchbrochener Strich
      // case 167: buf.append("&sect;"); break; //� Paragraph-Zeichen
      case 168:
         buf.append("");
         break; // � P�nktchen oben
      case 169:
         buf.append("(C)");
         break; // � Copyright-Zeichen
      // case 170: buf.append("&ordf;"); break; //� Ordinal-Zeichen weiblich
      case 171:
         buf.append("<<");
         break; // � angewinkelte Anf�hrungszeichen links
      case 172:
         buf.append("!=");
         break; // � Verneinungs-Zeichen
      case 173:
         buf.append("-");
         break; // � kurzer Trennstrich
      case 174:
         buf.append("(R)");
         break; // � Registriermarke-Zeichen
      case 175:
         buf.append("-");
         break; // � �berstrich
      // case 176: buf.append("&deg;"); break; //� Grad-Zeichen
      case 177:
         buf.append("+/-");
         break; // � Plusminus-Zeichen
      case 178:
         buf.append("^2");
         break; // � Hoch-2-Zeichen
      case 179:
         buf.append("^3");
         break; // � Hoch-3-Zeichen
      case 180:
         buf.append("");
         break; // � Acute-Zeichen
      // case 181: buf.append("&micro;"); break; //� Mikro-Zeichen
      // case 182: buf.append("&para;"); break; //� Absatz-Zeichen
      case 183:
         buf.append(".");
         break; // � Mittelpunkt
      case 184:
         buf.append("");
         break; // � H�kchen unten
      case 185:
         buf.append("^1");
         break; // � Hoch-1-Zeichen
      // case 186: buf.append("&ordm;"); break; //� Ordinal-Zeichen m�nnlich
      case 187:
         buf.append(">>");
         break; // � angewinkelte Anf�hrungszeichen rechts
      case 188:
         buf.append("1/4");
         break; // � ein Viertel
      case 189:
         buf.append("1/2");
         break; // � ein Halb
      case 190:
         buf.append("3/4");
         break; // � drei Viertel
      case 191:
         buf.append("?");
         break; // � umgekehrtes Fragezeichen
      case 192:
         buf.append("A");
         break; // � A mit Accent grave
      case 193:
         buf.append("A");
         break; // � A mit Accent acute
      case 194:
         buf.append("A");
         break; // � A mit Circumflex
      case 195:
         buf.append("A");
         break; // � A mit Tilde
      case 196:
         buf.append("Ae");
         break; // � A Umlaut
      case 197:
         buf.append("A");
         break; // � A mit Ring
      case 198:
         buf.append("AE");
         break; // � A mit legiertem E
      case 199:
         buf.append("C");
         break; // � C mit H�kchen
      case 200:
         buf.append("E");
         break; // � E mit Accent grave
      case 201:
         buf.append("E");
         break; // � E mit Accent acute
      case 202:
         buf.append("E");
         break; // � E mit Circumflex
      case 203:
         buf.append("E");
         break; // � E Umlaut
      case 204:
         buf.append("I");
         break; // � I mit Accent grave
      case 205:
         buf.append("I");
         break; // � I mit Accent acute
      case 206:
         buf.append("I");
         break; // � I mit Circumflex
      case 207:
         buf.append("I");
         break; // � I Umlaut
      case 208:
         buf.append("D");
         break; // � Eth (isl�ndisch)
      case 209:
         buf.append("N");
         break; // � N mit Tilde
      case 210:
         buf.append("O");
         break; // � O mit Accent grave
      case 211:
         buf.append("O");
         break; // � O mit Accent acute
      case 212:
         buf.append("O");
         break; // � O mit Circumflex
      case 213:
         buf.append("O");
         break; // � O mit Tilde
      case 214:
         buf.append("Oe");
         break; // � O Umlaut
      case 215:
         buf.append("x");
         break; // � Mal-Zeichen
      case 216:
         buf.append("O");
         break; // � O mit Schr�gstrich
      case 217:
         buf.append("U");
         break; // � U mit Accent grave
      case 218:
         buf.append("U");
         break; // � U mit Accent acute
      case 219:
         buf.append("U");
         break; // � U mit Circumflex
      case 220:
         buf.append("Ue");
         break; // � U Umlaut
      case 221:
         buf.append("Y");
         break; // � Y mit Accent acute
      case 222:
         buf.append("b");
         break; // � THORN (isl�ndisch)
      case 223:
         buf.append("ss");
         break; // � scharfes S
      case 224:
         buf.append("a");
         break; // � a mit Accent grave
      case 225:
         buf.append("a");
         break; // � a mit Accent acute
      case 226:
         buf.append("a");
         break; // � a mit Circumflex
      case 227:
         buf.append("a");
         break; // � a mit Tilde
      case 228:
         buf.append("ae");
         break; // � a Umlaut
      case 229:
         buf.append("ae");
         break; // � a mit Ring
      case 230:
         buf.append("ae");
         break; // � a mit legiertem e
      case 231:
         buf.append("c");
         break; // � c mit H�kchen
      case 232:
         buf.append("e");
         break; // � e mit Accent grave
      case 233:
         buf.append("e");
         break; // � e mit Accent acute
      case 234:
         buf.append("e");
         break; // � e mit Circumflex
      case 235:
         buf.append("e");
         break; // � e Umlaut
      case 236:
         buf.append("i");
         break; // � i mit Accent grave
      case 237:
         buf.append("i");
         break; // � i mit Accent acute
      case 238:
         buf.append("i");
         break; // � i mit Circumflex
      case 239:
         buf.append("i");
         break; // � i Umlaut
      case 240:
         buf.append("d");
         break; // � eth (isl�ndisch)
      case 241:
         buf.append("n");
         break; // � n mit Tilde
      case 242:
         buf.append("o");
         break; // � o mit Accent grave
      case 243:
         buf.append("o");
         break; // � o mit Accent acute
      case 244:
         buf.append("o");
         break; // � o mit Circumflex
      case 245:
         buf.append("o");
         break; // � o mit Tilde
      case 246:
         buf.append("oe");
         break; // � o Umlaut
      case 247:
         buf.append("/");
         break; // � Divisions-Zeichen
      case 248:
         buf.append("o");
         break; // � o mit Schr�gstrich
      case 249:
         buf.append("u");
         break; // � u mit Accent grave
      case 250:
         buf.append("u");
         break; // � u mit Accent acute
      case 251:
         buf.append("u");
         break; // � u mit Circumflex
      case 252:
         buf.append("ue");
         break; // � u Umlaut
      case 253:
         buf.append("y");
         break; // � y mit Accent acute
      case 254:
         buf.append("b");
         break; // � thorn (isl�ndisch)
      case 255:
         buf.append("y");
         break; // � y Umlaut
      default:
         buf.append(c); // throw new RuntimeException("Don't know how to encode
         // '" +
         // c + "' (ASCII code = " + ((int)c) + ")!");
      }
   }
   return buf.toString();
}

public static void unittest()
{
   String r = new String(UTF8AsciiUtl.transcribe("äüößÄÜÖ"));
   Test.assertEqualsTrue(r, "aeueoessAeUeOe", "Umlauts failed: " + r);
}
}
