aboutsummaryrefslogtreecommitdiff
path: root/ext/misc/regexp.c
diff options
context:
space:
mode:
authordrh <>2021-06-03 12:31:08 +0000
committerdrh <>2021-06-03 12:31:08 +0000
commit75f7317722c3e41b61291db992b6527b4a756011 (patch)
treec9b057363f50c8831fb4a9ec5d84dd33f18075db /ext/misc/regexp.c
parentf9ac1ab1e7fd9cb827094a88c894d595aacb4927 (diff)
downloadsqlite-75f7317722c3e41b61291db992b6527b4a756011.tar.gz
sqlite-75f7317722c3e41b61291db992b6527b4a756011.zip
Fix the case-insensitive version of the regexp() function so that it does not
use the prefix optimization incorrectly. [forum:/forumpost/983b43ef8e|Forum post 983b43ef8e]. FossilOrigin-Name: 1a8e43cc1b7969c40140dd7fd481d5ffd9de80e214eb494567c286d93a2b06e5
Diffstat (limited to 'ext/misc/regexp.c')
-rw-r--r--ext/misc/regexp.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/misc/regexp.c b/ext/misc/regexp.c
index 03bbeb97d..204489f58 100644
--- a/ext/misc/regexp.c
+++ b/ext/misc/regexp.c
@@ -673,7 +673,7 @@ static const char *re_compile(ReCompiled **ppRe, const char *zIn, int noCase){
** regex engine over the string. Do not worry able trying to match
** unicode characters beyond plane 0 - those are very rare and this is
** just an optimization. */
- if( pRe->aOp[0]==RE_OP_ANYSTAR ){
+ if( pRe->aOp[0]==RE_OP_ANYSTAR && !noCase ){
for(j=0, i=1; j<sizeof(pRe->zInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){
unsigned x = pRe->aArg[i];
if( x<=127 ){
@@ -719,7 +719,7 @@ static void re_sql_func(
if( pRe==0 ){
zPattern = (const char*)sqlite3_value_text(argv[0]);
if( zPattern==0 ) return;
- zErr = re_compile(&pRe, zPattern, 0);
+ zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0);
if( zErr ){
re_free(pRe);
sqlite3_result_error(context, zErr, -1);
@@ -756,5 +756,11 @@ int sqlite3_regexp_init(
SQLITE_EXTENSION_INIT2(pApi);
rc = sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8|SQLITE_INNOCUOUS,
0, re_sql_func, 0, 0);
+ if( rc==SQLITE_OK ){
+ /* The regexpi(PATTERN,STRING) function is a case-insensitive version
+ ** of regexp(PATTERN,STRING). */
+ rc = sqlite3_create_function(db, "regexpi", 2, SQLITE_UTF8|SQLITE_INNOCUOUS,
+ (void*)db, re_sql_func, 0, 0);
+ }
return rc;
}