[Home]
[Contents]
[Chapter]
[Previous Algorithm]
[Next Algorithm]


Deterministic-finite-automata text searching


char *search( pat, text ) char *pat, *text; { short st, **states; automata a; if( pat[0] == EOS ) return( text ); a = stringautom(pat); states = a->nextst; for( st=0; st < a->st; st++ ) states[st][EOS] = -1; st = 0; while( (st = states[st][*text++ & (MAXCHAR-1)]) >= 0 ); if( *(text-1) == EOS ) return( NULL ); else return( text - a->final[-st] ); }

C source (716.srch.c)



© Addison-Wesley Publishing Co. Inc.