Paste: locale snprintf
Author: | Jon |
Mode: | factor |
Date: | Wed, 12 Aug 2015 22:25:38 |
Plain Text |
USING: alien.syntax alien.c-types byte-arrays math.parser.private locals ;
FUNCTION-ALIAS: mysnprintf-int int snprintf ;
FUNCTION-ALIAS: mysnprintf-float int snprintf ;
LIBRARY: libc
CONSTANT: LC_NUMERIC 1
FUNCTION: c-string setlocale ;
: with-locale
over f setlocale
[ drop setlocale drop call ] [ nip setlocale drop ] 3bi ; inline
:: my-int-format
[
100 dup <byte-array> [ swap "%'d" n mysnprintf-int drop ] keep
dup 0 swap index format-head
] LC_NUMERIC locale with-locale ;
1234123 "fr_FR.UTF-8" my-int-format print
1234123 "en_US.UTF-8" my-int-format print
Author: | Jon |
Mode: | factor |
Date: | Thu, 13 Aug 2015 21:09:58 |
Plain Text |
USING: alien.syntax alien.c-types byte-arrays math.parser.private locals ;
FUNCTION-ALIAS: mysnprintf-int int snprintf
FUNCTION-ALIAS: mysnprintf-float int snprintf
LIBRARY: libc
CONSTANT: LC_NUMERIC 1
FUNCTION: c-string setlocale
: with-locale
over f setlocale
[ drop setlocale drop call ] [ nip setlocale drop ] 3bi ; inline
:: my-int-format
[
100 dup <byte-array> [ swap "%'d" n mysnprintf-int drop ] keep
dup 0 swap index format-head
] LC_NUMERIC locale with-locale ;
1234123 "fr_FR.UTF-8" my-int-format print
1234123 "en_US.UTF-8" my-int-format print
New Annotation