Example #1
0
int mem_string_search( const char *p, const char* d, const char* opt )
{
    int ps = strlen(p);
    ASSERT( ps < MAX_PATTERN );

    int nocase = str_find( opt, 'i' ) > -1;

    long pos = -1;

    if( str_find( opt, 'r' ) > -1 )
    {
        VRegexp re;
        if ( ! re.comp( p ) ) return -1;
        if ( ! re.m( d ) ) return -1;
        pos = re.sub_sp( 0 );
    } else if( str_find( opt, 'h' ) > -1 )
    {
        char new_p[MAX_PATTERN+1];
        int pl = hex_string_to_pattern( p, new_p );
        if (pl > 0)
            if ( nocase )
                pos = mem_quick_search_nc( new_p, pl, d, strlen(d) );
            else
                pos = mem_quick_search( new_p, pl, d, strlen(d) );
    }
    else
    {
        if ( nocase )
            pos = mem_quick_search_nc( p, ps, d, strlen(d) );
        else
            pos = mem_quick_search( p, ps, d, strlen(d) );
    }

    return pos;
};
Example #2
0
 int VRegexp::m( const char* line )
 {
   if ( ! ok() )
     {
     errstr = "no pattern compiled";
     return 0;
     }
   if ( ! line )
     {
     errstr = "no data to search into";
     return 0;
     }
   errstr = "";
   lp = line;
   if ( opt_mode == MODE_REGEXP )
     {
     rc = pcre_exec( re, pe, lp, strlen( lp ), 0, 0, sp, VREGEXP_MAX_SUBS*3 );
     ASSERT( rc >= -1 && rc != 0 );
     if ( rc > VREGEXP_MAX_SUBS ) rc = VREGEXP_MAX_SUBS;
     if ( rc < 1 ) rc = 0; // fail-safe, should throw exception above in debug mode
     return rc;
     }
   else
     {
     if ( opt_nocase )
       pos = mem_quick_search_nc( pt, pl, line, strlen(lp) );
     else
       pos = mem_quick_search( pt, pl, line, strlen(lp) );
     return pos >= 0;
     }
 }