Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1ed7f0e

Browse files
committed
Fix indentation of \d footers for non-ASCII cases.
Multi-line "Inherits:" and "Child tables:" footers were misindented whenthose strings' translations involved multibyte characters, because we wereusing 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 about8.2, but fortunately has been unused for the same length of time.Report and patch by Sergey Burladyan (bug #6480)
1 parent9088d1b commit1ed7f0e

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

‎src/bin/psql/describe.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,22 +2156,28 @@ describeOneTableDetails(const char *schemaname,
21562156
if (!result)
21572157
gotoerror_return;
21582158
else
2159-
tuples=PQntuples(result);
2160-
2161-
for (i=0;i<tuples;i++)
21622159
{
21632160
constchar*s=_("Inherits");
2161+
intsw=pg_wcswidth(s,strlen(s),pset.encoding);
21642162

2165-
if (i==0)
2166-
printfPQExpBuffer(&buf,"%s: %s",s,PQgetvalue(result,i,0));
2167-
else
2168-
printfPQExpBuffer(&buf,"%*s %s", (int)strlen(s),"",PQgetvalue(result,i,0));
2169-
if (i<tuples-1)
2170-
appendPQExpBuffer(&buf,",");
2163+
tuples=PQntuples(result);
21712164

2172-
printTableAddFooter(&cont,buf.data);
2165+
for (i=0;i<tuples;i++)
2166+
{
2167+
if (i==0)
2168+
printfPQExpBuffer(&buf,"%s: %s",
2169+
s,PQgetvalue(result,i,0));
2170+
else
2171+
printfPQExpBuffer(&buf,"%*s %s",
2172+
sw,"",PQgetvalue(result,i,0));
2173+
if (i<tuples-1)
2174+
appendPQExpBuffer(&buf,",");
2175+
2176+
printTableAddFooter(&cont,buf.data);
2177+
}
2178+
2179+
PQclear(result);
21732180
}
2174-
PQclear(result);
21752181

21762182
/* print child tables */
21772183
if (pset.sversion >=80300)
@@ -2198,6 +2204,7 @@ describeOneTableDetails(const char *schemaname,
21982204
{
21992205
/* display the list of child tables */
22002206
constchar*ct=_("Child tables");
2207+
intctw=pg_wcswidth(ct,strlen(ct),pset.encoding);
22012208

22022209
for (i=0;i<tuples;i++)
22032210
{
@@ -2206,8 +2213,7 @@ describeOneTableDetails(const char *schemaname,
22062213
ct,PQgetvalue(result,i,0));
22072214
else
22082215
printfPQExpBuffer(&buf,"%*s %s",
2209-
(int)strlen(ct),"",
2210-
PQgetvalue(result,i,0));
2216+
ctw,"",PQgetvalue(result,i,0));
22112217
if (i<tuples-1)
22122218
appendPQExpBuffer(&buf,",");
22132219

‎src/bin/psql/mbprint.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,12 @@ mb_utf_validate(unsigned char *pwcs)
168168
*/
169169

170170
/*
171-
* pg_wcswidth is the dumb width function. It assumes that everything will
172-
* only appear on one line. OTOH it is easier to use if this applies to you.
171+
* pg_wcswidth is the dumb display-width function.
172+
* It assumes that everything will appear on one line.
173+
* OTOH it is easier to use than pg_wcssize if this applies to you.
173174
*/
174175
int
175-
pg_wcswidth(constunsignedchar*pwcs,size_tlen,intencoding)
176+
pg_wcswidth(constchar*pwcs,size_tlen,intencoding)
176177
{
177178
intwidth=0;
178179

@@ -181,15 +182,16 @@ pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding)
181182
intchlen,
182183
chwidth;
183184

184-
chlen=PQmblen((constchar*)pwcs,encoding);
185-
if (chlen>len)
185+
chlen=PQmblen(pwcs,encoding);
186+
if (len< (size_t)chlen)
186187
break;/* Invalid string */
187188

188-
chwidth=PQdsplen((constchar*)pwcs,encoding);
189-
189+
chwidth=PQdsplen(pwcs,encoding);
190190
if (chwidth>0)
191191
width+=chwidth;
192+
192193
pwcs+=chlen;
194+
len-=chlen;
193195
}
194196
returnwidth;
195197
}

‎src/bin/psql/mbprint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct lineptr
1010
};
1111

1212
externunsignedchar*mbvalidate(unsignedchar*pwcs,intencoding);
13-
externintpg_wcswidth(constunsignedchar*pwcs,size_tlen,intencoding);
13+
externintpg_wcswidth(constchar*pwcs,size_tlen,intencoding);
1414
externvoidpg_wcsformat(constunsignedchar*pwcs,size_tlen,intencoding,structlineptr*lines,intcount);
1515
externvoidpg_wcssize(constunsignedchar*pwcs,size_tlen,intencoding,
1616
int*width,int*height,int*format_size);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp