diff --git a/manifest b/manifest index 3a38438d67..b7ed61fdcb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Strengthen\sthe\sfinal\stest\scase\sin\sindex5.test.\s\sAlso\sprovide\sadditional\ndiagnostic\sinformation\sout\sthe\soutput. -D 2013-02-25T13:55:59.837 +C Add\snew\sSQL\sfunctions\sunicode()\sand\schar(). +D 2013-02-25T14:39:47.361 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in a48faa9e7dd7d556d84f5456eabe5825dd8a6282 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -133,7 +133,7 @@ F src/delete.c 9b8d308979114991e5dc7cee958316e07186941d F src/expr.c f6c20285bd36e87ec47f4d840e90a32755e2a90c F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e16942bd5c8a868ac53287886464a5ed0e72b179 -F src/func.c 8147799b048065a1590805be464d05b4913e652c +F src/func.c 18b120b9a34daf6d38d50969b6f3471c09b2934a F src/global.c e59ecd2c553ad0d4bfbc84ca71231336f8993a7a F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4 F src/hash.h 2894c932d84d9f892d4b4023a75e501f83050970 @@ -508,7 +508,7 @@ F test/fts4merge2.test 5faa558d1b672f82b847d2a337465fa745e46891 F test/fts4merge3.test aab02a09f50fe6baaddc2e159c3eabc116d45fc7 F test/fts4unicode.test 25ccad45896f8e50f6a694cff738a35f798cdb40 F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d -F test/func.test 0d89043dab9a8853358d14c68e028ee0093bf066 +F test/func.test dd81580d3e8f2afafdcc8dd67233f9b4fc69a79e F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f F test/func3.test 001021e5b88bd02a3b365a5c5fd8f6f49d39744a F test/fuzz-oss1.test 4912e528ec9cf2f42134456933659d371c9e0d74 @@ -1035,7 +1035,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P d87e5acf2802d2887e20f79a8bd4990b2cd47b91 -R eab578b1b57353b6c3cb7f5f6faef55f +P 47b6418242bb2cd718d1a73b0cb73a43ee74e503 209b21085b9767f10f6ffb7c7cac756fcb74ded5 +R acbb3126cf444e9dd94bf56c3bd8260d U drh -Z 0e128646425d74587780af38946ae84f +Z f91250c13344084844a40baa07a182ba diff --git a/manifest.uuid b/manifest.uuid index 232a450f12..d8624e0281 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -47b6418242bb2cd718d1a73b0cb73a43ee74e503 \ No newline at end of file +be2493905281e12c7f4c146ab17c8872e52da350 \ No newline at end of file diff --git a/src/func.c b/src/func.c index d4655ad7e9..98f2a2e96b 100644 --- a/src/func.c +++ b/src/func.c @@ -962,6 +962,56 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ } } +/* +** The unicode() function. Return the integer unicode code-point value +** for the first character of the input string. +*/ +static void unicodeFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + const unsigned char *z = sqlite3_value_text(argv[0]); + if( z && z[0] ) sqlite3_result_int(context, sqlite3Utf8Read(&z)); +} + +/* +** The char() function takes zero or more arguments, each of which is +** an integer. It constructs a string where each character of the string +** is the unicode character for the corresponding integer argument. +*/ +static void charFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + unsigned char *z, *zOut; + int i; + zOut = z = sqlite3_malloc( argc*4 ); + if( z==0 ){ + sqlite3_result_error_nomem(context); + return; + } + for(i=0; i0x10ffff ) x = 0xfffd; + c = (unsigned)(x & 0x1fffff); + if( c<=0xFFFF ){ + *zOut++ = (u8)(c&0x00FF); + *zOut++ = (u8)((c>>8)&0x00FF); + }else{ + if( c>=0xd800 && c<=0xdbff ) c = 0xfffd; + *zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); + *zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03)); + *zOut++ = (u8)(c&0x00FF); + *zOut++ = (u8)(0x00DC + ((c>>8)&0x03)); + } + } + sqlite3_result_text16le(context, (char*)z, (int)(zOut-z), sqlite3_free); +} + /* ** The hex() function. Interpret the argument as a blob. Return ** a hexadecimal rendering as text. @@ -1589,6 +1639,8 @@ void sqlite3RegisterGlobalFunctions(void){ FUNCTION(instr, 2, 0, 0, instrFunc ), FUNCTION(substr, 2, 0, 0, substrFunc ), FUNCTION(substr, 3, 0, 0, substrFunc ), + FUNCTION(unicode, 1, 0, 0, unicodeFunc ), + FUNCTION(char, -1, 0, 0, charFunc ), FUNCTION(abs, 1, 0, 0, absFunc ), #ifndef SQLITE_OMIT_FLOATING_POINT FUNCTION(round, 1, 0, 0, roundFunc ), diff --git a/test/func.test b/test/func.test index e44c44b280..e45f961a73 100644 --- a/test/func.test +++ b/test/func.test @@ -1289,6 +1289,21 @@ do_test func-29.6 { if {$x<5} {set x 1} set x } {1} - + +do_execsql_test func-30.1 {SELECT unicode('$');} 36 +do_execsql_test func-30.2 {SELECT unicode('¢');} 162 +do_execsql_test func-30.3 {SELECT unicode('€');} 8364 +do_execsql_test func-30.4 {SELECT char(36,162,8364);} {$¢€} + +for {set i 1} {$i<0xd800} {incr i 13} { + do_execsql_test func-30.5.$i {SELECT unicode(char($i))} $i +} +for {set i 57344} {$i<=0xfffd} {incr i 17} { + if {$i==0xfeff} continue + do_execsql_test func-30.5.$i {SELECT unicode(char($i))} $i +} +for {set i 65536} {$i<=0x10ffff} {incr i 139} { + do_execsql_test func-30.5.$i {SELECT unicode(char($i))} $i +} finish_test