[GRASS-dev] Re: [GRASS GIS] #745: r.report formatting doesn't seem
to be multi-byte aware
GRASS GIS
trac at osgeo.org
Thu Sep 9 20:03:56 EDT 2010
#745: r.report formatting doesn't seem to be multi-byte aware
-------------------------+--------------------------------------------------
Reporter: peifer | Owner: grass-dev@…
Type: defect | Status: new
Priority: minor | Milestone: 6.4.1
Component: Raster | Version: 6.4.0 RCs
Keywords: | Platform: Linux
Cpu: Unspecified |
-------------------------+--------------------------------------------------
Comment(by glynn):
Replying to [ticket:745 peifer]:
The same issue applies to anything which attempts to format output
containing user-supplied text (hard-coded text should all be ASCII).
The main problem with fixing this is that the necessary functions aren't
available on all systems, so we will need either wrapper functions or a
lot of #ifdef's.
An outline approach is to convert the string from multi-byte to wide with
mbstowcs() or mbsrtowcs(), then either use wcslen() to find the number of
characters in the wide string, or use wcswidth() to find the width (in
columns) of the wide string.
wcswidth() correctly handles the "full-width" characters found in CJK
locales, which occupy two columns. However, wcswidth() is POSIX while
wcslen() is C99. None of the necessary functions are in C89.
Also, this rules out relying upon printf() etc for formatting, as printf's
width specifiers are in "char"s (i.e. bytes), not characters or columns.
BTW, regarding gawk/mawk: as the ticket notes, POSIX explicitly states
that awk matches the behaviour of printf, i.e. field widths are in bytes,
not characters/columns.
--
Ticket URL: <https://trac.osgeo.org/grass/ticket/745#comment:3>
GRASS GIS <http://grass.osgeo.org>
More information about the grass-dev
mailing list