public static void filter ( String value , AbstractRenderAppender result , boolean markupHTMLSpaceReturn ) { // if the value is null, return if ( value == null ) return ; // convert the string int numChars = value . length ( ) ; char c ; char prev = 0 ; for ( int i = 0 ; i < numChars ; i ++ ) { c = value . charAt ( i ) ; switch ( c ) { case ' ' : result . append ( "&lt;" ) ; break ; case ' ' : result . append ( "&gt;" ) ; break ; case ' ' : result . append ( "&amp;" ) ; break ; case ' ' : result . append ( "&quot;" ) ; break ; case ' ' : result . append ( "&#39;" ) ; break ; case ' ' : if ( markupHTMLSpaceReturn ) { if ( prev == ' ' ) { result . append ( "&nbsp;" ) ; } else result . append ( c ) ; } else result . append ( c ) ; break ; case ' ' : if ( markupHTMLSpaceReturn ) { result . append ( "<br />" ) ; } else result . append ( c ) ; break ; default : result . append ( c ) ; } prev = c ; } }
Filter the specified string for characters that are sensitive to HTML interpreters returning the string with these characters replaced by the corresponding character entities .