dev@javaserverfaces.java.net

Re: Determine if an encoding is multi-byte

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Wed, 06 Jun 2007 10:33:11 -0700

Ed Burns wrote:
>>>>>> On Fri, 18 May 2007 10:26:41 -0700, Ryan Lubke <Ryan.Lubke_at_Sun.COM> said:
>>>>>>
>
> RL> Hey folks,
> RL> I'm working on removing the following pending comments from
> RL> c.s.f.util.HtmlUtils:
>
> RL> // Double-byte characters to encode.
> RL> // PENDING: when outputting to an encoding that
> RL> // supports double-byte characters (UTF-8, for example),
> RL> // we should not be encoding
> RL> _writeDecRef(out, ch)
>
> RL> I've come up with:
>
> RL> /**
> RL> * @param encoding a valid encoding
> RL> * @return <code>true</code> if the specified encoding is
> RL> * multi-byte, otherwise <code>false</code>
> RL> */
> RL> static public boolean isEncodingMultiByte(String encoding) {
> RL> Charset c = Charset.forName(encoding);
> RL> return (c.newEncoder().maxBytesPerChar() > 1.0f);
> RL> }
>
> RL> Just curious if anyone had ideas on a better way to handle this detection.
>
> How frequently will this be called? If frequently, consider caching the
> result.
>
> Ed
>
>
Turns out I was barking up the wrong tree. Adam clarified what the
comment was
actually referring to.