A simple implementation of the Boyer-Moore string search algorithm for use with node.js' Buffer objects.
I needed this functionality in one of my projects. I started to write a search algorithm right away, until (after a few lines) I realized that it's absolutely unneccessary to do so - because others must have done this before (this "reinventing the wheel" thing, you know).
So I DuckDuckGoed (they really need a new name for that search engine, by the way) around the interwebs to find a suitable approach to my problem.
I immediately stumbled over the Boyer-Moore string search algorithm. Since I didn't know anything about how efficient string search is done (shame on me), I just started to write a ripoff from the Java example given in the Wikipedia article to get started learning about it.
var moore = require( './buffer-moore' ); var index = moore.indexOf( // the needle new Buffer( 'find me' ), // the haystack new Buffer( 'Some garbage text and the `find me` sequence.' ) );
var horspool = require( './buffer-horspool' ) var haystack = new Buffer( 'Some garbage text and the `find me` sequence.' ) var needle = new Buffer( 'find me' ) var index = horspool( haystack, needle )