int i;
int n;
int rv;
- char lc_numeric[128];
- const char * comma_locales[] = { "da_DK.UTF-8", "fr_FR.UTF-8", "ru_RU.UTF-8"};
+
+ const char * comma_locales[] = { "da_DK.UTF-8",
+ "fr_FR.UTF-8",
+ "ru_RU.UTF-8"};
const testFunc tests[] = { test_elements,
test_utf8,
test_unescape };
/* run the tests in a locale with a decimal point of '.' */
- tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
setlocale (LC_NUMERIC, "C");
if ((rv = runTests (tests, NUM_TESTS (tests))))
return rv;
fprintf (stderr, "WARNING: unable to run locale-specific json tests.\n");
else if ((rv = runTests (tests, NUM_TESTS(tests))))
return rv;
- setlocale (LC_NUMERIC, lc_numeric);
/* success */
return 0;
{
int stackSize = 0;
int stackAlloc = 64;
- char lc_numeric[128];
struct SaveNode * stack = tr_new (struct SaveNode, stackAlloc);
- /* always use a '.' decimal point s.t. locale-hopping doesn't bite us */
- tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
- setlocale (LC_NUMERIC, "C");
-
nodeConstruct (&stack[stackSize++], v, sort_dicts);
while (stackSize > 0)
}
}
- /* restore the locale... */
- setlocale (LC_NUMERIC, lc_numeric);
-
tr_free (stack);
}
struct evbuffer *
tr_variantToBuf (const tr_variant * v, tr_variant_fmt fmt)
{
+ char lc_numeric[128];
struct evbuffer * buf = evbuffer_new();
+ /* parse with LC_NUMERIC="C" to ensure a "." decimal separator */
+ tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
+ setlocale (LC_NUMERIC, "C");
+
evbuffer_expand (buf, 4096); /* alloc a little memory to start off with */
switch (fmt)
break;
}
+ /* restore the previous locale */
+ setlocale (LC_NUMERIC, lc_numeric);
return buf;
}
const char ** setme_end)
{
int err;
+ char lc_numeric[128];
+
+ /* parse with LC_NUMERIC="C" to ensure a "." decimal separator */
+ tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
+ setlocale (LC_NUMERIC, "C");
switch (fmt)
{
break;
}
+ /* restore the previous locale */
+ setlocale (LC_NUMERIC, lc_numeric);
return err;
}