int tr_variantFromBuf(tr_variant* setme, tr_variant_fmt fmt, void const* buf, size_t buflen, char const* optional_source,
    char const** setme_end)
{
    int err;
    struct locale_context locale_ctx;

    /* parse with LC_NUMERIC="C" to ensure a "." decimal separator */
    use_numeric_locale(&locale_ctx, "C");

    switch (fmt)
    {
    case TR_VARIANT_FMT_JSON:
    case TR_VARIANT_FMT_JSON_LEAN:
        err = tr_jsonParse(optional_source, buf, buflen, setme, setme_end);
        break;

    default /* TR_VARIANT_FMT_BENC */:
        err = tr_variantParseBenc(buf, (char const*)buf + buflen, setme, setme_end);
        break;
    }

    /* restore the previous locale */
    restore_locale(&locale_ctx);
    return err;
}
int tr_variantFromBuf(tr_variant* setme, tr_variant_fmt fmt, void const* buf, size_t buflen, char const* optional_source,
    char const** setme_end)
{
    int err;
    struct locale_context locale_ctx;

     
    use_numeric_locale(&locale_ctx, "C");

    switch (fmt)
    {
    case TR_VARIANT_FMT_JSON:
    case TR_VARIANT_FMT_JSON_LEAN:
        err = tr_jsonParse(optional_source, buf, buflen, setme, setme_end);
        break;

    default  :
        err = tr_variantParseBenc(buf, (char const*)buf + buflen, setme, setme_end);
        break;
    }

     
    restore_locale(&locale_ctx);
    return err;
}