mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-10 01:02:56 +03:00
Add the RTRIM collating sequence. Only implemented for UTF8. Still
considered experimental and may be removed if we find adverse impact elsewhere in the system. (CVS 4732) FossilOrigin-Name: 0bf4e7fefdbbf7be4e32195473563158f22f1869
This commit is contained in:
25
src/main.c
25
src/main.c
@@ -14,7 +14,7 @@
|
||||
** other files are for internal use by SQLite and should not be
|
||||
** accessed by users of the library.
|
||||
**
|
||||
** $Id: main.c,v 1.409 2007/12/07 18:55:28 drh Exp $
|
||||
** $Id: main.c,v 1.410 2008/01/20 23:19:57 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -45,12 +45,23 @@ void (*sqlite3_io_trace)(const char*, ...) = 0;
|
||||
char *sqlite3_temp_directory = 0;
|
||||
|
||||
|
||||
/*
|
||||
** Return true if the buffer z[0..n-1] contains all spaces.
|
||||
*/
|
||||
static int allSpaces(const char *z, int n){
|
||||
while( n>0 && z[--n]==' ' ){}
|
||||
return n==0;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is the default collating function named "BINARY" which is always
|
||||
** available.
|
||||
**
|
||||
** If the padFlag argument is not NULL then space padding at the end
|
||||
** of strings is ignored. This implements the RTRIM collation.
|
||||
*/
|
||||
static int binCollFunc(
|
||||
void *NotUsed,
|
||||
void *padFlag,
|
||||
int nKey1, const void *pKey1,
|
||||
int nKey2, const void *pKey2
|
||||
){
|
||||
@@ -58,7 +69,14 @@ static int binCollFunc(
|
||||
n = nKey1<nKey2 ? nKey1 : nKey2;
|
||||
rc = memcmp(pKey1, pKey2, n);
|
||||
if( rc==0 ){
|
||||
rc = nKey1 - nKey2;
|
||||
if( padFlag
|
||||
&& allSpaces(((char*)pKey1)+n, nKey1-n)
|
||||
&& allSpaces(((char*)pKey2)+n, nKey2-n)
|
||||
){
|
||||
/* Leave rc unchanged at 0 */
|
||||
}else{
|
||||
rc = nKey1 - nKey2;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -994,6 +1012,7 @@ static int openDatabase(
|
||||
if( createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc, 0) ||
|
||||
createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0) ||
|
||||
createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0) ||
|
||||
createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0) ||
|
||||
(db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0))==0
|
||||
){
|
||||
assert( db->mallocFailed );
|
||||
|
Reference in New Issue
Block a user