Changeset 13678


Ignore:
Timestamp:
Dec 17, 2012, 2:43:17 AM (10 years ago)
Author:
jordan
Message:

(trunk libT) when seraializing to JSON, set the LC_NUMERIC locale once for the entire serialization pass, instead of N times

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/variant-json.c

    r13675 r13678  
    492492{
    493493  struct jsonWalk * data = vdata;
    494   char locale[128];
    495494
    496495  if (fabs (val->val.d - (int)val->val.d) < 0.00001)
    497     {
    498       evbuffer_add_printf (data->out, "%d", (int)val->val.d);
    499     }
     496    evbuffer_add_printf (data->out, "%d", (int)val->val.d);
    500497  else
    501     {
    502       /* json requires a '.' decimal point regardless of locale */
    503       tr_strlcpy (locale, setlocale (LC_NUMERIC, NULL), sizeof (locale));
    504       setlocale (LC_NUMERIC, "POSIX");
    505       evbuffer_add_printf (data->out, "%.4f", tr_truncd (val->val.d, 4));
    506       setlocale (LC_NUMERIC, locale);
    507     }
     498    evbuffer_add_printf (data->out, "%.4f", tr_truncd (val->val.d, 4));
    508499
    509500  jsonChildFunc (data);
     
    630621tr_variantToBufJson (const tr_variant * top, struct evbuffer * buf, bool lean)
    631622{
     623  char lc_numeric[128];
    632624  struct jsonWalk data;
     625
    633626  data.doIndent = !lean;
    634627  data.out = buf;
    635628  data.parents = NULL;
     629
     630  /* json requires a '.' decimal point regardless of locale */
     631  tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
     632  setlocale (LC_NUMERIC, "POSIX");
    636633  tr_variantWalk (top, &walk_funcs, &data, true);
     634  setlocale (LC_NUMERIC, lc_numeric);
     635
    637636  if (evbuffer_get_length (buf))
    638637    evbuffer_add_printf (buf, "\n");
Note: See TracChangeset for help on using the changeset viewer.