Skip to content

Commit

Permalink
Merge pull request #2 from tmm1/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
SamSaffron committed Nov 21, 2013
2 parents fee792d + 3895a4a commit c316b57
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source 'https://rubygems.org'
gemspec

gem 'rake'
gem 'debugger', :platform => :mri_19
gem 'ruby-debug', :platform => :mri_18

Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ PATH
remote: .
specs:
fast_blank (0.0.1)
rake
rake-compiler

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -63,5 +61,7 @@ DEPENDENCIES
debugger
fast_blank!
guard-rspec
rake
rake-compiler
rspec
ruby-debug
59 changes: 36 additions & 23 deletions ext/fast_blank/fast_blank.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
#define RSTRING_LEN(s) (RSTRING(s)->len)
#endif

const unsigned int as_blank[26] = {9, 0xa, 0xb, 0xc, 0xd,
0x20, 0x85, 0xa0, 0x1680, 0x180e, 0x2000, 0x2001,
0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008,
0x2009, 0x200a, 0x2028, 0x2029, 0x202f, 0x205f, 0x3000
};

static VALUE
rb_str_blank_as(VALUE str)
{
Expand All @@ -33,22 +27,41 @@ rb_str_blank_as(VALUE str)

e = RSTRING_END(str);
while (s < e) {
int n;
unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);
int n;
unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);

found = 0;
for(i=0;i<26;i++){
unsigned int current = as_blank[i];
if(current == cc) {
found = 1;
break;
}
if(cc < current){
break;
}
switch (cc) {
case 9:
case 0xa:
case 0xb:
case 0xc:
case 0xd:
case 0x20:
case 0x85:
case 0xa0:
case 0x1680:
case 0x180e:
case 0x2000:
case 0x2001:
case 0x2002:
case 0x2003:
case 0x2004:
case 0x2005:
case 0x2006:
case 0x2007:
case 0x2008:
case 0x2009:
case 0x200a:
case 0x2028:
case 0x2029:
case 0x202f:
case 0x205f:
case 0x3000:
/* found */
break;
default:
return Qfalse;
}

if (!found) return Qfalse;
s += n;
}
return Qtrue;
Expand All @@ -66,10 +79,10 @@ rb_str_blank(VALUE str)

e = RSTRING_END(str);
while (s < e) {
int n;
unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);
int n;
unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);

if (!rb_isspace(cc) && cc != 0) return Qfalse;
if (!rb_isspace(cc) && cc != 0) return Qfalse;
s += n;
}
return Qtrue;
Expand Down
7 changes: 3 additions & 4 deletions fast_blank.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Gem::Specification.new do |s|

s.authors = ['Sam Saffron']
s.email = 'sam.saffron@gmail.com'
s.homepage = ''
s.homepage = 'https://github.com/SamSaffron/fast_blank'
s.license = 'MIT'

s.extensions = ['ext/fast_blank/extconf.rb']
s.require_paths = ['lib']
Expand All @@ -24,9 +25,7 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.rubygems_version = '1.3.7'

s.add_dependency 'rake'
s.add_dependency 'rake-compiler'

s.add_development_dependency 'rake-compiler'
s.add_development_dependency 'rspec'
end

0 comments on commit c316b57

Please sign in to comment.