CharsetSCSU.java 45.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.agl.charset;

import com.adobe.agl.charset.CharsetDecoderICU;
import com.adobe.agl.charset.CharsetEncoderICU;
import com.adobe.agl.charset.CharsetICU;
import com.adobe.agl.lang.UCharacter;
import com.adobe.agl.text.UTF16;
import com.adobe.agl.text.UnicodeSet;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.IntBuffer;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;

class CharsetSCSU
extends CharsetICU {
    private static final short SQ0 = 1;
    private static final short SQ7 = 8;
    private static final short SDX = 11;
    private static final short SQU = 14;
    private static final short SCU = 15;
    private static final short SC0 = 16;
    private static final short SC7 = 23;
    private static final short SD0 = 24;
    private static final short UC0 = 224;
    private static final short UC7 = 231;
    private static final short UD0 = 232;
    private static final short UD7 = 239;
    private static final short UQU = 240;
    private static final short UDX = 241;
    private static final short Urs = 242;
    private static final int gapThreshold = 104;
    private static final int gapOffset = 44032;
    private static final int reservedStart = 168;
    private static final int fixedThreshold = 15;
    protected byte[] fromUSubstitution = new byte[]{14, -1, -3};
    private static final int[] staticOffsets = new int[]{0, 128, 256, 768, 8192, 8320, 8448, 12288};
    private static final int[] initialDynamicOffsets = new int[]{128, 192, 1024, 1536, 2304, 12352, 12448, 65280};
    private static final int[] fixedOffsets = new int[]{192, 592, 880, 1328, 12352, 12448, 65376};
    private static final int readCommand = 0;
    private static final int quotePairOne = 1;
    private static final int quotePairTwo = 2;
    private static final int quoteOne = 3;
    private static final int definePairOne = 4;
    private static final int definePairTwo = 5;
    private static final int defineOne = 6;
    static final byte[] initialWindowUse = new byte[]{7, 0, 3, 2, 4, 5, 6, 1};
    static final byte[] initialWindowUse_ja = new byte[]{3, 2, 4, 1, 0, 7, 5, 6};
    private static final int l_ja = 1;
    private SCSUData extraInfo = null;

    public CharsetSCSU(String icuCanonicalName, String javaCanonicalName, String[] aliases) {
        super(icuCanonicalName, javaCanonicalName, aliases);
        this.maxBytesPerChar = 3;
        this.minBytesPerChar = 1;
        this.maxCharsPerByte = 1.0f;
        this.extraInfo = new SCSUData();
    }

    public CharsetDecoder newDecoder() {
        return new CharsetDecoderSCSU(this);
    }

    public CharsetEncoder newEncoder() {
        return new CharsetEncoderSCSU(this);
    }

    void getUnicodeSetImpl(UnicodeSet setFillIn, int which) {
        CharsetICU.getCompleteUnicodeSet(setFillIn);
    }

    class CharsetEncoderSCSU
    extends CharsetEncoderICU {
        private static final int Loop = 0;
        private static final int GetTrailUnicode = 1;
        private static final int OutputBytes = 2;
        private static final int EndLoop = 3;
        private int delta;
        private int length;
        private int offset;
        private char lead;
        private char trail;
        private int code;
        private byte window;
        private boolean isSingleByteMode;
        private byte dynamicWindow;
        private int currentOffset;
        int c;
        SCSUData data;
        private int sourceIndex;
        private int nextSourceIndex;
        private int targetCapacity;
        private boolean LabelLoop;
        private boolean AfterGetTrail;
        private boolean AfterGetTrailUnicode;
        CoderResult cr;

        public CharsetEncoderSCSU(CharsetICU cs) {
            super(cs, CharsetSCSU.this.fromUSubstitution);
            this.implReset();
        }

        protected void implReset() {
            super.implReset();
            CharsetSCSU.this.extraInfo.initialize();
        }

        protected CoderResult encodeLoop(CharBuffer source, ByteBuffer target, IntBuffer offsets, boolean flush) {
            this.data = CharsetSCSU.this.extraInfo;
            this.cr = CoderResult.UNDERFLOW;
            this.isSingleByteMode = this.data.fromUIsSingleByteMode;
            this.dynamicWindow = this.data.fromUDynamicWindow;
            this.currentOffset = this.data.fromUDynamicOffsets[this.dynamicWindow];
            this.c = this.fromUChar32;
            this.sourceIndex = this.c == 0 ? 0 : -1;
            this.nextSourceIndex = 0;
            this.targetCapacity = target.limit() - target.position();
            this.sourceIndex = this.c == 0 ? 0 : -1;
            this.nextSourceIndex = 0;
            int labelType = 0;
            this.LabelLoop = true;
            this.AfterGetTrail = false;
            this.AfterGetTrailUnicode = false;
            while (this.LabelLoop) {
                switch (labelType) {
                    case 0: {
                        labelType = this.loop(source, target, offsets);
                        break;
                    }
                    case 1: {
                        labelType = this.getTrailUnicode(source, target, offsets);
                        break;
                    }
                    case 2: {
                        labelType = this.outputBytes(source, target, offsets);
                        break;
                    }
                    case 3: {
                        this.endLoop(source, target, offsets);
                    }
                }
            }
            return this.cr;
        }

        private byte getWindow(int[] offsets) {
            for (int i = 0; i < 8; ++i) {
                if (((long)(this.c - offsets[i]) & 0xFFFFFFFFL) > 127) continue;
                return (byte)i;
            }
            return -1;
        }

        private boolean isInOffsetWindowOrDirect(int offsetValue, int a) {
            return ((long)a & 0xFFFFFFFFL) <= ((long)offsetValue & 0xFFFFFFFFL) + 127 & (((long)a & 0xFFFFFFFFL) >= ((long)offsetValue & 0xFFFFFFFFL) || ((long)a & 0xFFFFFFFFL) <= 127 && (((long)a & 0xFFFFFFFFL) >= 32 || (1 << (int)((long)a & 0xFFFFFFFFL) & 9729) != 0));
        }

        private byte getNextDynamicWindow() {
            byte windowValue = this.data.windowUse[this.data.nextWindowUseIndex];
            this.data.nextWindowUseIndex = (byte)(this.data.nextWindowUseIndex + 1);
            if (this.data.nextWindowUseIndex == 8) {
                this.data.nextWindowUseIndex = 0;
            }
            return windowValue;
        }

        private void useDynamicWindow(byte windowValue) {
            int i = this.data.nextWindowUseIndex;
            do {
                if (--i >= 0) continue;
                i = 7;
            } while (this.data.windowUse[i] != windowValue);
            int j = i + 1;
            if (j == 8) {
                j = 0;
            }
            while (j != this.data.nextWindowUseIndex) {
                this.data.windowUse[i] = this.data.windowUse[j];
                i = j++;
                if (j != 8) continue;
                j = 0;
            }
            this.data.windowUse[i] = windowValue;
        }

        private int getDynamicOffset() {
            for (int i = 0; i < 7; ++i) {
                if (((long)(this.c - fixedOffsets[i]) & 0xFFFFFFFFL) > 127) continue;
                this.offset = fixedOffsets[i];
                return 249 + i;
            }
            if (((long)this.c & 0xFFFFFFFFL) < 128) {
                return -1;
            }
            if (((long)this.c & 0xFFFFFFFFL) < 13312 || ((long)(this.c - 65536) & 0xFFFFFFFFL) < 16384 || ((long)(this.c - 118784) & 0xFFFFFFFFL) <= 12287) {
                this.offset = this.c & 2147483520;
                return this.c >> 7;
            }
            if (57344 <= ((long)this.c & 0xFFFFFFFFL) && ((long)this.c & 0xFFFFFFFFL) != 65279 && ((long)this.c & 0xFFFFFFFFL) < 65520) {
                this.offset = this.c & 2147483520;
                return this.c - 44032 >> 7;
            }
            return -1;
        }

        /*
         * Unable to fully structure code
         * Enabled aggressive block sorting
         * Lifted jumps to return sites
         */
        private int loop(CharBuffer source, ByteBuffer target, IntBuffer offsets) {
            label = 0;
            if (this.isSingleByteMode) ** GOTO lbl6
            if (this.c != 0 && this.targetCapacity > 0 && !this.AfterGetTrailUnicode) {
                return 1;
            }
            ** GOTO lbl125
lbl6: // 1 sources:
            if (this.c != 0 && this.targetCapacity > 0 && !this.AfterGetTrail) {
                return this.getTrail(source, target, offsets);
            }
            do {
                if (!this.AfterGetTrail) {
                    if (source.hasRemaining() == false) return 3;
                }
                if (this.targetCapacity <= 0 && !this.AfterGetTrail) {
                    this.cr = CoderResult.OVERFLOW;
                    return 3;
                }
                if (!this.AfterGetTrail) {
                    this.c = source.get();
                    ++this.nextSourceIndex;
                }
                if (((long)(this.c - 32) & 0xFFFFFFFFL) > 95 || this.AfterGetTrail) ** GOTO lbl23
                target.put((byte)this.c);
                if (offsets != null) {
                    offsets.put(this.sourceIndex);
                }
                --this.targetCapacity;
                ** GOTO lbl122
lbl23: // 1 sources:
                if (((long)this.c & 0xFFFFFFFFL) >= 32 || this.AfterGetTrail) ** GOTO lbl33
                if ((1 << (int)((long)this.c & 0xFFFFFFFFL) & 9729) == 0) {
                    this.c |= 256;
                    this.length = 2;
                    return 2;
                }
                target.put((byte)this.c);
                if (offsets != null) {
                    offsets.put(this.sourceIndex);
                }
                --this.targetCapacity;
                ** GOTO lbl122
lbl33: // 1 sources:
                this.delta = this.c - this.currentOffset;
                if (((long)this.delta & 0xFFFFFFFFL) > 127 || this.AfterGetTrail) ** GOTO lbl40
                target.put((byte)(this.delta | 128));
                if (offsets != null) {
                    offsets.put(this.sourceIndex);
                }
                --this.targetCapacity;
                ** GOTO lbl122
lbl40: // 1 sources:
                if (!this.AfterGetTrail && !UTF16.isSurrogate((char)this.c)) ** GOTO lbl81
                if (!this.AfterGetTrail) {
                    if (!UTF16.isLeadSurrogate((char)this.c)) {
                        this.cr = CoderResult.malformedForLength(1);
                        return 3;
                    }
                    label = this.getTrail(source, target, offsets);
                    if (label == 3) {
                        return label;
                    }
                }
                if (this.AfterGetTrail) {
                    this.AfterGetTrail = false;
                }
                if (((long)(this.delta = this.c - this.currentOffset) & 0xFFFFFFFFL) <= 127) {
                    target.put((byte)(this.delta | 128));
                    if (offsets != null) {
                        offsets.put(this.sourceIndex);
                    }
                    --this.targetCapacity;
                } else {
                    this.window = this.getWindow(this.data.fromUDynamicOffsets);
                    if (this.window >= 0) {
                        this.dynamicWindow = this.window;
                        this.currentOffset = this.data.fromUDynamicOffsets[this.dynamicWindow];
                        this.useDynamicWindow(this.dynamicWindow);
                        this.c = 16 + this.dynamicWindow << 8 | this.c - this.currentOffset | 128;
                        this.length = 2;
                        return 2;
                    }
                    this.code = this.getDynamicOffset();
                    if (this.code >= 0) {
                        this.code -= 512;
                        this.dynamicWindow = this.getNextDynamicWindow();
                        this.currentOffset = this.data.fromUDynamicOffsets[this.dynamicWindow] = this.offset;
                        this.useDynamicWindow(this.dynamicWindow);
                        this.c = 184549376 | this.dynamicWindow << 21 | this.code << 8 | this.c - this.currentOffset | 128;
                        this.length = 4;
                        return 2;
                    }
                    this.isSingleByteMode = false;
                    target.put(15);
                    if (offsets != null) {
                        offsets.put(this.sourceIndex);
                    }
                    --this.targetCapacity;
                    this.c = this.lead << 16 | this.trail;
                    this.length = 4;
                    return 2;
lbl81: // 1 sources:
                    if (((long)this.c & 0xFFFFFFFFL) < 160) {
                        this.c = this.c & 127 | 512;
                        this.length = 2;
                        return 2;
                    }
                    if (((long)this.c & 0xFFFFFFFFL) == 65279 || ((long)this.c & 0xFFFFFFFFL) >= 65520) {
                        this.c |= 917504;
                        this.length = 3;
                        return 2;
                    }
                    this.window = this.getWindow(this.data.fromUDynamicOffsets);
                    if (this.window >= 0) {
                        if (source.position() < source.limit() && !this.isInOffsetWindowOrDirect(this.data.fromUDynamicOffsets[this.window], source.get(source.position()))) {
                            this.c = 1 + this.window << 8 | this.c - this.data.fromUDynamicOffsets[this.window] | 128;
                            this.length = 2;
                            return 2;
                        }
                        this.dynamicWindow = this.window;
                        this.currentOffset = this.data.fromUDynamicOffsets[this.dynamicWindow];
                        this.useDynamicWindow(this.dynamicWindow);
                        this.c = 16 + this.window << 8 | this.c - this.currentOffset | 128;
                        this.length = 2;
                        return 2;
                    }
                    this.window = this.getWindow(CharsetSCSU.access$200());
                    if (this.window >= 0) {
                        this.c = 1 + this.window << 8 | this.c - CharsetSCSU.access$200()[this.window];
                        this.length = 2;
                        return 2;
                    }
                    this.code = this.getDynamicOffset();
                    if (this.code >= 0) {
                        this.dynamicWindow = this.getNextDynamicWindow();
                        this.currentOffset = this.data.fromUDynamicOffsets[this.dynamicWindow] = this.offset;
                        this.useDynamicWindow(this.dynamicWindow);
                        this.c = 24 + this.dynamicWindow << 16 | this.code << 8 | this.c - this.currentOffset | 128;
                        this.length = 3;
                        return 2;
                    }
                    if ((int)((long)(this.c - 13312) & 0xFFFFFFFFL) < 41984 && (source.position() >= source.limit() || (int)((long)(source.get(source.position()) - 13312) & 0xFFFFFFFFL) < 41984)) {
                        this.isSingleByteMode = false;
                        this.c |= 983040;
                        this.length = 3;
                        return 2;
                    }
                    this.c |= 917504;
                    this.length = 3;
                    return 2;
                }
lbl122: // 4 sources:
                this.c = 0;
                this.sourceIndex = this.nextSourceIndex;
            } while (true);
lbl125: // 1 sources:
            do {
                if (!this.AfterGetTrailUnicode) {
                    if (source.hasRemaining() == false) return 3;
                }
                if (this.targetCapacity <= 0 && !this.AfterGetTrailUnicode) break;
                if (!this.AfterGetTrailUnicode) {
                    this.c = source.get();
                    ++this.nextSourceIndex;
                }
                if (((long)(this.c - 13312) & 0xFFFFFFFFL) >= 41984 || this.AfterGetTrailUnicode) ** GOTO lbl144
                if (this.targetCapacity < 2) {
                    this.length = 2;
                    return 2;
                }
                target.put((byte)(this.c >> 8));
                target.put((byte)this.c);
                if (offsets != null) {
                    offsets.put(this.sourceIndex);
                    offsets.put(this.sourceIndex);
                }
                this.targetCapacity -= 2;
                if (!this.AfterGetTrailUnicode) ** GOTO lbl177
                ** GOTO lbl176
lbl144: // 1 sources:
                if (((long)(this.c - 13312) & 0xFFFFFFFFL) >= 48896 && !this.AfterGetTrailUnicode) {
                    if (!source.hasRemaining() || ((long)(source.get(source.position()) - 13312) & 0xFFFFFFFFL) >= 41984) {
                        if (((long)(this.c - 48) & 0xFFFFFFFFL) < 10 || ((long)(this.c - 97) & 0xFFFFFFFFL) < 26 || ((long)(this.c - 65) & 0xFFFFFFFFL) < 26) {
                            this.isSingleByteMode = true;
                            this.c |= 224 + this.dynamicWindow << 8 | this.c;
                            this.length = 2;
                            return 2;
                        }
                        this.window = this.getWindow(this.data.fromUDynamicOffsets);
                        if (this.window >= 0) {
                            this.isSingleByteMode = true;
                            this.dynamicWindow = this.window;
                            this.currentOffset = this.data.fromUDynamicOffsets[this.dynamicWindow];
                            this.useDynamicWindow(this.dynamicWindow);
                            this.c = 224 + this.dynamicWindow << 8 | this.c - this.currentOffset | 128;
                            this.length = 2;
                            return 2;
                        }
                        this.code = this.getDynamicOffset();
                        if (this.code >= 0) {
                            this.isSingleByteMode = true;
                            this.dynamicWindow = this.getNextDynamicWindow();
                            this.currentOffset = this.data.fromUDynamicOffsets[this.dynamicWindow] = this.offset;
                            this.useDynamicWindow(this.dynamicWindow);
                            this.c = 232 + this.dynamicWindow << 16 | this.code << 8 | this.c - this.currentOffset | 128;
                            this.length = 3;
                            return 2;
                        }
                    }
                    this.length = 2;
                    return 2;
                }
                if (this.c < 57344 && !this.AfterGetTrailUnicode) {
                    return 1;
                }
                this.c |= 15728640;
                this.length = 3;
                return 2;
lbl176: // 1 sources:
                this.AfterGetTrailUnicode = false;
lbl177: // 2 sources:
                this.c = 0;
                this.sourceIndex = this.nextSourceIndex;
            } while (true);
            this.cr = CoderResult.OVERFLOW;
            this.LabelLoop = false;
            return 3;
        }

        private int getTrail(CharBuffer source, ByteBuffer target, IntBuffer offsets) {
            this.lead = (char)this.c;
            int label = 0;
            if (source.hasRemaining()) {
                this.trail = source.get(source.position());
                if (UTF16.isTrailSurrogate(this.trail)) {
                    source.position(source.position() + 1);
                    ++this.nextSourceIndex;
                    this.c = UCharacter.getCodePoint((char)this.c, this.trail);
                    label = 0;
                } else {
                    this.cr = CoderResult.malformedForLength(1);
                    label = 3;
                }
            } else {
                label = 3;
            }
            this.AfterGetTrail = true;
            return label;
        }

        /*
         * Enabled aggressive block sorting
         */
        private int getTrailUnicode(CharBuffer source, ByteBuffer target, IntBuffer offsets) {
            int label = 3;
            this.AfterGetTrailUnicode = true;
            if (!UTF16.isLeadSurrogate((char)this.c)) {
                this.cr = CoderResult.malformedForLength(1);
                return 3;
            }
            this.lead = (char)this.c;
            if (!source.hasRemaining()) {
                return 3;
            }
            this.trail = source.get(source.position());
            if (!UTF16.isTrailSurrogate(this.trail)) {
                this.cr = CoderResult.malformedForLength(1);
                return 3;
            }
            source.get();
            ++this.nextSourceIndex;
            this.c = UCharacter.getCodePoint((char)this.c, this.trail);
            this.window = this.getWindow(this.data.fromUDynamicOffsets);
            if (!(this.window < 0 || source.hasRemaining() && ((long)(source.get(source.position()) - 13312) & 0xFFFFFFFFL) < 41984)) {
                this.isSingleByteMode = true;
                this.dynamicWindow = this.window;
                this.currentOffset = this.data.fromUDynamicOffsets[this.dynamicWindow];
                this.useDynamicWindow(this.dynamicWindow);
                this.c = 224 + this.dynamicWindow << 8 | this.c - this.currentOffset | 128;
                this.length = 2;
                return 2;
            }
            if (source.hasRemaining() && this.lead == source.get(source.position()) && (this.code = this.getDynamicOffset()) >= 0) {
                this.isSingleByteMode = true;
                this.dynamicWindow = this.getNextDynamicWindow();
                this.currentOffset = this.data.fromUDynamicOffsets[this.dynamicWindow] = this.offset;
                this.useDynamicWindow(this.dynamicWindow);
                this.c = -251658240 | this.dynamicWindow << 21 | this.code << 8 | this.c - this.currentOffset | 128;
                this.length = 4;
                return 2;
            }
            this.c = this.lead << 16 | this.trail;
            this.length = 4;
            return 2;
        }

        private void endLoop(CharBuffer source, ByteBuffer target, IntBuffer offsets) {
            this.data.fromUIsSingleByteMode = this.isSingleByteMode;
            this.data.fromUDynamicWindow = this.dynamicWindow;
            this.fromUChar32 = this.c;
            this.LabelLoop = false;
        }

        private int outputBytes(CharBuffer source, ByteBuffer target, IntBuffer offsets) {
            if (this.length <= this.targetCapacity) {
                if (offsets == null) {
                    switch (this.length) {
                        case 4: {
                            target.put((byte)(this.c >> 24));
                        }
                        case 3: {
                            target.put((byte)(this.c >> 16));
                        }
                        case 2: {
                            target.put((byte)(this.c >> 8));
                        }
                        case 1: {
                            target.put((byte)this.c);
                        }
                    }
                } else {
                    switch (this.length) {
                        case 4: {
                            target.put((byte)(this.c >> 24));
                            if (offsets != null) {
                                offsets.put(this.sourceIndex);
                            }
                        }
                        case 3: {
                            target.put((byte)(this.c >> 16));
                            if (offsets != null) {
                                offsets.put(this.sourceIndex);
                            }
                        }
                        case 2: {
                            target.put((byte)(this.c >> 8));
                            if (offsets != null) {
                                offsets.put(this.sourceIndex);
                            }
                        }
                        case 1: {
                            target.put((byte)this.c);
                            if (offsets == null) break;
                            offsets.put(this.sourceIndex);
                        }
                    }
                }
                this.targetCapacity -= this.length;
                this.c = 0;
                this.sourceIndex = this.nextSourceIndex;
                int label = 0;
                return label;
            }
            ByteBuffer p = ByteBuffer.wrap(this.errorBuffer);
            this.length -= this.targetCapacity;
            switch (this.length) {
                case 4: {
                    p.put((byte)(this.c >> 24));
                }
                case 3: {
                    p.put((byte)(this.c >> 16));
                }
                case 2: {
                    p.put((byte)(this.c >> 8));
                }
                case 1: {
                    p.put((byte)this.c);
                }
            }
            this.errorBufferLength = this.length;
            this.c >>= 8 * this.length;
            switch (this.targetCapacity) {
                case 3: {
                    target.put((byte)(this.c >> 16));
                    if (offsets != null) {
                        offsets.put(this.sourceIndex);
                    }
                }
                case 2: {
                    target.put((byte)(this.c >> 8));
                    if (offsets != null) {
                        offsets.put(this.sourceIndex);
                    }
                }
                case 1: {
                    target.put((byte)this.c);
                    if (offsets == null) break;
                    offsets.put(this.sourceIndex);
                }
            }
            this.targetCapacity = 0;
            this.cr = CoderResult.OVERFLOW;
            this.c = 0;
            int label = 3;
            return label;
        }
    }

    class CharsetDecoderSCSU
    extends CharsetDecoderICU {
        private static final int FastSingle = 0;
        private static final int SingleByteMode = 1;
        private static final int EndLoop = 2;
        private static final int ByteMode = 0;
        private static final int UnicodeMode = 1;
        short b;
        private boolean isSingleByteMode;
        private short state;
        private byte quoteWindow;
        private byte dynamicWindow;
        private short byteOne;
        private int sourceIndex;
        private int nextSourceIndex;
        CoderResult cr;
        SCSUData data;
        private boolean LabelLoop;

        public CharsetDecoderSCSU(CharsetICU cs) {
            super(cs);
            this.implReset();
        }

        protected void implReset() {
            super.implReset();
            this.toULength = 0;
            CharsetSCSU.this.extraInfo.initialize();
        }

        protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets, boolean flush) {
            this.data = CharsetSCSU.this.extraInfo;
            this.isSingleByteMode = this.data.toUIsSingleByteMode;
            this.state = this.data.toUState;
            this.quoteWindow = this.data.toUQuoteWindow;
            this.dynamicWindow = this.data.toUDynamicWindow;
            this.byteOne = this.data.toUByteOne;
            this.LabelLoop = true;
            this.sourceIndex = this.data.toUState == 0 ? 0 : -1;
            this.nextSourceIndex = 0;
            this.cr = CoderResult.UNDERFLOW;
            int labelType = 0;
            while (this.LabelLoop) {
                if (this.isSingleByteMode) {
                    switch (labelType) {
                        case 0: {
                            labelType = this.fastSingle(source, target, offsets, 0);
                            break;
                        }
                        case 1: {
                            labelType = this.singleByteMode(source, target, offsets, 0);
                            break;
                        }
                        case 2: {
                            this.endLoop(source, target, offsets);
                        }
                    }
                    continue;
                }
                switch (labelType) {
                    case 0: {
                        labelType = this.fastSingle(source, target, offsets, 1);
                        break;
                    }
                    case 1: {
                        labelType = this.singleByteMode(source, target, offsets, 1);
                        break;
                    }
                    case 2: {
                        this.endLoop(source, target, offsets);
                    }
                }
            }
            return this.cr;
        }

        private int fastSingle(ByteBuffer source, CharBuffer target, IntBuffer offsets, int modeType) {
            int label = 0;
            if (modeType == 0) {
                if (this.state == 0) {
                    while (source.hasRemaining() && target.hasRemaining() && (this.b = (short)(source.get(source.position()) & 255)) >= 32) {
                        source.position(source.position() + 1);
                        ++this.nextSourceIndex;
                        if (this.b <= 127) {
                            target.put((char)this.b);
                            if (offsets != null) {
                                offsets.put(this.sourceIndex);
                            }
                        } else {
                            int c = this.data.toUDynamicOffsets[this.dynamicWindow] + (this.b & 127);
                            if (c <= 65535) {
                                target.put((char)c);
                                if (offsets != null) {
                                    offsets.put(this.sourceIndex);
                                }
                            } else {
                                target.put((char)(55232 + (c >> 10)));
                                if (target.hasRemaining()) {
                                    target.put((char)(56320 | c & 1023));
                                    if (offsets != null) {
                                        offsets.put(this.sourceIndex);
                                        offsets.put(this.sourceIndex);
                                    }
                                } else {
                                    if (offsets != null) {
                                        offsets.put(this.sourceIndex);
                                    }
                                    this.charErrorBufferArray[0] = (char)(56320 | c & 1023);
                                    this.charErrorBufferLength = 1;
                                    label = 2;
                                    this.cr = CoderResult.OVERFLOW;
                                    this.LabelLoop = false;
                                    return label;
                                }
                            }
                        }
                        this.sourceIndex = this.nextSourceIndex;
                    }
                }
            } else if (modeType == 1 && this.state == 0) {
                while (source.position() + 1 < source.limit() && target.hasRemaining() && ((this.b = (short)source.get(source.position())) - 224 & 255) > 18) {
                    target.put((char)(this.b << 8 | source.get(source.position() + 1) & 255));
                    if (offsets != null) {
                        offsets.put(this.sourceIndex);
                    }
                    this.sourceIndex = this.nextSourceIndex;
                    this.nextSourceIndex += 2;
                    source.position(source.position() + 2);
                }
            }
            label = 1;
            return label;
        }

        private int singleByteMode(ByteBuffer source, CharBuffer target, IntBuffer offsets, int modeType) {
            int label = 1;
            if (modeType == 0) {
                while (source.hasRemaining()) {
                    if (!target.hasRemaining()) {
                        this.cr = CoderResult.OVERFLOW;
                        this.LabelLoop = false;
                        return label;
                    }
                    this.b = (short)(source.get() & 255);
                    ++this.nextSourceIndex;
                    switch (this.state) {
                        case 0: {
                            if ((1 << this.b & 9729) != 0) {
                                target.put((char)this.b);
                                if (offsets != null) {
                                    offsets.put(this.sourceIndex);
                                }
                                this.sourceIndex = this.nextSourceIndex;
                                label = 0;
                                return label;
                            }
                            if (16 <= this.b) {
                                if (this.b <= 23) {
                                    this.dynamicWindow = (byte)(this.b - 16);
                                    this.sourceIndex = this.nextSourceIndex;
                                    label = 0;
                                    return label;
                                }
                                this.dynamicWindow = (byte)(this.b - 24);
                                this.state = 6;
                            } else if (this.b <= 8) {
                                this.quoteWindow = (byte)(this.b - 1);
                                this.state = 3;
                            } else if (this.b == 11) {
                                this.state = 4;
                            } else if (this.b == 14) {
                                this.state = 1;
                            } else {
                                if (this.b == 15) {
                                    this.sourceIndex = this.nextSourceIndex;
                                    this.isSingleByteMode = false;
                                    label = 0;
                                    return label;
                                }
                                this.cr = CoderResult.malformedForLength(1);
                                this.toUBytesArray[0] = (byte)this.b;
                                this.toULength = 1;
                                label = 2;
                                return label;
                            }
                            this.toUBytesArray[0] = (byte)this.b;
                            this.toULength = 1;
                            break;
                        }
                        case 1: {
                            this.byteOne = this.b;
                            this.toUBytesArray[1] = (byte)this.b;
                            this.toULength = 2;
                            this.state = 2;
                            break;
                        }
                        case 2: {
                            target.put((char)(this.byteOne << 8 | this.b));
                            if (offsets != null) {
                                offsets.put(this.sourceIndex);
                            }
                            this.sourceIndex = this.nextSourceIndex;
                            this.state = 0;
                            label = 0;
                            return label;
                        }
                        case 3: {
                            if (this.b < 128) {
                                target.put((char)(staticOffsets[this.quoteWindow] + this.b));
                                if (offsets != null) {
                                    offsets.put(this.sourceIndex);
                                }
                            } else {
                                int c = this.data.toUDynamicOffsets[this.quoteWindow] + (this.b & 127);
                                if (c <= 65535) {
                                    target.put((char)c);
                                    if (offsets != null) {
                                        offsets.put(this.sourceIndex);
                                    }
                                } else {
                                    target.put((char)(55232 + (c >> 10)));
                                    if (target.hasRemaining()) {
                                        target.put((char)(56320 | c & 1023));
                                        if (offsets != null) {
                                            offsets.put(this.sourceIndex);
                                            offsets.put(this.sourceIndex);
                                        }
                                    } else {
                                        if (offsets != null) {
                                            offsets.put(this.sourceIndex);
                                        }
                                        this.charErrorBufferArray[0] = (char)(56320 | c & 1023);
                                        this.charErrorBufferLength = 1;
                                        label = 2;
                                        this.cr = CoderResult.OVERFLOW;
                                        this.LabelLoop = false;
                                        return label;
                                    }
                                }
                            }
                            this.sourceIndex = this.nextSourceIndex;
                            this.state = 0;
                            label = 0;
                            return label;
                        }
                        case 4: {
                            this.dynamicWindow = (byte)(this.b >> 5 & 7);
                            this.byteOne = (byte)(this.b & 31);
                            this.toUBytesArray[1] = (byte)this.b;
                            this.toULength = 2;
                            this.state = 5;
                            break;
                        }
                        case 5: {
                            this.data.toUDynamicOffsets[this.dynamicWindow] = 65536 + (this.byteOne << 15 | this.b << 7);
                            this.sourceIndex = this.nextSourceIndex;
                            this.state = 0;
                            label = 0;
                            return label;
                        }
                        case 6: {
                            if (this.b == 0) {
                                this.toUBytesArray[1] = (byte)this.b;
                                this.toULength = 2;
                                label = 2;
                                return label;
                            }
                            if (this.b < 104) {
                                this.data.toUDynamicOffsets[this.dynamicWindow] = this.b << 7;
                            } else if ((byte)(this.b - 104) < 64) {
                                this.data.toUDynamicOffsets[this.dynamicWindow] = (this.b << 7) + 44032;
                            } else if (this.b >= 15) {
                                this.data.toUDynamicOffsets[this.dynamicWindow] = fixedOffsets[this.b - 15];
                            } else {
                                this.toUBytesArray[1] = (byte)this.b;
                                this.toULength = 2;
                                label = 2;
                                return label;
                            }
                            this.sourceIndex = this.nextSourceIndex;
                            this.state = 0;
                            label = 0;
                            return label;
                        }
                    }
                }
            } else if (modeType == 1) {
                while (source.hasRemaining()) {
                    if (!target.hasRemaining()) {
                        this.cr = CoderResult.OVERFLOW;
                        this.LabelLoop = false;
                        return label;
                    }
                    this.b = source.get();
                    ++this.nextSourceIndex;
                    switch (this.state) {
                        case 0: {
                            if ((byte)(this.b - 224) > 18) {
                                this.byteOne = this.b;
                                this.toUBytesArray[0] = (byte)this.b;
                                this.toULength = 1;
                                this.state = 1;
                                break;
                            }
                            if ((this.b & 255) <= 231) {
                                this.dynamicWindow = (byte)(this.b - 224);
                                this.sourceIndex = this.nextSourceIndex;
                                this.isSingleByteMode = true;
                                label = 0;
                                return label;
                            }
                            if ((this.b & 255) <= 239) {
                                this.dynamicWindow = (byte)(this.b - 232);
                                this.isSingleByteMode = true;
                                this.toUBytesArray[0] = (byte)this.b;
                                this.toULength = 1;
                                this.state = 6;
                                label = 1;
                                return label;
                            }
                            if ((this.b & 255) == 241) {
                                this.isSingleByteMode = true;
                                this.toUBytesArray[0] = (byte)this.b;
                                this.toULength = 1;
                                this.state = 4;
                                label = 1;
                                return label;
                            }
                            if ((this.b & 255) == 240) {
                                this.toUBytesArray[0] = (byte)this.b;
                                this.toULength = 1;
                                this.state = 1;
                                break;
                            }
                            this.cr = CoderResult.malformedForLength(1);
                            this.toUBytesArray[0] = (byte)this.b;
                            this.toULength = 1;
                            label = 2;
                            return label;
                        }
                        case 1: {
                            this.byteOne = this.b;
                            this.toUBytesArray[1] = (byte)this.b;
                            this.toULength = 2;
                            this.state = 2;
                            break;
                        }
                        case 2: {
                            target.put((char)(this.byteOne << 8 | this.b));
                            if (offsets != null) {
                                offsets.put(this.sourceIndex);
                            }
                            this.sourceIndex = this.nextSourceIndex;
                            this.state = 0;
                            label = 0;
                            return label;
                        }
                    }
                }
            }
            label = 2;
            return label;
        }

        private void endLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets) {
            if (this.cr == CoderResult.OVERFLOW) {
                this.state = 0;
            } else if (this.state == 0) {
                this.toULength = 0;
            }
            this.data.toUIsSingleByteMode = this.isSingleByteMode;
            this.data.toUState = this.state;
            this.data.toUQuoteWindow = this.quoteWindow;
            this.data.toUDynamicWindow = this.dynamicWindow;
            this.data.toUByteOne = this.byteOne;
            this.LabelLoop = false;
        }
    }

    private final class SCSUData {
        int[] toUDynamicOffsets;
        int[] fromUDynamicOffsets;
        boolean toUIsSingleByteMode;
        short toUState;
        byte toUQuoteWindow;
        byte toUDynamicWindow;
        short toUByteOne;
        short[] toUPadding;
        boolean fromUIsSingleByteMode;
        byte fromUDynamicWindow;
        byte locale;
        byte nextWindowUseIndex;
        byte[] windowUse;

        SCSUData() {
            this.toUDynamicOffsets = new int[8];
            this.fromUDynamicOffsets = new int[8];
            this.windowUse = new byte[8];
            this.initialize();
        }

        void initialize() {
            int i;
            for (i = 0; i < 8; ++i) {
                this.toUDynamicOffsets[i] = initialDynamicOffsets[i];
            }
            this.toUIsSingleByteMode = true;
            this.toUState = 0;
            this.toUQuoteWindow = 0;
            this.toUDynamicWindow = 0;
            this.toUByteOne = 0;
            this.fromUIsSingleByteMode = true;
            this.fromUDynamicWindow = 0;
            for (i = 0; i < 8; ++i) {
                this.fromUDynamicOffsets[i] = initialDynamicOffsets[i];
            }
            this.nextWindowUseIndex = 0;
            switch (this.locale) {
                case 1: {
                    for (i = 0; i < 8; ++i) {
                        this.windowUse[i] = CharsetSCSU.initialWindowUse_ja[i];
                    }
                    break;
                }
                default: {
                    for (i = 0; i < 8; ++i) {
                        this.windowUse[i] = CharsetSCSU.initialWindowUse[i];
                    }
                }
            }
        }
    }

}