]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the NATSORT collating sequence. No test cases yet.
authordrh <drh@noemail.net>
Mon, 30 Mar 2020 15:39:54 +0000 (15:39 +0000)
committerdrh <drh@noemail.net>
Mon, 30 Mar 2020 15:39:54 +0000 (15:39 +0000)
FossilOrigin-Name: 79fcaa8e07f61ea84e24f7e30d2426a7d30bfe6316d5a89e5662b03b0c8943f3

manifest
manifest.uuid
src/main.c

index abeefcdd04682bfbd5a62a789cb0457a9d9d8890..67a728d47a0c79880ddfb0dc5492ff30636c394b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Use\s__atomic_load_n()\sand\s__atomic_store_n()\sfor\sa\sfew\smore\sthings\swhere\sthey\sare\savailable.
-D 2020-03-30T13:35:05.649
+C Add\sthe\sNATSORT\scollating\ssequence.\s\sNo\stest\scases\syet.
+D 2020-03-30T15:39:54.428
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -495,7 +495,7 @@ F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
 F src/insert.c 8e4211d04eb460c0694d486c6ba1c068d468c6f653c3f237869a802ad82854de
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
 F src/loadext.c b179df50e6e8bb0c36c149e95d958d49bd8c6c7469e59c01b53d164360bc6c32
-F src/main.c 2e076b6dc1f8ab69c7fc604e8af88ab138a64c0616826361e254cee55bcba4e8
+F src/main.c 38e2f027c843ede6d0b2fb4fae4cd51b1146848ed2736c6461d6cd72a5b973a1
 F src/malloc.c cabfef0d725e04c8abfe0231a556ed8b78bf329dcc3fddbf903f6cdcd53cf4e6
 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
 F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de
@@ -1860,7 +1860,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P fbd9378727141848ba2f5a8eee3076ecbd315e4a87b264c6d890103d56b2e4bc
-R c8b295e5bd68ca95045f3500e6ef50d6
-U dan
-Z 1be00e3678658e7590a9c61fafe2f4aa
+P a49f8ec552bede7da731e0571ccf49de1a30e7be3a5673150436c8b411ba6ffc
+R cdcaab153b3d333e9ee56a4e8fe64b19
+T *branch * natsort
+T *sym-natsort *
+T -sym-trunk *
+U drh
+Z 52cc0ba312367dbd46a4cc87640d9522
index ca0e7838139881cac0d96dc43f037aba170c7491..528f3bd36bab5db904f216edab9f2ffd14839943 100644 (file)
@@ -1 +1 @@
-a49f8ec552bede7da731e0571ccf49de1a30e7be3a5673150436c8b411ba6ffc
\ No newline at end of file
+79fcaa8e07f61ea84e24f7e30d2426a7d30bfe6316d5a89e5662b03b0c8943f3
\ No newline at end of file
index d693621b1e7b0987dc9df664c3abf515747f99f6..e042e05c9e05979ed07efa91c79aebae77fcb796 100644 (file)
@@ -991,6 +991,50 @@ static int nocaseCollatingFunc(
   return r;
 }
 
+/*
+** The UINT collating function that compares text byte-by-byte but compares
+** digits in numeric order.
+*/
+static int natsortCollFunc(
+  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<nKey1 && j<nKey2 ){
+    x = zA[i] - zB[j];
+    if( sqlite3Isdigit(zA[i]) ){
+      int k;
+      if( !sqlite3Isdigit(zB[j]) ) return x;
+      while( zA[i]=='0' && i<nKey1 ){ i++; }
+      while( zB[j]=='0' && j<nKey2 ){ j++; }
+      k = 0;
+      while( i+k<nKey1 && sqlite3Isdigit(zA[i+k])
+             && j+k<nKey2 && sqlite3Isdigit(zB[j+k]) ){
+        k++;
+      }
+      if( i+k<nKey1 && sqlite3Isdigit(zA[i+k]) ){
+        return +1;
+      }else if( j+k<nKey2 && sqlite3Isdigit(zB[j+k]) ){
+        return -1;
+      }else{
+        x = memcmp(zA+i, zB+j, k);
+        if( x ) return x;
+        i += k;
+        j += k;
+      }
+    }else if( x ){
+      return x;
+    }else{
+      i++;
+      j++;
+    }
+  }
+  return (nKey1 - i) - (nKey2 - j);
+}
+
 /*
 ** Return the ROWID of the most recent insert
 */
@@ -3208,6 +3252,7 @@ static int openDatabase(
   createCollation(db, sqlite3StrBINARY, SQLITE_UTF16LE, 0, binCollFunc, 0);
   createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
   createCollation(db, "RTRIM", SQLITE_UTF8, 0, rtrimCollFunc, 0);
+  createCollation(db, "NATSORT", SQLITE_UTF8, 0, natsortCollFunc, 0);
   if( db->mallocFailed ){
     goto opendb_out;
   }