static String normalizeUri ( String s ) { int n = s . length ( ) ; boolean colonsIrrelevant = false ; for ( int i = 0 ; i < n ; ++ i ) { char ch = s . charAt ( i ) ; switch ( ch ) { case ' ' : case ' ' : case ' ' : case ' ' : colonsIrrelevant = true ; break ; case ' ' : case ' ' : case ' ' : case ' ' : return normalizeUriFrom ( s , i , colonsIrrelevant ) ; case ' ' : case ' ' : case ' ' : case ' ' : if ( ! colonsIrrelevant ) { return normalizeUriFrom ( s , i , false ) ; } break ; default : if ( ch <= 0x20 ) { return normalizeUriFrom ( s , i , false ) ; } break ; } } return s ; }
Percent encodes anything that looks like a colon or a parenthesis .