3 * Copyright (C) 1999 by Marcel Baur
4 * To be distributed under the Wine license
6 * This file features Heuristic Boyer-Moore Text Search
8 * Always: - Buf is the Buffer containing the whole text
9 * ======= - SP is the Search Pattern, which has to be found in Buf.
15 #define CHARSETSIZE 255
17 int delta[CHARSETSIZE];
19 /* rightmostpos: return rightmost position of ch in szSP (or -1) */
20 int rightmostpos(char ch, LPSTR szSP, int nSPLen) {
22 while ((i>0) & (szSP[i]!=ch)) i--;
26 /* setup_delta: setup delta1 cache */
27 void setup_delta(LPSTR szSP, int nSPLen) {
30 for (i=0; i<CHARSETSIZE; i++) {
34 for (i=0; i<nSPLen; i++) {
35 delta[(int)szSP[i]] = (nSPLen - rightmostpos(szSP[i], szSP, nSPLen));
39 int bm_search(LPSTR szBuf, int nBufLen, LPSTR szSP, int nSPLen) {
44 if ((szBuf[i] = szSP[j])) {
47 if ((nSPLen-j+1) > delta[(int)szBuf[i]]) {
50 i+= delta[(int)szBuf[i]];
53 } while (j>0 && i<=nBufLen);