mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
Fix indentation of \d footers for non-ASCII cases.
Multi-line "Inherits:" and "Child tables:" footers were misindented when those strings' translations involved multibyte characters, because we were using strlen() instead of an appropriate display width measurement. In passing, avoid doing gettext() more than once per loop in these places. While at it, fix pg_wcswidth(), which has been entirely broken since about 8.2, but fortunately has been unused for the same length of time. Report and patch by Sergey Burladyan (bug #6480)
This commit is contained in:
parent
9088d1b965
commit
1ed7f0e6b9
@ -2156,22 +2156,28 @@ describeOneTableDetails(const char *schemaname,
|
|||||||
if (!result)
|
if (!result)
|
||||||
goto error_return;
|
goto error_return;
|
||||||
else
|
else
|
||||||
tuples = PQntuples(result);
|
|
||||||
|
|
||||||
for (i = 0; i < tuples; i++)
|
|
||||||
{
|
{
|
||||||
const char *s = _("Inherits");
|
const char *s = _("Inherits");
|
||||||
|
int sw = pg_wcswidth(s, strlen(s), pset.encoding);
|
||||||
|
|
||||||
if (i == 0)
|
tuples = PQntuples(result);
|
||||||
printfPQExpBuffer(&buf, "%s: %s", s, PQgetvalue(result, i, 0));
|
|
||||||
else
|
|
||||||
printfPQExpBuffer(&buf, "%*s %s", (int) strlen(s), "", PQgetvalue(result, i, 0));
|
|
||||||
if (i < tuples - 1)
|
|
||||||
appendPQExpBuffer(&buf, ",");
|
|
||||||
|
|
||||||
printTableAddFooter(&cont, buf.data);
|
for (i = 0; i < tuples; i++)
|
||||||
|
{
|
||||||
|
if (i == 0)
|
||||||
|
printfPQExpBuffer(&buf, "%s: %s",
|
||||||
|
s, PQgetvalue(result, i, 0));
|
||||||
|
else
|
||||||
|
printfPQExpBuffer(&buf, "%*s %s",
|
||||||
|
sw, "", PQgetvalue(result, i, 0));
|
||||||
|
if (i < tuples - 1)
|
||||||
|
appendPQExpBuffer(&buf, ",");
|
||||||
|
|
||||||
|
printTableAddFooter(&cont, buf.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
PQclear(result);
|
||||||
}
|
}
|
||||||
PQclear(result);
|
|
||||||
|
|
||||||
/* print child tables */
|
/* print child tables */
|
||||||
if (pset.sversion >= 80300)
|
if (pset.sversion >= 80300)
|
||||||
@ -2198,6 +2204,7 @@ describeOneTableDetails(const char *schemaname,
|
|||||||
{
|
{
|
||||||
/* display the list of child tables */
|
/* display the list of child tables */
|
||||||
const char *ct = _("Child tables");
|
const char *ct = _("Child tables");
|
||||||
|
int ctw = pg_wcswidth(ct, strlen(ct), pset.encoding);
|
||||||
|
|
||||||
for (i = 0; i < tuples; i++)
|
for (i = 0; i < tuples; i++)
|
||||||
{
|
{
|
||||||
@ -2206,8 +2213,7 @@ describeOneTableDetails(const char *schemaname,
|
|||||||
ct, PQgetvalue(result, i, 0));
|
ct, PQgetvalue(result, i, 0));
|
||||||
else
|
else
|
||||||
printfPQExpBuffer(&buf, "%*s %s",
|
printfPQExpBuffer(&buf, "%*s %s",
|
||||||
(int) strlen(ct), "",
|
ctw, "", PQgetvalue(result, i, 0));
|
||||||
PQgetvalue(result, i, 0));
|
|
||||||
if (i < tuples - 1)
|
if (i < tuples - 1)
|
||||||
appendPQExpBuffer(&buf, ",");
|
appendPQExpBuffer(&buf, ",");
|
||||||
|
|
||||||
|
@ -168,11 +168,12 @@ mb_utf_validate(unsigned char *pwcs)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* pg_wcswidth is the dumb width function. It assumes that everything will
|
* pg_wcswidth is the dumb display-width function.
|
||||||
* only appear on one line. OTOH it is easier to use if this applies to you.
|
* It assumes that everything will appear on one line.
|
||||||
|
* OTOH it is easier to use than pg_wcssize if this applies to you.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding)
|
pg_wcswidth(const char *pwcs, size_t len, int encoding)
|
||||||
{
|
{
|
||||||
int width = 0;
|
int width = 0;
|
||||||
|
|
||||||
@ -181,15 +182,16 @@ pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding)
|
|||||||
int chlen,
|
int chlen,
|
||||||
chwidth;
|
chwidth;
|
||||||
|
|
||||||
chlen = PQmblen((const char *) pwcs, encoding);
|
chlen = PQmblen(pwcs, encoding);
|
||||||
if (chlen > len)
|
if (len < (size_t) chlen)
|
||||||
break; /* Invalid string */
|
break; /* Invalid string */
|
||||||
|
|
||||||
chwidth = PQdsplen((const char *) pwcs, encoding);
|
chwidth = PQdsplen(pwcs, encoding);
|
||||||
|
|
||||||
if (chwidth > 0)
|
if (chwidth > 0)
|
||||||
width += chwidth;
|
width += chwidth;
|
||||||
|
|
||||||
pwcs += chlen;
|
pwcs += chlen;
|
||||||
|
len -= chlen;
|
||||||
}
|
}
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ struct lineptr
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding);
|
extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding);
|
||||||
extern int pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding);
|
extern int pg_wcswidth(const char *pwcs, size_t len, int encoding);
|
||||||
extern void pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count);
|
extern void pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count);
|
||||||
extern void pg_wcssize(const unsigned char *pwcs, size_t len, int encoding,
|
extern void pg_wcssize(const unsigned char *pwcs, size_t len, int encoding,
|
||||||
int *width, int *height, int *format_size);
|
int *width, int *height, int *format_size);
|
||||||
|
Loading…
Reference in New Issue
Block a user