コード例 #1
0
        /**
         * @param c The character to encode.
         * @return Whether the given unicode character is covered by this encoding.
         */
        public bool canEncodeChar(char c)
        {
            if (c >= 0 && c < 128)
            {
                return(true);
            }

            Simple8BitChar r = this.encodeHighChar(c);

            return(r != null);
        }
コード例 #2
0
        /**
         * Pushes the encoded form of the given character to the given byte buffer.
         *
         * @param bb The byte buffer to write to.
         * @param c The character to encode.
         * @return Whether the given unicode character is covered by this encoding.
         *         If <code>false</code> is returned, nothing is pushed to the
         *         byte buffer.
         */
        public bool pushEncodedChar(java.nio.ByteBuffer bb, char c)
        {
            if (c >= 0 && c < 128)
            {
                bb.put((byte)c);
                return(true);
            }

            Simple8BitChar r = this.encodeHighChar(c);

            if (r == null)
            {
                return(false);
            }
            bb.put(r.code);
            return(true);
        }
コード例 #3
0
        /**
         * @param c A unicode character in the range from 0x0080 to 0x7f00
         * @return A Simple8BitChar, if this character is covered by this encoding.
         *         A <code>null</code> value is returned, if this character is not
         *         covered by this encoding.
         */
        private Simple8BitChar encodeHighChar(char c)
        {
            // for performance an simplicity, yet another reincarnation of
            // binary search...
            int i0 = 0;
            int i1 = this.reverseMapping.size();

            while (i1 > i0)
            {
                int i = i0 + (i1 - i0) / 2;

                Simple8BitChar m = (Simple8BitChar)this.reverseMapping.get(i);

                if (m.unicode == c)
                {
                    return(m);
                }

                if (m.unicode < c)
                {
                    i0 = i + 1;
                }
                else
                {
                    i1 = i;
                }
            }

            if (i0 >= this.reverseMapping.size())
            {
                return(null);
            }

            Simple8BitChar r = (Simple8BitChar)this.reverseMapping.get(i0);

            if (r.unicode != c)
            {
                return(null);
            }

            return(r);
        }