]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add support for parsing C-style hexadecimal literals.
authordrh <drh@noemail.net>
Wed, 23 Jul 2014 01:26:51 +0000 (01:26 +0000)
committerdrh <drh@noemail.net>
Wed, 23 Jul 2014 01:26:51 +0000 (01:26 +0000)
FossilOrigin-Name: 34a1f38b7a23c64f5c6e5b34c19a20480be53961

manifest
manifest.uuid
src/tokenize.c
src/util.c

index f57975f5d310b5e7dd4dbc5d59394501f5a0134c..1ebf10efcd19ec82d65e183f087b4f5f16f2e867 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C When\srunning\sANALYZE,\sit\sis\snot\snecessary\sto\scheck\sthe\sright-most\skey\scolumn\nfor\schanges\ssince\sthat\scolumn\swill\salways\schange\sif\snone\sof\sthe\sprevious\ncolumns\shave.
-D 2014-07-22T22:46:54.689
+C Add\ssupport\sfor\sparsing\sC-style\shexadecimal\sliterals.
+D 2014-07-23T01:26:51.616
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -277,11 +277,11 @@ F src/test_thread.c 1e133a40b50e9c035b00174035b846e7eef481cb
 F src/test_vfs.c f84075a388527892ff184988f43b69ce69b8083c
 F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698
 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
-F src/tokenize.c 6da2de6e12218ccb0aea5184b56727d011f4bee7
+F src/tokenize.c ae45399d6252b4d736af43bee1576ce7bff86aec
 F src/trigger.c 66f3470b03b52b395e839155786966e3e037fddb
 F src/update.c 01564b3c430f6c7b0a35afaf7aba7987206fa3a5
 F src/utf.c a0314e637768a030e6e84a957d0c4f6ba910cc05
-F src/util.c 049fe1d3c0e2209c1bee107aec2fcff6285f909f
+F src/util.c 9d87de90e59d78e69ab944f34a03a4228b05de6e
 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
 F src/vdbe.c fa74c6563486022920db4d73897bd9b837c7441d
 F src/vdbe.h c63fad052c9e7388d551e556e119c0bcf6bebdf8
@@ -1183,7 +1183,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 77f412caf0192d3e7fecb377d6d72123d8b64424
-R e38e472b4e4b7503ed49bdb3ca667f5c
+P 48f40861db4fbd10725a2b8b606d44fe16d5bd27
+R bc60c63a2067ce5c2bcc7a7ef85e26f4
+T *branch * hex-literal
+T *sym-hex-literal *
+T -sym-trunk *
 U drh
-Z e390ae6bf708e4580525fb01df14fd1e
+Z 425e58328b59810233115ebd1d9053d0
index 691fcc01d630ab3f9b477f2c33ac0afaf14ea628..6e3e9df36da18e19ff7661f676987f74c03a6fc3 100644 (file)
@@ -1 +1 @@
-48f40861db4fbd10725a2b8b606d44fe16d5bd27
\ No newline at end of file
+34a1f38b7a23c64f5c6e5b34c19a20480be53961
\ No newline at end of file
index 87553e25b049419a5c76e4944a29f7989353ef5d..4017c3b81662929e72598c17c84158250f8865b7 100644 (file)
@@ -270,6 +270,12 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){
       testcase( z[0]=='6' );  testcase( z[0]=='7' );  testcase( z[0]=='8' );
       testcase( z[0]=='9' );
       *tokenType = TK_INTEGER;
+#ifndef SQLITE_OMIT_HEX_INTEGER
+      if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){
+        for(i=3; sqlite3Isxdigit(z[i]); i++){}
+        return i;
+      }
+#endif
       for(i=0; sqlite3Isdigit(z[i]); i++){}
 #ifndef SQLITE_OMIT_FLOATING_POINT
       if( z[i]=='.' ){
index 4fe07a862a0bb2e9ade4eeb525bd6269a00f307c..1686d4342d91d47eacb8db8ac5c57906a4828a72 100644 (file)
@@ -255,6 +255,22 @@ int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
   return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
 }
 
