public static String mangleName ( String name ) { boolean toLower = CauchoUtil . isCaseInsensitive ( ) ; CharBuffer cb = new CharBuffer ( ) ; cb . append ( "_" ) ; for ( int i = 0 ; i < name . length ( ) ; i ++ ) { char ch = name . charAt ( i ) ; if ( ch == ' ' || ch == CauchoUtil . getPathSeparatorChar ( ) ) { if ( i == 0 ) { } else if ( cb . charAt ( cb . length ( ) - 1 ) != ' ' && ( i + 1 < name . length ( ) && name . charAt ( i + 1 ) != ' ' ) ) cb . append ( "._" ) ; } else if ( ch == ' ' ) cb . append ( "__" ) ; else if ( ch == ' ' ) cb . append ( "_0" ) ; else if ( Character . isJavaIdentifierPart ( ch ) ) cb . append ( toLower ? Character . toLowerCase ( ch ) : ch ) ; else if ( ch <= 256 ) cb . append ( "_2" + encodeHex ( ch >> 4 ) + encodeHex ( ch ) ) ; else cb . append ( "_4" + encodeHex ( ch >> 12 ) + encodeHex ( ch >> 8 ) + encodeHex ( ch >> 4 ) + encodeHex ( ch ) ) ; } if ( cb . length ( ) == 0 ) cb . append ( "_z" ) ; return cb . toString ( ) ; }
Mangles the path into a valid Java class name .