dev@javaserverfaces.java.net

Determine if an encoding is multi-byte

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Fri, 18 May 2007 10:26:41 -0700

Hey folks,

I'm working on removing the following pending comments from
c.s.f.util.HtmlUtils:

                // Double-byte characters to encode.
                // PENDING: when outputting to an encoding that
                // supports double-byte characters (UTF-8, for example),
                // we should not be encoding
                _writeDecRef(out, ch)

I've come up with:

/**
     * @param encoding a valid encoding
     * @return <code>true</code> if the specified encoding is
     * multi-byte, otherwise <code>false</code>
     */
    static public boolean isEncodingMultiByte(String encoding) {
        Charset c = Charset.forName(encoding);
        return (c.newEncoder().maxBytesPerChar() > 1.0f);
    }

Just curious if anyone had ideas on a better way to handle this detection.