1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Internationalize the TRIM functions. Ticket #2323. (CVS 3883)

FossilOrigin-Name: ff1f4e744728c8f55afae265246797b30fe98fb0
This commit is contained in:
drh
2007-04-27 21:59:52 +00:00
parent ac7b2dd518
commit d1e3a616ca
4 changed files with 71 additions and 27 deletions

View File

@ -1,5 +1,5 @@
C Lift\scode\sto\straverse\sinterior\snodes\sout\sof\sloadSegment().\nRefactoring\stowards\sprefix\ssearching.\s(CVS\s3882)
D 2007-04-27T21:24:18
C Internationalize\sthe\sTRIM\sfunctions.\s\sTicket\s#2323.\s(CVS\s3883)
D 2007-04-27T21:59:53
F Makefile.in 8cab54f7c9f5af8f22fd97ddf1ecfd1e1860de62
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -68,7 +68,7 @@ F src/date.c 94a6777df13d2aaacd19de080d9e8d3444364133
F src/delete.c 5c0d89b3ef7d48fe1f5124bfe8341f982747fe29
F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
F src/expr.c 2f0f9f89efe9170e5e6ca5d5e93a9d5896fff5ac
F src/func.c 89d8547a9cb1c5ad8e0b86b3d74de56e5254254b
F src/func.c b40a6320fa12530602ffd9535c8f97f934f0e69c
F src/hash.c 67b23e14f0257b69a3e8aa663e4eeadc1a2b6fd5
F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564
F src/insert.c 413cc06990cb3c401e64e596776c1e43934f8841
@ -235,7 +235,7 @@ F test/fts2j.test f68d7611f76309bc8b94170f3740d9fbbc061d9b
F test/fts2k.test 222d0b3bc8667753f18406aaea9906a6098ea016
F test/fts2l.test 4c53c89ce3919003765ff4fd8d98ecf724d97dd3
F test/fts2m.test 4b30142ead6f3ed076e880a2a464064c5ad58c51
F test/func.test d66c42af501a77bd9b36c3d675d844b04db04765
F test/func.test 8a3bc8e8365dc0053c826923c0f738645f50f2f5
F test/hook.test 7e7645fd9a033f79cce8fdff151e32715e7ec50a
F test/in.test 369cb2aa1eab02296b4ec470732fe8c131260b1d
F test/incrvacuum.test fc5e88ac32095fb65ea11b739bc4e310c4852ef4
@ -464,7 +464,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 22ffdae4b6f3d0ea584dafa5268af7aa6fdcdc6e
R dce6a390ff9ccb534e4d5743da453b5a
U shess
Z 3d1f65a5bd747e5ae2188d3aea41ae85
P 25935db73877c0cb132acb30c2fed2544d0e5e32
R fdd67fb21752d8fbe0a5631485c66773
U drh
Z dbf7b152ffcec38cc7febead2efd96a3

View File

@ -1 +1 @@
25935db73877c0cb132acb30c2fed2544d0e5e32
ff1f4e744728c8f55afae265246797b30fe98fb0

View File

@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.142 2007/04/27 17:16:20 drh Exp $
** $Id: func.c,v 1.143 2007/04/27 21:59:53 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -750,9 +750,12 @@ static void trimFunc(
const unsigned char *zIn; /* Input string */
const unsigned char *zCharSet; /* Set of characters to trim */
int nIn; /* Number of bytes in input */
int flags;
int i;
unsigned char cFirst, cNext;
int flags; /* 1: trimleft 2: trimright 3: trim */
int i; /* Loop counter */
unsigned char *aLen; /* Length of each character in zCharSet */
const unsigned char **azChar; /* Individual characters in zCharSet */
int nChar; /* Number of characters in zCharSet */
if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
return;
}
@ -760,29 +763,60 @@ static void trimFunc(
zIn = sqlite3_value_text(argv[0]);
if( zIn==0 ) return;
if( argc==1 ){
static const unsigned char zSpace[] = " ";
zCharSet = zSpace;
static const unsigned char lenOne[] = { 1 };
static const char *azOne[] = { " " };
nChar = 1;
aLen = (unsigned char*)lenOne;
azChar = (const unsigned char**)azOne;
zCharSet = 0;
}else if( (zCharSet = sqlite3_value_text(argv[1]))==0 ){
return;
}else{
const unsigned char *z;
for(z=zCharSet, nChar=0; *z; nChar++){
sqliteNextChar(z);
}
if( nChar>0 ){
azChar = sqlite3_malloc( nChar*(sizeof(char*)+1) );
if( azChar==0 ){
return;
}
aLen = (unsigned char*)&azChar[nChar];
for(z=zCharSet, nChar=0; *z; nChar++){
azChar[nChar] = z;
sqliteNextChar(z);
aLen[nChar] = z - azChar[nChar];
}
}
}
cFirst = zCharSet[0];
if( cFirst ){
if( nChar>0 ){
flags = (int)sqlite3_user_data(context);
if( flags & 1 ){
for(; nIn>0; nIn--, zIn++){
if( cFirst==zIn[0] ) continue;
for(i=1; zCharSet[i] && zCharSet[i]!=zIn[0]; i++){}
if( zCharSet[i]==0 ) break;
while( nIn>0 ){
int len;
for(i=0; i<nChar; i++){
len = aLen[i];
if( memcmp(zIn, azChar[i], len)==0 ) break;
}
if( i>=nChar ) break;
zIn += len;
nIn -= len;
}
}
if( flags & 2 ){
for(; nIn>0; nIn--){
cNext = zIn[nIn-1];
if( cFirst==cNext ) continue;
for(i=1; zCharSet[i] && zCharSet[i]!=cNext; i++){}
if( zCharSet[i]==0 ) break;
while( nIn>0 ){
int len;
for(i=0; i<nChar; i++){
len = aLen[i];
if( len<=nIn && memcmp(&zIn[nIn-len],azChar[i],len)==0 ) break;
}
if( i>=nChar ) break;
nIn -= len;
}
}
if( zCharSet ){
sqlite3_free(azChar);
}
}
sqlite3_result_text(context, (char*)zIn, nIn, SQLITE_TRANSIENT);
}

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing built-in functions.
#
# $Id: func.test,v 1.61 2007/04/27 01:18:03 drh Exp $
# $Id: func.test,v 1.62 2007/04/27 21:59:53 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -821,6 +821,16 @@ do_test func-22.12 {
do_test func-22.13 {
execsql {SELECT trim(' hi ','');}
} {{ hi }}
do_test func-22.14 {
execsql {SELECT hex(trim(x'c280e1bfbff7bfbfbf6869',x'6162e1bfbfc280'))}
} {F7BFBFBF6869}
do_test func-22.15 {
execsql {SELECT hex(trim(x'6869c280e1bfbff7bfbfbf61',
x'6162e1bfbfc280f7bfbfbf'))}
} {6869}
do_test func-22.16 {
execsql {SELECT hex(trim(x'ceb1ceb2ceb3',x'ceb1'));}
} {CEB2CEB3}
do_test func-22.20 {
execsql {SELECT typeof(trim(NULL));}
} {null}