[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: CSV parsing and other issues (Re: LC_NUMERIC)
From: |
Maxim Nikulin |
Subject: |
Re: CSV parsing and other issues (Re: LC_NUMERIC) |
Date: |
Fri, 11 Jun 2021 23:51:40 +0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 |
Eli, Boruch, you are overreacting (both).
On 11/06/2021 13:19, Eli Zaretskii wrote:
There's no need to
introduce into Emacs features that are useful for a few people.
I think that expectation of users and developers in respect to support
of locales evolves in time. Proper formatting of numbers is useful more
widely then for a few people.
Boruch, till your last messages, I believed that you were convinced that
adding support of "'" and "I" is not so easy.
Support of locale-dependent format specifiers through printf looks
attractive but it can not be directly used by `format' or other elisp
functions in a safe way.
Some code calling `format' implicitly expects that it generates
locale-independent numbers, so changing its behavior is not backward
compatible.
libc can only work with single global locale at any moment. I expect
that attempt to "temporary" call setlocale(LC_NUMERIC, "") will be
permanent source of bugs: forgotten reverting call, call of a function
that needs universal format in locale-specific context, threads started
at inappropriate moment, etc.
Another implementation of locale functions is necessary with ability to
perform parsing and formatting without touching of global variables.
Personally I expect basic level functions with explicit locale context
(random names):
(locale-format-number-with-ctx
(locale-get-current-context :group-separator 'suppress)
1234567890)
or with explicit locale instead of `locale-get-current-context'. It is
better to add some convenience helpers that inspect text properties,
buffer-local and global settings to determine context:
(locale-format-number 1234567890)
and maybe even `locale-format[-with-ctx]' that accepts printf-like
format string.
On 11/06/2021 03:20, Boruch Baum wrote:
> Then don't make them locale specific. Implement the
> single-quote specifier the same way you currently handle the
> floating-point specifier '%f', a locale-specific format that
> has existed in emacs without complaint since ...
You are confusing something. "%f" is not locale-specific inside Emacs,
it uses "universal" format with dot "." as decimal separator even in
locales with "," in this role. At the same time "'" is highly
locale-dependent in libc. Group sizes and group separator widely
vary. I posted this example earlier:
LC_NUMERIC=C.UTF-8 /usr/bin/printf "%'d\n" 1234567890
1234567890
LC_NUMERIC=en_US.UTF-8 /usr/bin/printf "%'d\n" 1234567890
1,234,567,890
LC_NUMERIC=es_ES.UTF-8 /usr/bin/printf "%'d\n" 1234567890
1.234.567.890
LC_NUMERIC=ru_RU.UTF-8 /usr/bin/printf "%'d\n" 1234567890
1 234 567 890
LC_NUMERIC=en_IN.UTF-8 /usr/bin/printf "%'d\n" 1234567890
1,23,45,67,890
> It's not your responsibilty.
>
> I can say that in the use-case that prompted my request, I'm
> confident it will *never* be an issue. I ask format to give
> me a string and I display it. End of story. Whether just 99%
> or 99.99%, the overwhelming majority of cases will be the
> same. Your concerns are total non-issues.
I would prefer to avoid idiosyncrasy when "%'d" is locale-dependent but
"%f" is not.
P.S.
With some limitation (printf binary is available and you do not need to
work with floating point numbers), you can leverage libc formatting
facilities with the following crutch:
(shell-command-to-string (format "/usr/bin/printf \"%%'d\" %d"
1234567890))
- Re: CSV parsing and other issues (Re: LC_NUMERIC), (continued)
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Eli Zaretskii, 2021/06/08
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Maxim Nikulin, 2021/06/10
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Eli Zaretskii, 2021/06/10
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Boruch Baum, 2021/06/10
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Eli Zaretskii, 2021/06/10
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Boruch Baum, 2021/06/10
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Eli Zaretskii, 2021/06/10
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Boruch Baum, 2021/06/10
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Eli Zaretskii, 2021/06/11
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Boruch Baum, 2021/06/11
- Re: CSV parsing and other issues (Re: LC_NUMERIC),
Maxim Nikulin <=
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Filipp Gunbin, 2021/06/11
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Eli Zaretskii, 2021/06/11
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Filipp Gunbin, 2021/06/11
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Eli Zaretskii, 2021/06/11
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Maxim Nikulin, 2021/06/11
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Eli Zaretskii, 2021/06/11
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Maxim Nikulin, 2021/06/14
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Eli Zaretskii, 2021/06/14
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Maxim Nikulin, 2021/06/16
- Re: CSV parsing and other issues (Re: LC_NUMERIC), Eli Zaretskii, 2021/06/16