|
5 | 5 |
|
6 | 6 | final class NumberParser {
|
7 | 7 |
|
8 |
| -// public final static Short SHORT_ZERO = 0; |
9 |
| -// public final static Integer INT_ZERO = 0; |
10 |
| -// public final static Long LONG_ZERO = 0L; |
11 |
| -// public final static Float FLOAT_ZERO = 0f; |
12 |
| -// public final static Double DOUBLE_ZERO = 0.0; |
13 |
| - |
14 |
| - // private final static int[] DIGITS = new int[1000]; |
15 |
| - private final static int[] DIFF = {111, 222, 444, 888, 1776}; |
16 |
| - private final static int[] ERROR = {50, 100, 200, 400, 800}; |
17 |
| - private final static int[] SCALE_10 = {10000, 1000, 100, 10, 1}; |
18 |
| - private final static double[] POW_10 = { |
| 8 | + private static final int[] DIFF = {111, 222, 444, 888, 1776}; |
| 9 | + private static final int[] ERROR = {50, 100, 200, 400, 800}; |
| 10 | + private static final int[] SCALE_10 = {10000, 1000, 100, 10, 1}; |
| 11 | + private static final double[] POW_10 = { |
19 | 12 | 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
|
20 | 13 | 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
|
21 | 14 | 1e20, 1e21, 1e22, 1e23, 1e24, 1e25, 1e26, 1e27, 1e28, 1e29,
|
@@ -699,182 +692,4 @@ static BigInteger deserializeBigInt(JParser reader) {
|
699 | 692 | }
|
700 | 693 | }
|
701 | 694 |
|
702 |
| -// private static final BigDecimal BD_MAX_LONG = BigDecimal.valueOf(Long.MAX_VALUE); |
703 |
| -// private static final BigDecimal BD_MIN_LONG = BigDecimal.valueOf(Long.MIN_VALUE); |
704 |
| -// |
705 |
| -// private static Number bigDecimalOrDouble(BigDecimal num, JsonParser.UnknownNumberParsing unknownNumbers) { |
706 |
| -// return unknownNumbers == JsonParser.UnknownNumberParsing.LONG_AND_BIGDECIMAL |
707 |
| -// ? num |
708 |
| -// : num.doubleValue(); |
709 |
| -// } |
710 |
| -// |
711 |
| -// private static Number tryLongFromBigDecimal(final char[] buf, final int len, JsonParser reader) throws IOException { |
712 |
| -// final BigDecimal num = parseNumberGeneric(buf, len, reader, false); |
713 |
| -// if (num.scale() == 0 && num.precision() <= 19) { |
714 |
| -// if (num.signum() == 1) { |
715 |
| -// if (num.compareTo(BD_MAX_LONG) <= 0) { |
716 |
| -// return num.longValue(); |
717 |
| -// } |
718 |
| -// } else if (num.compareTo(BD_MIN_LONG) >= 0) { |
719 |
| -// return num.longValue(); |
720 |
| -// } |
721 |
| -// } |
722 |
| -// return bigDecimalOrDouble(num, reader.unknownNumbers); |
723 |
| -// } |
724 |
| -// |
725 |
| -// public static Number deserializeNumber(final JReader reader) throws IOException { |
726 |
| -// if (reader.unknownNumbers == JReader.UnknownNumberParsing.BIGDECIMAL) return deserializeDecimal(reader); |
727 |
| -// else if (reader.unknownNumbers == JReader.UnknownNumberParsing.DOUBLE) return deserializeDouble(reader); |
728 |
| -// final int start = reader.scanNumber(); |
729 |
| -// int end = reader.getCurrentIndex(); |
730 |
| -// if (end == reader.length()) { |
731 |
| -// NumberInfo info = readLongNumber(reader, start); |
732 |
| -// return tryLongFromBigDecimal(info.buffer, info.length, reader); |
733 |
| -// } |
734 |
| -// int len = end - start; |
735 |
| -// if (len > 18) { |
736 |
| -// return tryLongFromBigDecimal(reader.prepareBuffer(start, len), len, reader); |
737 |
| -// } |
738 |
| -// final byte[] buf = reader.buffer; |
739 |
| -// final byte ch = buf[start]; |
740 |
| -// if (ch == '-') { |
741 |
| -// return parseNegativeNumber(buf, reader, start, end); |
742 |
| -// } |
743 |
| -// return parsePositiveNumber(buf, reader, start, end); |
744 |
| -// } |
745 |
| -// |
746 |
| -// private static Number parsePositiveNumber(final byte[] buf, final JReader reader, final int start, final int end) throws IOException { |
747 |
| -// long value = 0; |
748 |
| -// byte ch = ' '; |
749 |
| -// int i = start; |
750 |
| -// final boolean leadingZero = buf[start] == 48; |
751 |
| -// for (; i < end; i++) { |
752 |
| -// ch = buf[i]; |
753 |
| -// if (ch == '.' || ch == 'e' || ch == 'E') break; |
754 |
| -// final int ind = ch - 48; |
755 |
| -// if (ind < 0 || ind > 9) { |
756 |
| -// if (leadingZero && i > start + 1) { |
757 |
| -// numberException(reader, start, end, "Leading zero is not allowed"); |
758 |
| -// } |
759 |
| -// if (i > start && reader.allWhitespace(i, end)) return value; |
760 |
| -// return tryLongFromBigDecimal(reader.prepareBuffer(start, end - start), end - start, reader); |
761 |
| -// } |
762 |
| -// value = (value << 3) + (value << 1) + ind; |
763 |
| -// } |
764 |
| -// if (i == start) numberException(reader, start, end, "Digit not found"); |
765 |
| -// else if (leadingZero && ch != '.' && i > start + 1) numberException(reader, start, end, "Leading zero is not allowed"); |
766 |
| -// else if (i == end) return value; |
767 |
| -// else if (ch == '.') { |
768 |
| -// i++; |
769 |
| -// if (i == end) numberException(reader, start, end, "Number ends with a dot"); |
770 |
| -// int dp = i; |
771 |
| -// for (; i < end; i++) { |
772 |
| -// ch = buf[i]; |
773 |
| -// if (ch == 'e' || ch == 'E') break; |
774 |
| -// final int ind = ch - 48; |
775 |
| -// if (ind < 0 || ind > 9) { |
776 |
| -// if (reader.allWhitespace(i, end)) return BigDecimal.valueOf(value, i - dp); |
777 |
| -// return tryLongFromBigDecimal(reader.prepareBuffer(start, end - start), end - start, reader); |
778 |
| -// } |
779 |
| -// value = (value << 3) + (value << 1) + ind; |
780 |
| -// } |
781 |
| -// if (i == end) return bigDecimalOrDouble(BigDecimal.valueOf(value, end - dp), reader.unknownNumbers); |
782 |
| -// else if (ch == 'e' || ch == 'E') { |
783 |
| -// final int ep = i; |
784 |
| -// i++; |
785 |
| -// ch = buf[i]; |
786 |
| -// final int exp; |
787 |
| -// if (ch == '-') { |
788 |
| -// exp = parseNegativeInt(buf, reader, i, end); |
789 |
| -// } else if (ch == '+') { |
790 |
| -// exp = parsePositiveInt(buf, reader, i, end, 1); |
791 |
| -// } else { |
792 |
| -// exp = parsePositiveInt(buf, reader, i, end, 0); |
793 |
| -// } |
794 |
| -// return bigDecimalOrDouble(BigDecimal.valueOf(value, ep - dp - exp), reader.unknownNumbers); |
795 |
| -// } |
796 |
| -// return BigDecimal.valueOf(value, end - dp); |
797 |
| -// } else if (ch == 'e' || ch == 'E') { |
798 |
| -// i++; |
799 |
| -// ch = buf[i]; |
800 |
| -// final int exp; |
801 |
| -// if (ch == '-') { |
802 |
| -// exp = parseNegativeInt(buf, reader, i, end); |
803 |
| -// } else if (ch == '+') { |
804 |
| -// exp = parsePositiveInt(buf, reader, i, end, 1); |
805 |
| -// } else { |
806 |
| -// exp = parsePositiveInt(buf, reader, i, end, 0); |
807 |
| -// } |
808 |
| -// return bigDecimalOrDouble(BigDecimal.valueOf(value, -exp), reader.unknownNumbers); |
809 |
| -// } |
810 |
| -// return bigDecimalOrDouble(BigDecimal.valueOf(value), reader.unknownNumbers); |
811 |
| -// } |
812 |
| -// |
813 |
| -// private static Number parseNegativeNumber(final byte[] buf, final JReader reader, final int start, final int end) throws IOException { |
814 |
| -// long value = 0; |
815 |
| -// byte ch = ' '; |
816 |
| -// int i = start + 1; |
817 |
| -// final boolean leadingZero = buf[start + 1] == 48; |
818 |
| -// for (; i < end; i++) { |
819 |
| -// ch = buf[i]; |
820 |
| -// if (ch == '.' || ch == 'e' || ch == 'E') break; |
821 |
| -// final int ind = ch - 48; |
822 |
| -// if (ind < 0 || ind > 9) { |
823 |
| -// if (leadingZero && i > start + 2) { |
824 |
| -// numberException(reader, start, end, "Leading zero is not allowed"); |
825 |
| -// } |
826 |
| -// if (i > start + 1 && reader.allWhitespace(i, end)) return value; |
827 |
| -// return tryLongFromBigDecimal(reader.prepareBuffer(start, end - start), end - start, reader); |
828 |
| -// } |
829 |
| -// value = (value << 3) + (value << 1) - ind; |
830 |
| -// } |
831 |
| -// if (i == start + 1) numberException(reader, start, end, "Digit not found"); |
832 |
| -// else if (leadingZero && ch != '.' && i > start + 2) numberException(reader, start, end, "Leading zero is not allowed"); |
833 |
| -// else if (i == end) return value; |
834 |
| -// else if (ch == '.') { |
835 |
| -// i++; |
836 |
| -// if (i == end) numberException(reader, start, end, "Number ends with a dot"); |
837 |
| -// int dp = i; |
838 |
| -// for (; i < end; i++) { |
839 |
| -// ch = buf[i]; |
840 |
| -// if (ch == 'e' || ch == 'E') break; |
841 |
| -// final int ind = ch - 48; |
842 |
| -// if (ind < 0 || ind > 9) { |
843 |
| -// if (reader.allWhitespace(i, end)) return BigDecimal.valueOf(value, i - dp); |
844 |
| -// return tryLongFromBigDecimal(reader.prepareBuffer(start, end - start), end - start, reader); |
845 |
| -// } |
846 |
| -// value = (value << 3) + (value << 1) - ind; |
847 |
| -// } |
848 |
| -// if (i == end) return bigDecimalOrDouble(BigDecimal.valueOf(value, end - dp), reader.unknownNumbers); |
849 |
| -// else if (ch == 'e' || ch == 'E') { |
850 |
| -// final int ep = i; |
851 |
| -// i++; |
852 |
| -// ch = buf[i]; |
853 |
| -// final int exp; |
854 |
| -// if (ch == '-') { |
855 |
| -// exp = parseNegativeInt(buf, reader, i, end); |
856 |
| -// } else if (ch == '+') { |
857 |
| -// exp = parsePositiveInt(buf, reader, i, end, 1); |
858 |
| -// } else { |
859 |
| -// exp = parsePositiveInt(buf, reader, i, end, 0); |
860 |
| -// } |
861 |
| -// return bigDecimalOrDouble(BigDecimal.valueOf(value, ep - dp - exp), reader.unknownNumbers); |
862 |
| -// } |
863 |
| -// return bigDecimalOrDouble(BigDecimal.valueOf(value, end - dp), reader.unknownNumbers); |
864 |
| -// } else if (ch == 'e' || ch == 'E') { |
865 |
| -// i++; |
866 |
| -// ch = buf[i]; |
867 |
| -// final int exp; |
868 |
| -// if (ch == '-') { |
869 |
| -// exp = parseNegativeInt(buf, reader, i, end); |
870 |
| -// } else if (ch == '+') { |
871 |
| -// exp = parsePositiveInt(buf, reader, i, end, 1); |
872 |
| -// } else { |
873 |
| -// exp = parsePositiveInt(buf, reader, i, end, 0); |
874 |
| -// } |
875 |
| -// return bigDecimalOrDouble(BigDecimal.valueOf(value, -exp), reader.unknownNumbers); |
876 |
| -// } |
877 |
| -// return bigDecimalOrDouble(BigDecimal.valueOf(value), reader.unknownNumbers); |
878 |
| -// } |
879 |
| - |
880 | 695 | }
|
0 commit comments