Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #2

Merged
merged 4 commits into from
Nov 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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