public static String FTLStringLiteralDec(String s) throws ParseException {
  int idx=s.indexOf('\\');
  if (idx == -1) {
    return s;
  }
  int lidx=s.length() - 1;
  int bidx=0;
  StringBuilder buf=new StringBuilder(lidx);
  do {
    buf.append(s.substring(bidx,idx));
    if (idx >= lidx) {
      throw new ParseException("The last character of string literal is backslash",0,0);
    }
    char c=s.charAt(idx + 1);
switch (c) {
case '"':
      buf.append('"');
    bidx=idx + 2;
  break;
case '\'':
buf.append('\'');
bidx=idx + 2;
break;
case '\\':
buf.append('\\');
bidx=idx + 2;
break;
case 'n':
buf.append('\n');
bidx=idx + 2;
break;
case 'r':
buf.append('\r');
bidx=idx + 2;
break;
case 't':
buf.append('\t');
bidx=idx + 2;
break;
case 'f':
buf.append('\f');
bidx=idx + 2;
break;
case 'b':
buf.append('\b');
bidx=idx + 2;
break;
case 'g':
buf.append('>');
bidx=idx + 2;
break;
case 'l':
buf.append('<');
bidx=idx + 2;
break;
case 'a':
buf.append('&');
bidx=idx + 2;
break;
case '{':
buf.append('{');
bidx=idx + 2;
break;
case 'x':
{
idx+=2;
int x=idx;
int y=0;
int z=lidx > idx + 3 ? idx + 3 : lidx;
while (idx <= z) {
char b=s.charAt(idx);
if (b >= '0' && b <= '9') {
y<<=4;
y+=b - '0';
}
 else if (b >= 'a' && b <= 'f') {
y<<=4;
y+=b - 'a' + 10;
}
 else if (b >= 'A' && b <= 'F') {
y<<=4;
y+=b - 'A' + 10;
}
 else {
break;
}
idx++;
}
if (x < idx) {
buf.append((char)y);
}
 else {
throw new ParseException("Invalid \\x escape in a string literal",0,0);
}
bidx=idx;
break;
}
default :
throw new ParseException("Invalid escape sequence (\\" + c + ") in a string literal",0,0);
}
idx=s.indexOf('\\',bidx);
}
 while (idx != -1);
buf.append(s.substring(bidx));
return buf.toString();
}

public static String FTLStringLiteralDec ( String s ) throws ParseException { int idx = s . indexOf ( '\\' ) ; if ( idx == - 1 ) { return s ; } int lidx = s . length ( ) - 1 ; int bidx = 0 ; StringBuilder buf = new StringBuilder ( lidx ) ; do { buf . append ( s . substring ( bidx , idx ) ) ; if ( idx >= lidx ) { throw new ParseException ( "The last character of string literal is backslash" , 0 , 0 ) ; } char c = s . charAt ( idx + 1 ) ; switch ( c ) { case '"' : buf . append ( '"' ) ; bidx = idx + 2 ; break ; case '\'' : buf . append ( '\'' ) ; bidx = idx + 2 ; break ; case '\\' : buf . append ( '\\' ) ; bidx = idx + 2 ; break ; case 'n' : buf . append ( '\n' ) ; bidx = idx + 2 ; break ; case 'r' : buf . append ( '\r' ) ; bidx = idx + 2 ; break ; case 't' : buf . append ( '\t' ) ; bidx = idx + 2 ; break ; case 'f' : buf . append ( '\f' ) ; bidx = idx + 2 ; break ; case 'b' : buf . append ( '\b' ) ; bidx = idx + 2 ; break ; case 'g' : buf . append ( '>' ) ; bidx = idx + 2 ; break ; case 'l' : buf . append ( '<' ) ; bidx = idx + 2 ; break ; case 'a' : buf . append ( '&' ) ; bidx = idx + 2 ; break ; case '{' : buf . append ( '{' ) ; bidx = idx + 2 ; break ; case 'x' : { idx += 2 ; int x = idx ; int y = 0 ; int z = lidx > idx + 3 ? idx + 3 : lidx ; while ( idx <= z ) { char b = s . charAt ( idx ) ; if ( b >= '0' && b <= '9' ) { y <<= 4 ; y += b - '0' ; } else if ( b >= 'a' && b <= 'f' ) { y <<= 4 ; y += b - 'a' + 10 ; } else if ( b >= 'A' && b <= 'F' ) { y <<= 4 ; y += b - 'A' + 10 ; } else { break ; } idx ++ ; } if ( x < idx ) { buf . append ( ( char ) y ) ; } else { throw new ParseException ( "Invalid \\x escape in a string literal" , 0 , 0 ) ; } bidx = idx ; break ; } default : throw new ParseException ( "Invalid escape sequence (\\" + c + ") in a string literal" , 0 , 0 ) ; } idx = s . indexOf ( '\\' , bidx ) ; } while ( idx != - 1 ) ; buf . append ( s . substring ( bidx ) ) ; return buf . toString ( ) ; }
ftl string literal decoding . \ \ , \ " , \ ' , \ n , \ t , \ r , \ b and \ f will be replaced according to java rules . in additional , it knows \ g , \ l , \ a and \ { which are replaced with & lt ; , & gt ; , & amp ; and { respectively . \ x works as hexadecimal character code escape . the character codes are interpreted according to ucs basic plane ( unicode ) . " f \ x006fo " , " f \ x06fo " and " f \ x6fo " will be " foo " . " f \ x006f123 " will be " foo123 " as the maximum number of digits is 4 . all other \ x ( where x is any character not mentioned above or end - of - string ) will cause a parseexception .
