public static String unescapeCString(String s){
  if (s.indexOf('\\') < 0) {
    return s;
  }
  StringBuilder sb=new StringBuilder();
  int len=s.length();
  for (int i=0; i < len; ) {
    char c=s.charAt(i++);
    if (c == '\\' && (i < len)) {
      c=s.charAt(i++);
switch (c) {
case 'a':
        c='\007';
      break;
case 'b':
    c='\b';
  break;
case 'f':
c='\f';
break;
case 'n':
c='\n';
break;
case 'r':
c='\r';
break;
case 't':
c='\t';
break;
case 'v':
c='\013';
break;
case '\\':
c='\\';
break;
case '?':
c='?';
break;
case '\'':
c='\'';
break;
case '"':
c='\"';
break;
default :
{
if ((c == 'x') && (i < len) && isHex(s.charAt(i))) {
int v=hexValue(s.charAt(i++));
if ((i < len) && isHex(s.charAt(i))) {
v=v * 16 + hexValue(s.charAt(i++));
}
c=(char)v;
}
 else if (isOctal(c)) {
int v=(c - '0');
if ((i < len) && isOctal(s.charAt(i))) {
v=v * 8 + (s.charAt(i++) - '0');
}
if ((i < len) && isOctal(s.charAt(i))) {
v=v * 8 + (s.charAt(i++) - '0');
}
c=(char)v;
}
 else {
sb.append('\\');
}
break;
}
}
}
sb.append(c);
}
return sb.toString();
}

public static String unescapeCString ( String s ) { if ( s . indexOf ( '\\' ) < 0 ) { return s ; } StringBuilder sb = new StringBuilder ( ) ; int len = s . length ( ) ; for ( int i = 0 ; i < len ; ) { char c = s . charAt ( i ++ ) ; if ( c == '\\' && ( i < len ) ) { c = s . charAt ( i ++ ) ; switch ( c ) { case 'a' : c = '\007' ; break ; case 'b' : c = '\b' ; break ; case 'f' : c = '\f' ; break ; case 'n' : c = '\n' ; break ; case 'r' : c = '\r' ; break ; case 't' : c = '\t' ; break ; case 'v' : c = '\013' ; break ; case '\\' : c = '\\' ; break ; case '?' : c = '?' ; break ; case '\'' : c = '\'' ; break ; case '"' : c = '\"' ; break ; default : { if ( ( c == 'x' ) && ( i < len ) && isHex ( s . charAt ( i ) ) ) { int v = hexValue ( s . charAt ( i ++ ) ) ; if ( ( i < len ) && isHex ( s . charAt ( i ) ) ) { v = v * 16 + hexValue ( s . charAt ( i ++ ) ) ; } c = ( char ) v ; } else if ( isOctal ( c ) ) { int v = ( c - '0' ) ; if ( ( i < len ) && isOctal ( s . charAt ( i ) ) ) { v = v * 8 + ( s . charAt ( i ++ ) - '0' ) ; } if ( ( i < len ) && isOctal ( s . charAt ( i ) ) ) { v = v * 8 + ( s . charAt ( i ++ ) - '0' ) ; } c = ( char ) v ; } else { sb . append ( '\\' ) ; } break ; } } } sb . append ( c ) ; } return sb . toString ( ) ; }
unescape any c escape sequences ( \ n , \ r , \ \ , \ ooo , etc ) and return the resulting string .
