class Util {

    public static String escape(String s) {
        // Guesstimate on length.  Doesn't need to be accurate, only
        // probable
        StringBuilder buff = new StringBuilder(s.length() + 20);

        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            switch(c) {
                case '\r':
                    // If not followed by '\n', convert to '\n', else strip.
                    if (i == s.length() - 1 || s.charAt(i + 1) != '\n') {
                        buff.append("\\n");
                    }
                    break;
                case '\n':
                    buff.append("\\n");
                    break;

                case '\t':
                    buff.append("\\t");
                    break;

                case '\\':
                    buff.append("\\\\");
                    break;

                default:
                    buff.append(c);
            }
        }

        return buff.toString();
    }

    private  Util();

}