Taylor Gautier <[EMAIL PROTECTED]> wrote:
>I have to concur, this is one of the more annoying things about building
>dynamic pages with current Java solutions.
>...
Due to the lack of a standard API there must be quite a few HTMLEncode
variants out there (including my own, with slight variations for cookies,
urls, etc.)
>FYI, Myriam, for better efficiency (for the time being) you should use the
>toCharArray() function of a String (indexing into an array repeatedly is far
>faster than calling an API to do it for you) and also change res to be a
>StringBuffer and use res.append("<"); etc.
Is it more efficient to call toCharArray, which allocates a new array of
characters, than to call charAt? It probably depends on how many times you
encode strings and how long are the strings. You can actually improve
memory allocation a bit by only allocating a string buffer and a new string
if the string contains characters that need encoding (contrast this with
String.toLower, which always allocates a new String). For most applications
it probably hardly matters to performance provided you use a StringBuffer
(as you suggest) and not the += operator.
-- Ari Halberstadt mailto:[EMAIL PROTECTED] <http://www.magiccookie.com/>
PGP public key available at <http://www.magiccookie.com/pgpkey.txt>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".