Skip to content

Commit

Permalink
Don't mutate the original string
Browse files Browse the repository at this point in the history
  • Loading branch information
romanbsd committed Apr 5, 2012
1 parent 8fe8d57 commit 12ea1d2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,3 +1,4 @@
*.sw?
ext/Makefile
.DS_Store
coverage
coverage
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -16,7 +16,7 @@ rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end

require 'rake/rdoctask'
require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'fast-stemmer'
Expand Down
5 changes: 3 additions & 2 deletions VERSION.yml
@@ -1,4 +1,5 @@
---
---
:major: 1
:minor: 0
:patch: 0
:patch: 1
:build:
19 changes: 7 additions & 12 deletions ext/porter_wrap.c
Expand Up @@ -17,25 +17,20 @@ struct stemmer {

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

str = StringValue(arg);
word = RSTRING_PTR(str);
word = malloc(RSTRING_LEN(str) + 1);
strncpy(word, RSTRING_PTR(str), RSTRING_LEN(str));
word[RSTRING_LEN(str)] = '\0';

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);
word[length+1] = 0;
rv = rb_str_new2(word);
free(word);
return rv;
}

Expand Down
1 change: 1 addition & 0 deletions lib/fast-stemmer.rb
@@ -0,0 +1 @@
require 'fast_stemmer'

0 comments on commit 12ea1d2

Please sign in to comment.