Exemple #1
0
/* This is used if the key is not UTF-8, or it is but the search is case-sensitive */
static SLsearch_Type *bm_open_search (SLuchar_Type *key, int flags)
{
   SLsearch_Type *st;
   size_t keylen;

   keylen = strlen ((char *)key);
   if (NULL == (st = (SLsearch_Type *)SLcalloc (1, sizeof (SLsearch_Type))))
     return NULL;

   st->free_fun = bm_free;

   /* If the search is case-insensitive, then it must either be all ascii, or
    * it is not unicode.  In either case, the UPPER_CASE and LOWER_CASE macros
    * should be ok to use.
    */
   if (flags & SLSEARCH_CASELESS)
     {
	char *keyup = SLmake_nstring ((char *)key, keylen);
	if (keyup != NULL)
	  {
	     unsigned char *k = (unsigned char *)keyup;
	     while (*k != 0)
	       {
		  *k = UPPER_CASE(*k);
		  k++;
	       }
	     st->s.bm.key = (SLuchar_Type *)SLang_create_slstring (keyup);
	     SLfree (keyup);
	  }
	else st->s.bm.key = NULL;
     }
   else st->s.bm.key = (SLuchar_Type*) SLang_create_slstring ((char *)key);

   if (st->s.bm.key == NULL)
     {
        SLsearch_delete (st);
        return NULL;
     }
   st->s.bm.key_len = keylen;
   st->flags = flags;

   st->search_fun = bm_search;

   init_skip_table (st->s.bm.key, st->s.bm.key_len, st->s.bm.fskip_table, 1, flags);
   init_skip_table (st->s.bm.key, st->s.bm.key_len, st->s.bm.bskip_table, -1, flags);
   return st;
}
        knuth_morris_pratt ( patIter first, patIter last ) 
                : pat_first ( first ), pat_last ( last ), 
                  k_pattern_length ( std::distance ( pat_first, pat_last )),
                  skip_ ( k_pattern_length + 1 ) {
#ifdef NEW_KMP
            preKmp ( pat_first, pat_last );
#else
            init_skip_table ( pat_first, pat_last );
#endif
#ifdef BOOST_ALGORITHM_KNUTH_MORRIS_PRATT_DEBUG
            detail::PrintTable ( skip_.begin (), skip_.end ());
#endif
            }