From: drh Date: Tue, 14 Apr 2020 15:48:55 +0000 (+0000) Subject: Add the UINT collating sequence extension. The implementation is copied out X-Git-Tag: version-3.32.0~79 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e6a85962e754fded78939a826093baaf7869af4d;p=thirdparty%2Fsqlite.git Add the UINT collating sequence extension. The implementation is copied out of the "natsort" branch. FossilOrigin-Name: 6f46c6e3e3c471ca864d7596e0211ee90316b784c8fe22c7ae177c9d29731dc7 --- diff --git a/ext/misc/uint.c b/ext/misc/uint.c new file mode 100644 index 0000000000..12982c2a20 --- /dev/null +++ b/ext/misc/uint.c @@ -0,0 +1,91 @@ +/* +** 2020-04-14 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +****************************************************************************** +** +** This SQLite extension implements the UINT collating sequence. +** +** UINT works like BINARY for text, except that embedded strings +** of digits compare in numeric order. +** +** * Leading zeros are handled properly, in the sense that +** they do not mess of the maginitude comparison of embedded +** strings of digits. "x00123y" is equal to "x123y". +** +** * Only unsigned integers are recognized. Plus and minus +** signs are ignored. Decimal points and exponential notation +** are ignored. +** +** * Embedded integers can be of arbitrary length. Comparison +** is *not* limited integers that can be expressed as a +** 64-bit machine integer. +*/ +#include "sqlite3ext.h" +SQLITE_EXTENSION_INIT1 +#include +#include +#include + +/* +** Compare text in lexicographic order, except strings of digits +** compare in numeric order. +*/ +static int uintCollFunc( + void *notUsed, + int nKey1, const void *pKey1, + int nKey2, const void *pKey2 +){ + const unsigned char *zA = (const unsigned char*)pKey1; + const unsigned char *zB = (const unsigned char*)pKey2; + int i=0, j=0, x; + while( i