+/*
+** Translate a single byte of Hex into an integer.
+** This routine only works if h really is a valid hexadecimal
+** character:  0..9a..fA..F
+*/
+u8 sqlite3HexToInt(int h){
+  assert( (h>='0' && h<='9') ||  (h>='a' && h<='f') ||  (h>='A' && h<='F') );
+#ifdef SQLITE_ASCII
+  h += 9*(1&(h>>6));
+#endif
+#ifdef SQLITE_EBCDIC
+  h += 9*(1&~(h>>4));
+#endif
+  return (u8)(h & 0xf);
+}
+
 /*
 ** The string z[] is an text representation of a real number.
 ** Convert this string to a double and write it into *pResult.
@@ -318,6 +334,20 @@ int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
   }else if( *z=='+' ){
     z+=incr;
   }
+#ifndef SQLITE_OMIT_HEX_INTEGER
+  else if( *z==0
+        && &z[incr*2]<zEnd
+        && (z[incr]=='x' || z[incr]=='X')
+        && sqlite3Isxdigit(z[incr*2])
+  ){
+    result = 0.0;
+    for(z += incr*2; z<zEnd && sqlite3Isxdigit(z[0]); z += incr){
+      result = result*16.0 + sqlite3HexToInt(z[0]);
+    }
+    *pResult = result;
+    return z>=zEnd && nonNum==0;
+  }
+#endif
 
   /* skip leading zeroes */
   while( z<zEnd && z[0]=='0' ) z+=incr, nDigits++;
@@ -475,7 +505,6 @@ static int compare2pow63(const char *zNum, int incr){
   return c;
 }
 
-
 /*
 ** Convert zNum to a 64-bit signed integer.
 **
@@ -522,6 +551,21 @@ int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
     }else if( *zNum=='+' ){
       zNum+=incr;
     }
+#ifndef SQLITE_OMIT_HEX_INTEGER
+    else if( *zNum=='0'
+          &&  &zNum[incr*2]<zEnd
+          && (zNum[incr]=='x' || zNum[incr]=='X')
+          && sqlite3Isxdigit(zNum[incr*2])
+    ){
+      zNum += incr*2;
+      while( zNum<zEnd && zNum[0]=='0' ) zNum += incr;
+      for(i=0; &zNum[i]<zEnd && sqlite3Isxdigit(zNum[i]); i+=incr){
+        u = u*16 + sqlite3HexToInt(zNum[i]);
+      }
+      memcpy(pNum, &u, 8);
+      return &zNum[i]<zEnd || i>16*incr || nonNum;
+    }
+#endif
   }
   zStart = zNum;
   while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
@@ -583,7 +627,25 @@ int sqlite3GetInt32(const char *zNum, int *pValue){
   }else if( zNum[0]=='+' ){
     zNum++;
   }
-  while( zNum[0]=='0' ) zNum++;
+#ifndef SQLITE_OMIT_HEX_INTEGER
+  else if( zNum[0]=='0'
+        && (zNum[1]=='x' || zNum[1]=='X')
+        && sqlite3Isxdigit(zNum[2])
+  ){
+    u32 u = 0;
+    zNum += 2;
+    while( zNum[0]=='0' ) zNum++;
+    for(i=0; sqlite3Isxdigit(zNum[i]) && i<8; i++){
+      u = u*16 + sqlite3HexToInt(zNum[i]);
+    }
+    if( (u&0x80000000)==0 && sqlite3Isxdigit(zNum[i])==0 ){
+      memcpy(pValue, &u, 4);
+      return 1;
+    }else{
+      return 0;
+    }
+  }
+#endif
   for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
     v = v*10 + c;
   }
@@ -1029,24 +1091,6 @@ void sqlite3Put4byte(unsigned char *p, u32 v){
   p[3] = (u8)v;
 }
 
-
-
-/*
-** Translate a single byte of Hex into an integer.
-** This routine only works if h really is a valid hexadecimal
-** character:  0..9a..fA..F
-*/
-u8 sqlite3HexToInt(int h){
-  assert( (h>='0' && h<='9') ||  (h>='a' && h<='f') ||  (h>='A' && h<='F') );
-#ifdef SQLITE_ASCII
-  h += 9*(1&(h>>6));
-#endif
-#ifdef SQLITE_EBCDIC
-  h += 9*(1&~(h>>4));
-#endif
-  return (u8)(h & 0xf);
-}
-
 #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
 /*
 ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary