shithub: asif

ref: 672e6e2a22e2b3c94aabd4f591fcc20a7634b93f
dir: /match/strnaive.c/

View raw version
#include <u.h>
#include <libc.h>
#include "asif.h"

/* naive exact string search of a word within a text */
VArray *
naivestrfind(String S, String W)
{
	int i, n;
	VArray *v;

	n = S.n - W.n + 1;
	if(n <= 0)
		return nil;
	v = valloc(n, sizeof(int));
	for(i=0; i<n; i++)
		if(strcmp(S.s+i, W.s) == 0)
			vinsert(v, (void*)&i);
	return v;
}