From: drh Date: Mon, 5 Jun 2017 12:29:26 +0000 (+0000) Subject: Fix the column width deduction logic in the command-line shell to account X-Git-Tag: version-3.20.0~214 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=64bf76d2b2eaa5c6e37a9c1ae67d3afbdf78e1e4;p=thirdparty%2Fsqlite.git Fix the column width deduction logic in the command-line shell to account for multi-byte utf8 characters. FossilOrigin-Name: ed0842c156ab1a78d5d00d3a55dab5e3f08cd349328d606724688f1528df3f6b --- diff --git a/manifest b/manifest index fa86dc3059..0513f7b6e6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Omit\ssome\sof\sthe\sfstree\stests\sin\svtabH\sif\sthe\sPWD\scontains\sLIKE\swildcards. -D 2017-06-05T10:31:03.284 +C Fix\sthe\scolumn\swidth\sdeduction\slogic\sin\sthe\scommand-line\sshell\sto\saccount\nfor\smulti-byte\sutf8\scharacters. +D 2017-06-05T12:29:26.935 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 8eeb80162074004e906b53d7340a12a14c471a83743aab975947e95ce061efcc @@ -406,7 +406,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c adf3ef9843135b1383321ad751f16f5a40c3f37925154555a3e61653d2a954e8 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c d93205e43af302d9eb147fddecc956509ee9d0dde6297ee3f93c591f60f0e295 -F src/shell.c 3f761fe604174b31aacd2ea2eacef5e6fe550111d60c0d71532cc008c68cf3f3 +F src/shell.c eca7e7fe8dae859aa56e462c5b35c735976fa1e5e1d7a90fd5a32aa4615c1825 F src/sqlite.h.in ad7f4101e3613b1134d1ad6c61ff385424ffac0d542627fd31f26667fdd91c94 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 58fd0676d3111d02e62e5a35992a7d3da5d3f88753acc174f2d37b774fbbdd28 @@ -1582,7 +1582,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 65182ce041b30cd0193b958eca975b720fe5200a868baba1e633e49433d86813 -R 2c9842dfb62b82356e8a96cc9ba71901 +P ead29f9cb757a5f9921086e3bb4998f60e0d6cfcf41ef0f9a230b365b6226947 +R a0798b817cd3131e3fcd85873638461d U drh -Z 6bfb0810488624ef037a9b068fe5d2de +Z 989f90c118a47ae7c1914060875ac3d8 diff --git a/manifest.uuid b/manifest.uuid index de082373de..eda3a2f91c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ead29f9cb757a5f9921086e3bb4998f60e0d6cfcf41ef0f9a230b365b6226947 \ No newline at end of file +ed0842c156ab1a78d5d00d3a55dab5e3f08cd349328d606724688f1528df3f6b \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 322c6e5c4f..6a436da488 100644 --- a/src/shell.c +++ b/src/shell.c @@ -509,6 +509,18 @@ static int strlen30(const char *z){ return 0x3fffffff & (int)(z2 - z); } +/* +** Return the length of a string in characters. Multibyte UTF8 characters +** count as a single character. +*/ +static int strlenChar(const char *z){ + int n = 0; + while( *z ){ + if( (0xc0&*(z++))!=0x80 ) n++; + } + return n; +} + /* ** This routine reads a line of text from FILE in, stores ** the text in memory obtained from malloc() and returns a pointer @@ -1917,9 +1929,9 @@ static int shell_callback( w = 0; } if( w==0 ){ - w = strlen30(azCol[i] ? azCol[i] : ""); + w = strlenChar(azCol[i] ? azCol[i] : ""); if( w<10 ) w = 10; - n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullValue); + n = strlenChar(azArg && azArg[i] ? azArg[i] : p->nullValue); if( wactualWidth) ){ @@ -1954,8 +1966,8 @@ static int shell_callback( }else{ w = 10; } - if( p->cMode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){ - w = strlen30(azArg[i]); + if( p->cMode==MODE_Explain && azArg[i] && strlenChar(azArg[i])>w ){ + w = strlenChar(azArg[i]); } if( i==1 && p->aiIndent && p->pStmt ){ if( p->iIndentnIndent ){