1 /*
2 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
301 KAYAH_LI ('\ua900', '\ua900', '\ua930'),
302 /**
303 * The Cham range with the Cham digits.
304 */
305 CHAM ('\uaa50', '\uaa00', '\uaa60'),
306 /**
307 * The Tai Tham Hora range with the Tai Tham Hora digits.
308 */
309 TAI_THAM_HORA ('\u1a80', '\u1a20', '\u1ab0'),
310 /**
311 * The Tai Tham Tham range with the Tai Tham Tham digits.
312 */
313 TAI_THAM_THAM ('\u1a90', '\u1a20', '\u1ab0'),
314 /**
315 * The Javanese range with the Javanese digits.
316 */
317 JAVANESE ('\ua9d0', '\ua980', '\ua9e0'),
318 /**
319 * The Meetei Mayek range with the Meetei Mayek digits.
320 */
321 MEETEI_MAYEK ('\uabf0', '\uabc0', '\uac00');
322
323 private static int toRangeIndex(Range script) {
324 int index = script.ordinal();
325 return index < NUM_KEYS ? index : -1;
326 }
327
328 private static Range indexToRange(int index) {
329 return index < NUM_KEYS ? Range.values()[index] : null;
330 }
331
332 private static int toRangeMask(Set<Range> ranges) {
333 int m = 0;
334 for (Range range : ranges) {
335 int index = range.ordinal();
336 if (index < NUM_KEYS) {
337 m |= 1 << index;
338 }
339 }
340 return m;
341 }
607 * A range table of strong directional characters (types L, R, AL).
608 * Even (left) indexes are starts of ranges of non-strong-directional (or undefined)
609 * characters, odd (right) indexes are starts of ranges of strong directional
610 * characters.
611 */
612 private static int[] strongTable = {
613 0x0000, 0x0041,
614 0x005b, 0x0061,
615 0x007b, 0x00aa,
616 0x00ab, 0x00b5,
617 0x00b6, 0x00ba,
618 0x00bb, 0x00c0,
619 0x00d7, 0x00d8,
620 0x00f7, 0x00f8,
621 0x02b9, 0x02bb,
622 0x02c2, 0x02d0,
623 0x02d2, 0x02e0,
624 0x02e5, 0x02ee,
625 0x02ef, 0x0370,
626 0x0374, 0x0376,
627 0x037e, 0x0386,
628 0x0387, 0x0388,
629 0x03f6, 0x03f7,
630 0x0483, 0x048a,
631 0x058a, 0x05be,
632 0x05bf, 0x05c0,
633 0x05c1, 0x05c3,
634 0x05c4, 0x05c6,
635 0x05c7, 0x05d0,
636 0x0600, 0x0608,
637 0x0609, 0x060b,
638 0x060c, 0x060d,
639 0x060e, 0x061b,
640 0x064b, 0x066d,
641 0x0670, 0x0671,
642 0x06d6, 0x06e5,
643 0x06e7, 0x06ee,
644 0x06f0, 0x06fa,
645 0x0711, 0x0712,
646 0x0730, 0x074d,
647 0x07a6, 0x07b1,
648 0x07eb, 0x07f4,
649 0x07f6, 0x07fa,
650 0x0816, 0x081a,
651 0x081b, 0x0824,
652 0x0825, 0x0828,
653 0x0829, 0x0830,
654 0x0859, 0x085e,
655 0x08e4, 0x0903,
656 0x093a, 0x093b,
657 0x093c, 0x093d,
658 0x0941, 0x0949,
659 0x094d, 0x094e,
660 0x0951, 0x0958,
661 0x0962, 0x0964,
662 0x0981, 0x0982,
663 0x09bc, 0x09bd,
664 0x09c1, 0x09c7,
665 0x09cd, 0x09ce,
666 0x09e2, 0x09e6,
667 0x09f2, 0x09f4,
668 0x09fb, 0x0a03,
669 0x0a3c, 0x0a3e,
670 0x0a41, 0x0a59,
671 0x0a70, 0x0a72,
672 0x0a75, 0x0a83,
673 0x0abc, 0x0abd,
674 0x0ac1, 0x0ac9,
675 0x0acd, 0x0ad0,
676 0x0ae2, 0x0ae6,
677 0x0af1, 0x0b02,
678 0x0b3c, 0x0b3d,
679 0x0b3f, 0x0b40,
680 0x0b41, 0x0b47,
681 0x0b4d, 0x0b57,
682 0x0b62, 0x0b66,
683 0x0b82, 0x0b83,
684 0x0bc0, 0x0bc1,
685 0x0bcd, 0x0bd0,
686 0x0bf3, 0x0c01,
687 0x0c3e, 0x0c41,
688 0x0c46, 0x0c58,
689 0x0c62, 0x0c66,
690 0x0c78, 0x0c7f,
691 0x0cbc, 0x0cbd,
692 0x0ccc, 0x0cd5,
693 0x0ce2, 0x0ce6,
694 0x0d41, 0x0d46,
695 0x0d4d, 0x0d4e,
696 0x0d62, 0x0d66,
697 0x0dca, 0x0dcf,
698 0x0dd2, 0x0dd8,
699 0x0e31, 0x0e32,
700 0x0e34, 0x0e40,
701 0x0e47, 0x0e4f,
702 0x0eb1, 0x0eb2,
703 0x0eb4, 0x0ebd,
704 0x0ec8, 0x0ed0,
705 0x0f18, 0x0f1a,
706 0x0f35, 0x0f36,
707 0x0f37, 0x0f38,
708 0x0f39, 0x0f3e,
709 0x0f71, 0x0f7f,
710 0x0f80, 0x0f85,
711 0x0f86, 0x0f88,
712 0x0f8d, 0x0fbe,
713 0x0fc6, 0x0fc7,
714 0x102d, 0x1031,
715 0x1032, 0x1038,
716 0x1039, 0x103b,
717 0x103d, 0x103f,
718 0x1058, 0x105a,
719 0x105e, 0x1061,
720 0x1071, 0x1075,
721 0x1082, 0x1083,
722 0x1085, 0x1087,
723 0x108d, 0x108e,
724 0x109d, 0x109e,
725 0x135d, 0x1360,
726 0x1390, 0x13a0,
727 0x1400, 0x1401,
728 0x1680, 0x1681,
729 0x169b, 0x16a0,
730 0x1712, 0x1720,
731 0x1732, 0x1735,
732 0x1752, 0x1760,
733 0x1772, 0x1780,
734 0x17b4, 0x17b6,
735 0x17b7, 0x17be,
736 0x17c6, 0x17c7,
737 0x17c9, 0x17d4,
738 0x17db, 0x17dc,
739 0x17dd, 0x17e0,
740 0x17f0, 0x1810,
741 0x18a9, 0x18aa,
742 0x1920, 0x1923,
743 0x1927, 0x1929,
744 0x1932, 0x1933,
745 0x1939, 0x1946,
746 0x19de, 0x1a00,
747 0x1a17, 0x1a19,
748 0x1a56, 0x1a57,
749 0x1a58, 0x1a61,
750 0x1a62, 0x1a63,
751 0x1a65, 0x1a6d,
752 0x1a73, 0x1a80,
753 0x1b00, 0x1b04,
754 0x1b34, 0x1b35,
755 0x1b36, 0x1b3b,
756 0x1b3c, 0x1b3d,
757 0x1b42, 0x1b43,
758 0x1b6b, 0x1b74,
759 0x1b80, 0x1b82,
760 0x1ba2, 0x1ba6,
761 0x1ba8, 0x1baa,
762 0x1bab, 0x1bac,
763 0x1be6, 0x1be7,
764 0x1be8, 0x1bea,
765 0x1bed, 0x1bee,
766 0x1bef, 0x1bf2,
767 0x1c2c, 0x1c34,
768 0x1c36, 0x1c3b,
769 0x1cd0, 0x1cd3,
770 0x1cd4, 0x1ce1,
771 0x1ce2, 0x1ce9,
772 0x1ced, 0x1cee,
773 0x1cf4, 0x1cf5,
774 0x1dc0, 0x1e00,
775 0x1fbd, 0x1fbe,
776 0x1fbf, 0x1fc2,
777 0x1fcd, 0x1fd0,
778 0x1fdd, 0x1fe0,
779 0x1fed, 0x1ff2,
780 0x1ffd, 0x200e,
781 0x2010, 0x2071,
782 0x2074, 0x207f,
783 0x2080, 0x2090,
784 0x20a0, 0x2102,
785 0x2103, 0x2107,
786 0x2108, 0x210a,
787 0x2114, 0x2115,
788 0x2116, 0x2119,
789 0x211e, 0x2124,
790 0x2125, 0x2126,
791 0x2127, 0x2128,
792 0x2129, 0x212a,
793 0x212e, 0x212f,
794 0x213a, 0x213c,
795 0x2140, 0x2145,
796 0x214a, 0x214e,
797 0x2150, 0x2160,
798 0x2189, 0x2336,
799 0x237b, 0x2395,
800 0x2396, 0x249c,
801 0x24ea, 0x26ac,
802 0x26ad, 0x2800,
803 0x2900, 0x2c00,
804 0x2ce5, 0x2ceb,
805 0x2cef, 0x2cf2,
806 0x2cf9, 0x2d00,
807 0x2d7f, 0x2d80,
808 0x2de0, 0x3005,
809 0x3008, 0x3021,
810 0x302a, 0x3031,
811 0x3036, 0x3038,
812 0x303d, 0x3041,
813 0x3099, 0x309d,
814 0x30a0, 0x30a1,
815 0x30fb, 0x30fc,
816 0x31c0, 0x31f0,
817 0x321d, 0x3220,
818 0x3250, 0x3260,
819 0x327c, 0x327f,
820 0x32b1, 0x32c0,
821 0x32cc, 0x32d0,
822 0x3377, 0x337b,
823 0x33de, 0x33e0,
824 0x33ff, 0x3400,
825 0x4dc0, 0x4e00,
826 0xa490, 0xa4d0,
827 0xa60d, 0xa610,
828 0xa66f, 0xa680,
829 0xa69f, 0xa6a0,
830 0xa6f0, 0xa6f2,
831 0xa700, 0xa722,
832 0xa788, 0xa789,
833 0xa802, 0xa803,
834 0xa806, 0xa807,
835 0xa80b, 0xa80c,
836 0xa825, 0xa827,
837 0xa828, 0xa830,
838 0xa838, 0xa840,
839 0xa874, 0xa880,
840 0xa8c4, 0xa8ce,
841 0xa8e0, 0xa8f2,
842 0xa926, 0xa92e,
843 0xa947, 0xa952,
844 0xa980, 0xa983,
845 0xa9b3, 0xa9b4,
846 0xa9b6, 0xa9ba,
847 0xa9bc, 0xa9bd,
848 0xaa29, 0xaa2f,
849 0xaa31, 0xaa33,
850 0xaa35, 0xaa40,
851 0xaa43, 0xaa44,
852 0xaa4c, 0xaa4d,
853 0xaab0, 0xaab1,
854 0xaab2, 0xaab5,
855 0xaab7, 0xaab9,
856 0xaabe, 0xaac0,
857 0xaac1, 0xaac2,
858 0xaaec, 0xaaee,
859 0xaaf6, 0xab01,
860 0xabe5, 0xabe6,
861 0xabe8, 0xabe9,
862 0xabed, 0xabf0,
863 0xfb1e, 0xfb1f,
864 0xfb29, 0xfb2a,
865 0xfd3e, 0xfd50,
866 0xfdfd, 0xfe70,
867 0xfeff, 0xff21,
868 0xff3b, 0xff41,
869 0xff5b, 0xff66,
870 0xffe0, 0x10000,
871 0x10101, 0x10102,
872 0x10140, 0x101d0,
873 0x101fd, 0x10280,
874 0x1091f, 0x10920,
875 0x10a01, 0x10a10,
876 0x10a38, 0x10a40,
877 0x10b39, 0x10b40,
878 0x10e60, 0x11000,
879 0x11001, 0x11002,
880 0x11038, 0x11047,
881 0x11052, 0x11066,
882 0x11080, 0x11082,
883 0x110b3, 0x110b7,
884 0x110b9, 0x110bb,
885 0x11100, 0x11103,
886 0x11127, 0x1112c,
887 0x1112d, 0x11136,
888 0x11180, 0x11182,
889 0x111b6, 0x111bf,
890 0x116ab, 0x116ac,
891 0x116ad, 0x116ae,
892 0x116b0, 0x116b6,
893 0x116b7, 0x116c0,
894 0x16f8f, 0x16f93,
895 0x1d167, 0x1d16a,
896 0x1d173, 0x1d183,
897 0x1d185, 0x1d18c,
898 0x1d1aa, 0x1d1ae,
899 0x1d200, 0x1d360,
900 0x1d6db, 0x1d6dc,
901 0x1d715, 0x1d716,
902 0x1d74f, 0x1d750,
903 0x1d789, 0x1d78a,
904 0x1d7c3, 0x1d7c4,
905 0x1d7ce, 0x1ee00,
906 0x1eef0, 0x1f110,
907 0x1f16a, 0x1f170,
908 0x1f300, 0x1f48c,
909 0x1f48d, 0x1f524,
910 0x1f525, 0x20000,
911 0xe0001, 0xf0000,
912 0x10fffe, 0x10ffff // sentinel
913 };
914
915
916 // use a binary search with a cache
917
918 private transient volatile int stCache = 0;
919
920 private boolean isStrongDirectional(char c) {
921 int cachedIndex = stCache;
922 if (c < strongTable[cachedIndex]) {
923 cachedIndex = search(c, strongTable, 0, cachedIndex);
924 } else if (c >= strongTable[cachedIndex + 1]) {
925 cachedIndex = search(c, strongTable, cachedIndex + 1,
926 strongTable.length - cachedIndex - 1);
927 }
928 boolean val = (cachedIndex & 0x1) == 1;
929 stCache = cachedIndex;
930 return val;
931 }
|
|