public static String replacePlaceholders(String s, boolean lenient) {
        StringBuilder sb = new StringBuilder(s.length());
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c != '\\') {
                sb.append(c);
            } else {
                if (i + 1 >= s.length()) {
                    String msg = "Error processing escape sequences: expected escape character, found end of string";
                    throw new OkapiException(msg);
                } else {
                    char c2 = s.charAt(i + 1);
                    switch (c2) {
                        case '0':
                            sb.append('\u0000'); // null
                            i++;
                            break;
                        case 'E':
                            sb.append('\u0004'); // end of transmission
                            i++;
                            break;
                        case 'a':
                            sb.append('\u0007'); // bell
                            i++;
                            break;
                        case 'b':
                            sb.append('\u0008'); // backspace
                            i++;
                            break;
                        case 't':
                            sb.append('\u0009'); // horizontal tab
                            i++;
                            break;
                        case 'n':
                            sb.append('\n'); // line feed
                            i++;
                            break;
                        case 'v':
                            sb.append('\u000b'); // vertical tab
                            i++;
                            break;
                        case 'f':
                            sb.append('\u000c'); // form feed
                            i++;
                            break;
                        case 'r':
                            sb.append('\r'); // carriage return
                            i++;
                            break;
                        case 'e':
                            sb.append('\u001b'); // escape
                            i++;
                            break;
                        case 'G':
                            sb.append('\u001d'); // group separator
                            i++;
                            break;
                        case 'R':
                            sb.append('\u001e'); // record separator
                            i++;
                            break;
                        case '\\':
                            sb.append('\\'); // escape the escape character
                            i++;
                            break;
                        case 'x':
                            if (i + 3 >= s.length()) {
                                String msg = "Error processing escape sequences: expected hex sequence, found end of string";
                                throw new OkapiException(msg);
                            } else {
                                char c3 = s.charAt(i + 2);
                                char c4 = s.charAt(i + 3);
                                if (isHex(c3) && isHex(c4)) {
                                    byte b = (byte) Integer.parseInt("" + c3 + c4, 16);
                                    sb.append(new String(new byte[] { b }, StandardCharsets.ISO_8859_1));
                                    i += 3;
                                } else {
                                    String msg = "Error processing escape sequences: expected hex sequence, found '" + c3 + c4 + "'";
                                    throw new OkapiException(msg);
                                }
                            }
                            break;
                        default:
                            if (lenient) {
                                sb.append(c);
                            } else {
                                throw new OkapiException("Error processing escape sequences: expected valid escape character, found '" + c2 + "'");
                            }
                    }
                }
            }
        }
        return sb.toString();
    }
public static String replacePlaceholders ( String s , boolean lenient ) { StringBuilder sb = new StringBuilder ( s . length ( ) ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( c != '\\' ) { sb . append ( c ) ; } else { if ( i + 1 >= s . length ( ) ) { String msg = "Error processing escape sequences: expected escape character, found end of string" ; throw new OkapiException ( msg ) ; } else { char c2 = s . charAt ( i + 1 ) ; switch ( c2 ) { case '0' : sb . append ( '' ) ; i ++ ; break ; case 'E' : sb . append ( '' ) ; i ++ ; break ; case 'a' : sb . append ( '' ) ; i ++ ; break ; case 'b' : sb . append ( '' ) ; i ++ ; break ; case 't' : sb . append ( '	' ) ; i ++ ; break ; case 'n' : sb . append ( '\n' ) ; i ++ ; break ; case 'v' : sb . append ( '' ) ; i ++ ; break ; case 'f' : sb . append ( '' ) ; i ++ ; break ; case 'r' : sb . append ( '\r' ) ; i ++ ; break ; case 'e' : sb . append ( '' ) ; i ++ ; break ; case 'G' : sb . append ( '' ) ; i ++ ; break ; case 'R' : sb . append ( '' ) ; i ++ ; break ; case '\\' : sb . append ( '\\' ) ; i ++ ; break ; case 'x' : if ( i + 3 >= s . length ( ) ) { String msg = "Error processing escape sequences: expected hex sequence, found end of string" ; throw new OkapiException ( msg ) ; } else { char c3 = s . charAt ( i + 2 ) ; char c4 = s . charAt ( i + 3 ) ; if ( isHex ( c3 ) && isHex ( c4 ) ) { byte b = ( byte ) Integer . parseInt ( "" + c3 + c4 , 16 ) ; sb . append ( new String ( new byte [ ] { b } , StandardCharsets . ISO_8859_1 ) ) ; i += 3 ; } else { String msg = "Error processing escape sequences: expected hex sequence, found '" + c3 + c4 + "'" ; throw new OkapiException ( msg ) ; } } break ; default : if ( lenient ) { sb . append ( c ) ; } else { throw new OkapiException ( "Error processing escape sequences: expected valid escape character, found '" + c2 + "'" ) ; } } } } } return sb . toString ( ) ; }
Replaces any special placeholders with their raw values (not including FNC values).

@param s the string to check for placeholders
@param lenient whether or not to be lenient with unrecognized escape sequences
@return the specified string, with placeholders replaced
@see <a href="http://www.zint.org.uk/Manual.aspx?type=p&page=4">Zint placeholders</a>