Module: Stemmer

Defined in:
ext/porter_wrap.c

Class Method Summary collapse

Class Method Details

.stem_word(arg) ⇒ Object

a general offset into the string



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'ext/porter_wrap.c', line 18

static VALUE stem_word(VALUE self, VALUE arg)
{
	int length, i;
	char *word;
	char *res;
	struct stemmer z;
	VALUE str, rv;

	str = StringValue(arg);
	word = RSTRING_PTR(str);

	length  = stem(&z, word, strlen(word)-1);
	/* length is the index of last char, add one for size and one for '\0' */
	res = (char *)malloc((length+2) * sizeof(char));
	for (i=0; i<=length; i++)
	{
		res[i] = word[i];
	}
	res[length+1] = 0;
	rv = rb_str_new2(res);
	free(res);
	return rv;
}