src/sqlite3-re.c
/*
 * Checks if source string matches pattern.
 * regexp_statement(pattern, source)
 * E.g.:
 * select true where 'abc' regexp 'a.c';
 */
Checks if source string matches pattern.
Checks if source string matches pattern .
static void regexp_statement(
    sqlite3_context *context,
    int argc,
    sqlite3_value **argv) {
    regexp *r;
    const char *source;
    const char *pattern;
    int is_match = 0;
    assert(argc == 2);
    source = (const char *)sqlite3_value_text(argv[1]);
#ifdef DEBUG
    fprintf(stderr, "source = %s\n", source);
#endif
    if (!source) {
        sqlite3_result_int(context, is_match);
        return;
    }
    pattern = (const char *)sqlite3_value_text(argv[0]);
#ifdef DEBUG
    fprintf(stderr, "pattern = %s\n", pattern);
#endif
    if (!pattern) {
        sqlite3_result_error(context, "missing regexp pattern", -1);
        return;
    }
    r = re_compile(pattern);
    if (r == NULL) {
        sqlite3_result_error(context, "invalid regexp pattern", -1);
        return;
    }
    is_match = re_execute(r, source);
    sqlite3_result_int(context, is_match);
    free((char *)r);
}
static void regexp_statement ( sqlite3_context * context , int argc , sqlite3_value * * argv ) { regexp * r ; const char * source ; const char * pattern ; int is_match = 0 ; assert ( argc == 2 ) ; source = ( const char * ) sqlite3_value_text ( argv [ 1 ] ) ; #ifdef DEBUG fprintf ( stderr , " \n " , source ) ; #endif if ( ! source ) { sqlite3_result_int ( context , is_match ) ; return ; } pattern = ( const char * ) sqlite3_value_text ( argv [ 0 ] ) ; #ifdef DEBUG fprintf ( stderr , " \n " , pattern ) ; #endif if ( ! pattern ) { sqlite3_result_error ( context , " " , -1 ) ; return ; } r = re_compile ( pattern ) ; if ( r == NULL ) { sqlite3_result_error ( context , " " , -1 ) ; return ; } is_match = re_execute ( r , source ) ; sqlite3_result_int ( context , is_match ) ; free ( ( char * ) r ) ; }
Checks if source string matches pattern.
Checks if source string matches pattern .