class Utils {

    public static String decodeApacheHTTPDLogValue(String input){
        if (input == null || input.length() == 0) {
            return input;
        }

        if (!input.contains("\\")) {
            return input;
        }

        StringBuilder sb = new StringBuilder(input.length());

        // https://stackoverflow.com/q/8894258/114196 : Fastest way to iterate over all the chars in a String
        for (int i = 0; i < input.length(); i++) {
            char chr = input.charAt(i);

            if (chr == '\\') {
                chr = input.charAt(++i);
                switch (chr){
                    case '"':
                    case '\\':
                        sb.append(chr);
                        break;
                    case 'b':
                        sb.append('\b');
                        break;
                    case 'n':
                        sb.append('\n');
                        break;
                    case 'r':
                        sb.append('\r');
                        break;
                    case 't':
                        sb.append('\t');
                        break;
                    case 'v':
                        sb.append((char)hexCharsToByte('0', 'b'));
                        break;
                    case 'x':
                        // This should be \xhh  (hh = [0-9a-f][0-9a-f])
                        char chr1 = input.charAt(++i);
                        char chr2 = input.charAt(++i);
                        sb.append((char)hexCharsToByte(chr1, chr2));
                        break;
                    default:
                        // This shouldn't happen.
                        // Let's just append the unmodified input for now.
                        sb.append('\\').append(chr);
                }
            } else {
                sb.append(chr);
            }

        }
        return sb.toString();
    }

    private  Utils();

}