The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
MODULE = CPP::panda::lib                PACKAGE = CPP::panda::lib::Test
PROTOTYPES: DISABLE

SV* from_chars_i8 (string_view str, SV* pos, int base = 10) : ALIAS(from_chars_i16=1, from_chars_i32=2, from_chars_i64=3, from_chars_u8=4, from_chars_u16=5, from_chars_u32=6, from_chars_u64=7) {
    const char* ptr = str.data();
    const char* end = ptr + str.length();
    std::from_chars_result res;
    RETVAL = 0;
    switch (ix) {
        case 0: int8_t   tmp1; res = std::from_chars(ptr, end, tmp1, base); RETVAL = newSViv(tmp1); break;
        case 1: int16_t  tmp2; res = std::from_chars(ptr, end, tmp2, base); RETVAL = newSViv(tmp2); break;
        case 2: int32_t  tmp3; res = std::from_chars(ptr, end, tmp3, base); RETVAL = newSViv(tmp3); break;
        case 3: int64_t  tmp4; res = std::from_chars(ptr, end, tmp4, base); RETVAL = newSViv(tmp4); break;
        case 4: uint8_t  tmp5; res = std::from_chars(ptr, end, tmp5, base); RETVAL = newSVuv(tmp5); break;
        case 5: uint16_t tmp6; res = std::from_chars(ptr, end, tmp6, base); RETVAL = newSVuv(tmp6); break;
        case 6: uint32_t tmp7; res = std::from_chars(ptr, end, tmp7, base); RETVAL = newSVuv(tmp7); break;
        case 7: uint64_t tmp8; res = std::from_chars(ptr, end, tmp8, base); RETVAL = newSVuv(tmp8); break;
        default: croak("SHOULD NOT HAPPEN");
    }
    sv_setuv(pos, res.ptr - str.data());
    if (res.ec) XSRETURN_UNDEF;
}

pandaString to_chars_i8 (int64_t val, int base = 10, size_t buflen = 0) : ALIAS(to_chars_i16=1, to_chars_i32=2, to_chars_i64=3, to_chars_u8=4, to_chars_u16=5, to_chars_u32=6, to_chars_u64=7) {
    auto maxsize = buflen ? buflen : 100;
    char* buf = RETVAL.reserve(maxsize);
    char* bufend = buf + maxsize;
    std::to_chars_result res;
    switch (ix) {
        case 0: res = std::to_chars(buf, bufend, (int8_t)val,   base); break;
        case 1: res = std::to_chars(buf, bufend, (int16_t)val,  base); break;
        case 2: res = std::to_chars(buf, bufend, (int32_t)val,  base); break;
        case 3: res = std::to_chars(buf, bufend, (int64_t)val,  base); break;
        case 4: res = std::to_chars(buf, bufend, (uint8_t)val,  base); break;
        case 5: res = std::to_chars(buf, bufend, (uint16_t)val, base); break;
        case 6: res = std::to_chars(buf, bufend, (uint32_t)val, base); break;
        case 7: res = std::to_chars(buf, bufend, (uint64_t)val, base); break;
    }
    if (res.ec) XSRETURN_UNDEF;
    RETVAL.length(res.ptr - buf);
}