aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c148
1 files changed, 1 insertions, 147 deletions
diff --git a/src/util.c b/src/util.c
index aaf198bc3..5f934a6bc 100644
--- a/src/util.c
+++ b/src/util.c
@@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
-** $Id: util.c,v 1.106 2004/06/21 08:18:55 danielk1977 Exp $
+** $Id: util.c,v 1.107 2004/06/25 01:10:48 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -774,152 +774,6 @@ int sqlite3GetInt64(const char *zNum, i64 *pValue){
return 0;
}
-/* This comparison routine is what we use for comparison operations
-** between numeric values in an SQL expression. "Numeric" is a little
-** bit misleading here. What we mean is that the strings have a
-** type of "numeric" from the point of view of SQL. The strings
-** do not necessarily contain numbers. They could contain text.
-**
-** If the input strings both look like actual numbers then they
-** compare in numerical order. Numerical strings are always less
-** than non-numeric strings so if one input string looks like a
-** number and the other does not, then the one that looks like
-** a number is the smaller. Non-numeric strings compare in
-** lexigraphical order (the same order as strcmp()).
-*/
-int sqlite3Compare(const char *atext, const char *btext){
- int result;
- int isNumA, isNumB;
- if( atext==0 ){
- return -1;
- }else if( btext==0 ){
- return 1;
- }
- isNumA = sqlite3IsNumber(atext, 0, SQLITE_UTF8);
- isNumB = sqlite3IsNumber(btext, 0, SQLITE_UTF8);
- if( isNumA ){
- if( !isNumB ){
- result = -1;
- }else{
- double rA, rB;
- rA = sqlite3AtoF(atext, 0);
- rB = sqlite3AtoF(btext, 0);
- if( rA<rB ){
- result = -1;
- }else if( rA>rB ){
- result = +1;
- }else{
- result = 0;
- }
- }
- }else if( isNumB ){
- result = +1;
- }else {
- result = strcmp(atext, btext);
- }
- return result;
-}
-
-/*
-** This routine is used for sorting. Each key is a list of one or more
-** null-terminated elements. The list is terminated by two nulls in
-** a row. For example, the following text is a key with three elements
-**
-** Aone\000Dtwo\000Athree\000\000
-**
-** All elements begin with one of the characters "+-AD" and end with "\000"
-** with zero or more text elements in between. Except, NULL elements
-** consist of the special two-character sequence "N\000".
-**
-** Both arguments will have the same number of elements. This routine
-** returns negative, zero, or positive if the first argument is less
-** than, equal to, or greater than the first. (Result is a-b).
-**
-** Each element begins with one of the characters "+", "-", "A", "D".
-** This character determines the sort order and collating sequence:
-**
-** + Sort numerically in ascending order
-** - Sort numerically in descending order
-** A Sort as strings in ascending order
-** D Sort as strings in descending order.
-**
-** For the "+" and "-" sorting, pure numeric strings (strings for which the
-** isNum() function above returns TRUE) always compare less than strings
-** that are not pure numerics. Non-numeric strings compare in memcmp()
-** order. This is the same sort order as the sqlite3Compare() function
-** above generates.
-**
-** The last point is a change from version 2.6.3 to version 2.7.0. In
-** version 2.6.3 and earlier, substrings of digits compare in numerical
-** and case was used only to break a tie.
-**
-** Elements that begin with 'A' or 'D' compare in memcmp() order regardless
-** of whether or not they look like a number.
-**
-** Note that the sort order imposed by the rules above is the same
-** from the ordering defined by the "<", "<=", ">", and ">=" operators
-** of expressions and for indices. This was not the case for version
-** 2.6.3 and earlier.
-*/
-int sqlite3SortCompare(const char *a, const char *b){
- int res = 0;
- int isNumA, isNumB;
- int dir = 0;
-
- while( res==0 && *a && *b ){
- if( a[0]=='N' || b[0]=='N' ){
- if( a[0]==b[0] ){
- a += 2;
- b += 2;
- continue;
- }
- if( a[0]=='N' ){
- dir = b[0];
- res = -1;
- }else{
- dir = a[0];
- res = +1;
- }
- break;
- }
- assert( a[0]==b[0] );
- if( (dir=a[0])=='A' || a[0]=='D' ){
- res = strcmp(&a[1],&b[1]);
- if( res ) break;
- }else{
- isNumA = sqlite3IsNumber(&a[1], 0, SQLITE_UTF8);
- isNumB = sqlite3IsNumber(&b[1], 0, SQLITE_UTF8);
- if( isNumA ){
- double rA, rB;
- if( !isNumB ){
- res = -1;
- break;
- }
- rA = sqlite3AtoF(&a[1], 0);
- rB = sqlite3AtoF(&b[1], 0);
- if( rA<rB ){
- res = -1;
- break;
- }
- if( rA>rB ){
- res = +1;
- break;
- }
- }else if( isNumB ){
- res = +1;
- break;
- }else{
- res = strcmp(&a[1],&b[1]);
- if( res ) break;
- }
- }
- a += strlen(&a[1]) + 2;
- b += strlen(&b[1]) + 2;
- }
- if( dir=='-' || dir=='D' ) res = -res;
- return res;
-}
-
#if 1 /* We are now always UTF-8 */
/*
** X is a pointer to the first byte of a UTF-8 character. Increment