/**
  * The first translator to consume codepoints from the input is the 'winner'. Execution stops with
  * the number of consumed codepoints being returned. {@inheritDoc}
  */
 @Override
 public int translate(CharSequence input, int index, Writer out) throws IOException {
   for (CharSequenceTranslator translator : translators) {
     int consumed = translator.translate(input, index, out);
     if (consumed != 0) {
       return consumed;
     }
   }
   return 0;
 }
 public boolean translate(final int codepoint, final Writer out) throws IOException {
   if (this.between) {
     if (codepoint < this.below || codepoint > this.above) {
       return false;
     }
   } else if (codepoint >= this.below && codepoint <= this.above) {
     return false;
   }
   if (codepoint > 65535) {
     out.write("\\u" + CharSequenceTranslator.hex(codepoint));
   } else if (codepoint > 4095) {
     out.write("\\u" + CharSequenceTranslator.hex(codepoint));
   } else if (codepoint > 255) {
     out.write("\\u0" + CharSequenceTranslator.hex(codepoint));
   } else if (codepoint > 15) {
     out.write("\\u00" + CharSequenceTranslator.hex(codepoint));
   } else {
     out.write("\\u000" + CharSequenceTranslator.hex(codepoint));
   }
   return true;
 }
Example #3
0
 public static String unescape(final String what) {
   return UNESCAPE_JAVA.translate(what);
 }