private static String unescape(String s){
  int len=s.length(), base=0, idx;
  String escapes="tnrbf\\\"'";
  String chars="\t\n\r\b\f\\\"'";
  StringBuffer sbuf=null;
  while ((idx=s.indexOf('\\',base)) != -1) {
    if (sbuf != null)     sbuf.append(s.substring(base,idx));
    if (idx + 1 == len)     break;
    char c=s.charAt(idx + 1);
    int cidx=escapes.indexOf(c);
    if (cidx == -1) {
      sbuf.append('\\');
      sbuf.append(c);
    }
 else {
      if (sbuf == null)       sbuf=new StringBuffer(s.substring(base,idx));
      sbuf.append(chars.charAt(cidx));
    }
    base=idx + 2;
  }
  if (sbuf != null && base < len)   sbuf.append(s.substring(base));
  return (sbuf == null ? s : sbuf.toString());
}

private static String unescape ( String s ) { int len = s . length ( ) , base = 0 , idx ; String escapes = "tnrbf\\\"'" ; String chars = "\t\n\r\b\f\\\"'" ; StringBuffer sbuf = null ; while ( ( idx = s . indexOf ( '\\' , base ) ) != - 1 ) { if ( sbuf != null ) sbuf . append ( s . substring ( base , idx ) ) ; if ( idx + 1 == len ) break ; char c = s . charAt ( idx + 1 ) ; int cidx = escapes . indexOf ( c ) ; if ( cidx == - 1 ) { sbuf . append ( '\\' ) ; sbuf . append ( c ) ; } else { if ( sbuf == null ) sbuf = new StringBuffer ( s . substring ( base , idx ) ) ; sbuf . append ( chars . charAt ( cidx ) ) ; } base = idx + 2 ; } if ( sbuf != null && base < len ) sbuf . append ( s . substring ( base ) ) ; return ( sbuf == null ? s : sbuf . toString ( ) ) ; }
replace escape sequences with represented characters . this includes newlines , tabs , and quotes .
