From: drh Date: Mon, 19 Feb 2018 18:03:10 +0000 (+0000) Subject: Make the alternate-form-2 flag ("!") change the meaning of width and precision X-Git-Tag: version-3.23.0~117^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=57e3ba7623c1d819399f779e83372fea1727b9bf;p=thirdparty%2Fsqlite.git Make the alternate-form-2 flag ("!") change the meaning of width and precision from bytes to characters for the %q, %Q, and %w extensions of printf(). FossilOrigin-Name: 391540acbea34eb88c75b1152b458d8936b3fdfff47633b9ec897775b015ba4c --- diff --git a/manifest b/manifest index 51334ef416..867a07179e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\sprintf()\slibrary,\smeasure\swidth\sand\sprecision\sin\scharacters\srather\nthan\sbytes\sif\sthe\s"!"\s(alternate-form-2)\sflag\sis\spresent\son\sa\s%s\sor\s%z\nsubstitution. -D 2018-02-19T17:03:23.575 +C Make\sthe\salternate-form-2\sflag\s("!")\schange\sthe\smeaning\sof\swidth\sand\sprecision\nfrom\sbytes\sto\scharacters\sfor\sthe\s%q,\s%Q,\sand\s%w\sextensions\sof\sprintf(). +D 2018-02-19T18:03:10.959 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7a3f714b4fcf793108042b7b0a5c720b0b310ec84314d61ba7f3f49f27e550ea @@ -484,7 +484,7 @@ F src/pcache1.c 716975564c15eb6679e97f734cec1bfd6c16ac3d4010f05f1f8e509fc7d19880 F src/pragma.c bea56df3ae0637768c0da4fbbb8f2492f780980d95000034a105ff291bf7ca69 F src/pragma.h bb83728944b42f6d409c77f5838a8edbdb0fe83046c5496ffc9602b40340a324 F src/prepare.c 259f4e7960c47082c9653f3d5f0c294abd68bb9c3aab86de7630700cba1c20fb -F src/printf.c a94897345b3228d97c6aa06297890b7c62bc47acc86e34d3634d125426d78695 +F src/printf.c ab91b63394bf07a430af0c644f8e42ca136c015e2533544f585dab8b0a408b84 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c bbee7e31d369a18a2f4836644769882e9c5d40ef4a3af911db06410b65cb3730 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac @@ -1707,10 +1707,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 38f654dc117bb11d61407327884b5c913cfaf920547bebc4ce5a4cf983e5c20e -R 07cd50bae7c4080dd411c728ce9cf3a0 -T *branch * printf-enhancement -T *sym-printf-enhancement * -T -sym-trunk * +P ca31c6630422fca70e626dd38aae96296bd8535d491ca52391624a5e7e663636 +R d4aa6a8346f9339a7533b828b4137a72 U drh -Z 9d6ee38fe0b61a32cc5a7309de027572 +Z bc6f530d4e962e8540ac43cd25813033 diff --git a/manifest.uuid b/manifest.uuid index 29c0e9958e..50989e81be 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ca31c6630422fca70e626dd38aae96296bd8535d491ca52391624a5e7e663636 \ No newline at end of file +391540acbea34eb88c75b1152b458d8936b3fdfff47633b9ec897775b015ba4c \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index f6980c90db..ff948ff5a4 100644 --- a/src/printf.c +++ b/src/printf.c @@ -668,15 +668,16 @@ void sqlite3VXPrintf( }else{ length = 0x7fffffff & (int)strlen(bufpt); } + adjust_width_for_utf8: if( flag_altform2 && width>0 ){ /* Adjust width to account for extra bytes in UTF-8 characters */ int ii = length - 1; while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++; } break; - case etSQLESCAPE: /* Escape ' characters */ - case etSQLESCAPE2: /* Escape ' and enclose in '...' */ - case etSQLESCAPE3: { /* Escape " characters */ + case etSQLESCAPE: /* %q: Escape ' characters */ + case etSQLESCAPE2: /* %Q: Escape ' and enclose in '...' */ + case etSQLESCAPE3: { /* %w: Escape " characters */ int i, j, k, n, isnull; int needQuote; char ch; @@ -690,9 +691,17 @@ void sqlite3VXPrintf( } isnull = escarg==0; if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)"); + /* For %q, %Q, and %w, the precision is the number of byte (or + ** characters if the ! flags is present) to use from the input. + ** Because of the extra quoting characters inserted, the number + ** of output characters may be larger than the precision. + */ k = precision; for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){ if( ch==q ) n++; + if( flag_altform2 && (ch&0xc0)==0xc0 ){ + while( (escarg[i+1]&0xc0)==0x80 ){ i++; } + } } needQuote = !isnull && xtype==etSQLESCAPE2; n += i + 3; @@ -715,10 +724,7 @@ void sqlite3VXPrintf( if( needQuote ) bufpt[j++] = q; bufpt[j] = 0; length = j; - /* The precision in %q and %Q means how many input bytes to - ** consume, not the length of the output... - ** if( precision>=0 && precision