src/java/org/pifan/util/StringUtils.java
/**
     * Converts unicodes to encoded &#92;uxxxx and escapes
     * special characters with a preceding slash
     * 
     * @param theString
     * @param escapeSpace
     * @return
     */
Converts unicodes to encoded \uxxxx and escapes
special characters with a preceding slash

@param theString
@param escapeSpace
@return
Converts unicodes to encoded \ uxxxx and escapes special characters with a preceding slash @param theString @param escapeSpace @return
public static final String saveConvert(String theString, boolean escapeSpace) {
        int len = theString.length();
        int bufLen = len * 2;
        if (bufLen < 0) {
            bufLen = Integer.MAX_VALUE;
        }
        StringBuilder sb = new StringBuilder(bufLen);
        for (int x = 0; x < len; x++) {
            char aChar = theString.charAt(x);
            if ((aChar > 61) && (aChar < 127)) {
                if (aChar == '\\') {
                    sb.append('\\');
                    sb.append('\\');
                    continue;
                }
                sb.append(aChar);
                continue;
            }
            switch (aChar) {
            case ' ':
                if (x == 0 || escapeSpace) {
                    sb.append('\\');
                }
                sb.append(' ');
                break;
            case '\t':
                sb.append('\\');
                sb.append('t');
                break;
            case '\n':
                sb.append('\\');
                sb.append('n');
                break;
            case '\r':
                sb.append('\\');
                sb.append('r');
                break;
            case '\f':
                sb.append('\\');
                sb.append('f');
                break;
            case '=': 
            case ':': 
            case '#': 
            case '!':
                sb.append('\\');
                sb.append(aChar);
                break;
            default:
                if ((aChar < 0x0020) || (aChar > 0x007e)) {
                    sb.append('\\');
                    sb.append('u');
                    sb.append(toHex((aChar >> 12) & 0xF));
                    sb.append(toHex((aChar >> 8) & 0xF));
                    sb.append(toHex((aChar >> 4) & 0xF));
                    sb.append(toHex(aChar & 0xF));
                } else {
                    sb.append(aChar);
                }
            }
        }
        return sb.toString();
    }
public static final String saveConvert ( String theString , boolean escapeSpace ) { int len = theString . length ( ) ; int bufLen = len * 2 ; if ( bufLen < 0 ) { bufLen = Integer . MAX_VALUE ; } StringBuilder sb = new StringBuilder ( bufLen ) ; for ( int x = 0 ; x < len ; x ++ ) { char aChar = theString . charAt ( x ) ; if ( ( aChar > 61 ) && ( aChar < 127 ) ) { if ( aChar == '\\' ) { sb . append ( '\\' ) ; sb . append ( '\\' ) ; continue ; } sb . append ( aChar ) ; continue ; } switch ( aChar ) { case ' ' : if ( x == 0 || escapeSpace ) { sb . append ( '\\' ) ; } sb . append ( ' ' ) ; break ; case '\t' : sb . append ( '\\' ) ; sb . append ( 't' ) ; break ; case '\n' : sb . append ( '\\' ) ; sb . append ( 'n' ) ; break ; case '\r' : sb . append ( '\\' ) ; sb . append ( 'r' ) ; break ; case '\f' : sb . append ( '\\' ) ; sb . append ( 'f' ) ; break ; case '=' : case ':' : case '#' : case '!' : sb . append ( '\\' ) ; sb . append ( aChar ) ; break ; default : if ( ( aChar < 0x0020 ) || ( aChar > 0x007e ) ) { sb . append ( '\\' ) ; sb . append ( 'u' ) ; sb . append ( toHex ( ( aChar >> 12 ) & 0xF ) ) ; sb . append ( toHex ( ( aChar >> 8 ) & 0xF ) ) ; sb . append ( toHex ( ( aChar >> 4 ) & 0xF ) ) ; sb . append ( toHex ( aChar & 0xF ) ) ; } else { sb . append ( aChar ) ; } } } return sb . toString ( ) ; }
Converts unicodes to encoded &#92;uxxxx and escapes
 special characters with a preceding slash
Converts unicodes to encoded &#92 ; uxxxx and escapes special characters with a preceding slash
// Handle common case first, selecting largest block that
 // avoids the specials below
 // Fall through
 // Fall through
 // Fall through
