-/*
- * Lookup tables that converts from a decimal character value to an integral
- * binary value, shifted by a decimal "shift" multiplier.
- * For all character values in the range '0'..'9', the table at those
- * index locations returns the actual decimal value shifted by the multiplier.
- * For all other values, the lookup table returns an invalid OOR value.
- */
-// Out-of-range flag value, larger than the largest value that can fit in
-// four decimal bytes (9999), but four of these added up together should
-// still not overflow uint16_t.
-constexpr int32_t OOR = 10000;
-
-__attribute__((aligned(16))) constexpr uint16_t shift1[] = {
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 0-9
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 10
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 20
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 30
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, 0, // 40
- 1, 2, 3, 4, 5, 6, 7, 8, 9, OOR, OOR,
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 60
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 70
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 80
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 90
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 100
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 110
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 120
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 130
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 140
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 150
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 160
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 170
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 180
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 190
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 200
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 210
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 220
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 230
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 240
- OOR, OOR, OOR, OOR, OOR, OOR // 250
-};
-
-__attribute__((aligned(16))) constexpr uint16_t shift10[] = {
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 0-9
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 10
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 20
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 30
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, 0, // 40
- 10, 20, 30, 40, 50, 60, 70, 80, 90, OOR, OOR,
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 60
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 70
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 80
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 90
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 100
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 110
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 120
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 130
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 140
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 150
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 160
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 170
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 180
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 190
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 200
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 210
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 220
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 230
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 240
- OOR, OOR, OOR, OOR, OOR, OOR // 250
-};
-
-__attribute__((aligned(16))) constexpr uint16_t shift100[] = {
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 0-9
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 10
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 20
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 30
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, 0, // 40
- 100, 200, 300, 400, 500, 600, 700, 800, 900, OOR, OOR,
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 60
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 70
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 80
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 90
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 100
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 110
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 120
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 130
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 140
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 150
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 160
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 170
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 180
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 190
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 200
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 210
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 220
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 230
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 240
- OOR, OOR, OOR, OOR, OOR, OOR // 250
-};
-
-__attribute__((aligned(16))) constexpr uint16_t shift1000[] = {
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 0-9
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 10
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 20
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 30
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, 0, // 40
- 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, OOR, OOR,
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 60
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 70
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 80
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 90
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 100
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 110
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 120
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 130
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 140
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 150
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 160
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 170
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 180
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 190
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 200
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 210
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 220
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 230
- OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, OOR, // 240
- OOR, OOR, OOR, OOR, OOR, OOR // 250
-};
-
-/**
- * String represented as a pair of pointers to char to unsigned
- * integrals. Assumes NO whitespace before or after, and also that the
- * string is composed entirely of digits. Tgt must be unsigned, and no
- * sign is allowed in the string (even it's '+'). String may be empty,
- * in which case digits_to throws.
- */
- template <class Tgt>
- Tgt digits_to(const char * b, const char * e) {
-
- static_assert(!std::is_signed<Tgt>::value, "Unsigned type expected");
- assert(b <= e);
-
- const size_t size = e - b;
-
- /* Although the string is entirely made of digits, we still need to
- * check for overflow.
- */
- if (size >= std::numeric_limits<Tgt>::digits10 + 1) {
- // Leading zeros? If so, recurse to keep things simple
- if (b < e && *b == '0') {
- for (++b;; ++b) {
- if (b == e) return 0; // just zeros, e.g. "0000"
- if (*b != '0') return digits_to<Tgt>(b, e);
- }
- }
- FOLLY_RANGE_CHECK(size == std::numeric_limits<Tgt>::digits10 + 1 &&
- strncmp(b, detail::MaxString<Tgt>::value, size) <= 0,
- "Numeric overflow upon conversion");
- }
-
- // Here we know that the number won't overflow when
- // converted. Proceed without checks.