burke-monkeysupport 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ pkg
7
7
  *.so
8
8
  *.dll
9
9
  *.o
10
+ Makefile
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/burke/monkeysupport"
12
12
  gem.authors = ["Burke Libbey"]
13
13
  gem.files.include '{test,lib,ext}/**/*'
14
- gem.extensions = ["ext/extconf.rb"]
14
+ gem.extensions = ["ext/monkeysupport_c/extconf.rb"]
15
15
  gem.add_development_dependency "thoughtbot-shoulda"
16
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.7
@@ -0,0 +1,4 @@
1
+ require 'mkmf'
2
+ extension_name = 'monkeysupport_c'
3
+ dir_config(extension_name)
4
+ create_makefile(extension_name, 'src')
@@ -4,12 +4,13 @@
4
4
  #include <stdlib.h>
5
5
  #include <string.h>
6
6
 
7
- #include "inflector.h"
7
+ #include "activesupport_inflector.h"
8
8
  #include "ruby.h"
9
9
 
10
- VALUE inflector_underscore(VALUE self, VALUE rstr)
10
+ VALUE activesupport_inflector_underscore(VALUE self, VALUE rstr)
11
11
  {
12
- Check_Type(rstr, T_STRING);
12
+ // This is handled in the calling code. Every bit counts...
13
+ // Check_Type(rstr, T_STRING);
13
14
 
14
15
  VALUE ret = rb_str_new("", 0);
15
16
  char * ip = StringValuePtr(rstr);
@@ -41,10 +42,11 @@ VALUE inflector_underscore(VALUE self, VALUE rstr)
41
42
  return ret;
42
43
  }
43
44
 
44
- VALUE inflector_parameterize(VALUE self, VALUE str, VALUE sep)
45
+ VALUE activesupport_inflector_parameterize(VALUE self, VALUE str, VALUE sep)
45
46
  {
46
- Check_Type(str, T_STRING);
47
- Check_Type(sep, T_STRING);
47
+ // This is handled in the calling code. Every bit counts...
48
+ // Check_Type(str, T_STRING);
49
+ // Check_Type(sep, T_STRING);
48
50
 
49
51
  VALUE ret = rb_str_new("", 0);
50
52
  int sep_len = RSTRING_LEN(sep);
@@ -79,9 +81,10 @@ VALUE inflector_parameterize(VALUE self, VALUE str, VALUE sep)
79
81
  return ret;
80
82
  }
81
83
 
82
- VALUE inflector_dasherize(VALUE self, VALUE str)
84
+ VALUE activesupport_inflector_dasherize(VALUE self, VALUE str)
83
85
  {
84
- Check_Type(str, T_STRING);
86
+ // This is handled in the calling code. Every bit counts...
87
+ // Check_Type(str, T_STRING);
85
88
 
86
89
  char * out = ALLOC_N(char, RSTRING_LEN(str) + 1);
87
90
  char * ip = RSTRING_PTR(str);
@@ -100,9 +103,10 @@ VALUE inflector_dasherize(VALUE self, VALUE str)
100
103
  return rb_str_new(out, len);
101
104
  }
102
105
 
103
- VALUE inflector_demodulize(VALUE self, VALUE rstr)
106
+ VALUE activesupport_inflector_demodulize(VALUE self, VALUE rstr)
104
107
  {
105
- Check_Type(rstr, T_STRING);
108
+ // This is handled in the calling code. Every bit counts...
109
+ // Check_Type(rstr, T_STRING);
106
110
 
107
111
  char * str = RSTRING_PTR(rstr);
108
112
  char * ip = str;
@@ -123,9 +127,10 @@ VALUE inflector_demodulize(VALUE self, VALUE rstr)
123
127
  return ret;
124
128
  }
125
129
 
126
- VALUE inflector_camelize(VALUE self, VALUE str, VALUE first_letter_uppercase)
130
+ VALUE activesupport_inflector_camelize(VALUE self, VALUE str, VALUE first_letter_uppercase)
127
131
  {
128
- Check_Type(str, T_STRING);
132
+ // This is handled in the calling code. Every bit counts...
133
+ // Check_Type(str, T_STRING);
129
134
 
130
135
  VALUE ret = rb_str_new("", 0);
131
136
  bool cap_next = RTEST(first_letter_uppercase);
@@ -154,11 +159,12 @@ VALUE inflector_camelize(VALUE self, VALUE str, VALUE first_letter_uppercase)
154
159
  return ret;
155
160
  }
156
161
 
157
- VALUE inflector_foreign_key(VALUE self, VALUE str, VALUE use_underscore)
162
+ VALUE activesupport_inflector_foreign_key(VALUE self, VALUE str, VALUE use_underscore)
158
163
  {
159
- Check_Type(str, T_STRING);
164
+ // This is handled in the calling code. Every bit counts...
165
+ // Check_Type(str, T_STRING);
160
166
 
161
- VALUE ret = inflector_underscore(self, inflector_demodulize(self, str));
167
+ VALUE ret = activesupport_inflector_underscore(self, activesupport_inflector_demodulize(self, str));
162
168
 
163
169
  if (RTEST(use_underscore)) {
164
170
  rb_str_cat(ret, "_id", 3);
@@ -195,9 +201,10 @@ static char * itoa(int n)
195
201
  return ret;
196
202
  }
197
203
 
198
- VALUE inflector_ordinalize(VALUE self, VALUE rn)
204
+ VALUE activesupport_inflector_ordinalize(VALUE self, VALUE rn)
199
205
  {
200
- Check_Type(rn, T_FIXNUM);
206
+ // This is handled in the calling code. Every bit counts...
207
+ // Check_Type(rn, T_FIXNUM);
201
208
 
202
209
  int n = FIX2INT(rn);
203
210
  VALUE ret = rb_str_new2(itoa(n));
@@ -0,0 +1,10 @@
1
+ #pragma once
2
+ #include "ruby.h"
3
+
4
+ VALUE activesupport_inflector_underscore(VALUE self, VALUE str);
5
+ VALUE activesupport_inflector_parameterize(VALUE self, VALUE str, VALUE sep);
6
+ VALUE activesupport_inflector_dasherize(VALUE self, VALUE str);
7
+ VALUE activesupport_inflector_demodulize(VALUE self, VALUE str);
8
+ VALUE activesupport_inflector_camelize(VALUE self, VALUE str, VALUE first_letter_uppercase);
9
+ VALUE activesupport_inflector_foreign_key(VALUE self, VALUE str, VALUE use_underscore);
10
+ VALUE activesupport_inflector_ordinalize(VALUE self, VALUE n);
@@ -0,0 +1,19 @@
1
+ #include "activesupport_inflector.h"
2
+
3
+ #include "ruby.h"
4
+
5
+ void
6
+ Init_monkeysupport_c()
7
+ {
8
+ VALUE mMonkeySupport = rb_define_module("MonkeySupport");
9
+ VALUE cMSC = rb_define_class_under(mMonkeySupport, "C", rb_cObject);
10
+
11
+ /* ActiveSupport::ASC.camelize("my_string") */
12
+ rb_define_singleton_method(cMSC, "activesupport_inflector_camelize", activesupport_inflector_camelize, 2);
13
+ rb_define_singleton_method(cMSC, "activesupport_inflector_demodulize", activesupport_inflector_demodulize, 1);
14
+ rb_define_singleton_method(cMSC, "activesupport_inflector_dasherize", activesupport_inflector_dasherize, 1);
15
+ rb_define_singleton_method(cMSC, "activesupport_inflector_foreign_key", activesupport_inflector_foreign_key, 2);
16
+ rb_define_singleton_method(cMSC, "activesupport_inflector_ordinalize", activesupport_inflector_ordinalize, 1);
17
+ rb_define_singleton_method(cMSC, "activesupport_inflector_parameterize", activesupport_inflector_parameterize, 2);
18
+ rb_define_singleton_method(cMSC, "activesupport_inflector_underscore", activesupport_inflector_underscore, 1);
19
+ }
@@ -0,0 +1,115 @@
1
+
2
+ module ActiveSupport
3
+ module Inflector
4
+
5
+ extend MonkeySupport::Memoizable
6
+ extend MonkeySupport::CProxy
7
+
8
+ monkey_memoize :pluralize, :singularize, :humanize
9
+
10
+ monkey_c_proxy(:camelize,
11
+ :activesupport_inflector_camelize,
12
+ [:string, # lower_case_and_underscored_word
13
+ [:bool, true]]) # first_letter_in_uppercase
14
+
15
+ monkey_c_proxy(:underscore,
16
+ :activesupport_inflector_underscore,
17
+ [:string]) # camel_cased_word
18
+
19
+ monkey_c_proxy(:dasherize,
20
+ :activesupport_inflector_dasherize,
21
+ [:string]) # underscored_word
22
+
23
+ monkey_c_proxy(:foreign_key,
24
+ :activesupport_inflector_foreign_key,
25
+ [:string, # class_name
26
+ [:bool, true]]) # separate_class_name_and_id_with_underscore
27
+
28
+ monkey_c_proxy(:demodulize,
29
+ :activesupport_inflector_demodulize,
30
+ [:string]) # class_name_in_module
31
+
32
+ =begin
33
+ # TODO: Transliterate
34
+ monkey_c_proxy(:parameterize,
35
+ :activesupport_inflector_parameterize,
36
+ [:string, # string
37
+ [:string, '-']]) # separator
38
+
39
+ # TODO: .to_i
40
+ monkey_c_proxy(:ordinalize,
41
+ :activesupport_inflector_ordinalize,
42
+ [:fixnum]) # number
43
+
44
+ alias_method :__camelize, :camelize
45
+ def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
46
+ if MonkeySupport::TypeChecks.is_ascii_string?(lower_case_and_underscored_word)
47
+ MonkeySupport::C.activesupport_inflector_camelize(lower_case_and_underscored_word.to_s, first_letter_in_uppercase)
48
+ else
49
+ __camelize(lower_case_and_underscored_word, first_letter_in_uppercase)
50
+ end
51
+ end
52
+
53
+ alias_method :__underscore, :underscore
54
+ def underscore(camel_cased_word)
55
+ if MonkeySupport::TypeChecks.is_ascii_string?(camel_cased_word)
56
+ MonkeySupport::C.activesupport_inflector_underscore(camel_cased_word)
57
+ else
58
+ __underscore(camel_cased_word)
59
+ end
60
+ end
61
+
62
+ alias_method :__dasherize, :dasherize
63
+ def dasherize(underscored_word)
64
+ if MonkeySupport::TypeChecks.is_ascii_string?(underscored_word)
65
+ MonkeySupport::C.activesupport_inflector_dasherize(underscored_word)
66
+ else
67
+ __dasherize(underscored_word)
68
+ end
69
+ end
70
+
71
+ alias_method :__demodulize, :demodulize
72
+ def demodulize(class_name_in_module)
73
+ if MonkeySupport::TypeChecks.is_ascii_string?(class_name_in_module)
74
+ MonkeySupport::C.activesupport_inflector_demodulize(class_name_in_module)
75
+ else
76
+ __demodulize(class_name_in_module)
77
+ end
78
+ end
79
+
80
+ alias_method :__foreign_key, :foreign_key
81
+ def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
82
+ if MonkeySupport::TypeChecks.is_ascii_string?(class_name)
83
+ MonkeySupport::C.activesupport_inflector_foreign_key(class_name, separate_class_name_and_id_with_underscore)
84
+ else
85
+ __foreign_key(class_name, separate_class_name_and_id_with_underscore)
86
+ end
87
+ end
88
+
89
+ =end
90
+
91
+ alias_method :__parameterize, :parameterize
92
+ def parameterize(string, sep = '-')
93
+ parameterized_string = transliterate(string)
94
+ if (MonkeySupport::TypeChecks.is_ascii_string?(parameterized_string) \
95
+ && MonkeySupport::TypeChecks.is_ascii_string?(sep))
96
+
97
+ MonkeySupport::C.activesupport_inflector_parameterize(parameterized_string.to_s, sep)
98
+ else
99
+ __parameterize(string, sep)
100
+ end
101
+ end
102
+
103
+ alias_method :__ordinalize, :ordinalize
104
+ def ordinalize(number)
105
+ x = number.to_i
106
+ if (x.class == Fixnum)
107
+ MonkeySupport::C.activesupport_inflector_ordinalize(x)
108
+ else
109
+ __ordinalize(number)
110
+ end
111
+ end
112
+
113
+ end
114
+ end
115
+
@@ -0,0 +1,79 @@
1
+ module MonkeySupport
2
+ module CProxy
3
+
4
+ # Generates a proxy-to-C method.
5
+ #
6
+ # Parameters:
7
+ # - ruby_name -- the original name of the function to override
8
+ # - c_name -- the name of the C function in MonkeySupport::C to use
9
+ # - args -- list of arguments to funtion, by type.
10
+ #
11
+ # args example: [:string, :fixnum, [:string, '-'], [:bool true]]
12
+ # - takes a string, a fixnum, a string with default value '-', then a boolean
13
+ # with default value true.
14
+ #
15
+ # EXAMPLE:
16
+ #
17
+ # alias_method :__demodulize, :demodulize
18
+ # def demodulize(arg0)
19
+ # if ((MonkeySupport::TypeChecks.valid_string?(arg0)))
20
+ # MonkeySupport::C.activesupport_inflector_demodulize(arg0)
21
+ # else
22
+ # __demodulize(arg0)
23
+ # end
24
+ # end
25
+ def monkey_c_proxy(ruby_name, c_name, args)
26
+ checklist = Util::checklist(args)
27
+ arglist_with_defaults = Util::arglist(args, true)
28
+ arglist_without_defaults = Util::arglist(args, false)
29
+
30
+ if checklist
31
+ body = <<-EOS
32
+ if #{checklist}
33
+ MonkeySupport::C.#{c_name}(#{arglist_without_defaults})
34
+ else
35
+ __#{ruby_name}(#{arglist_without_defaults})
36
+ end
37
+ EOS
38
+ else
39
+ body = <<-EOS
40
+ MonkeySupport::C.#{c_name}(#{arglist_without_defaults})
41
+ EOS
42
+ end
43
+
44
+ function = <<-EOS
45
+ alias_method :__#{ruby_name}, :#{ruby_name}
46
+ def #{ruby_name}(#{arglist_with_defaults})
47
+ #{body}
48
+ end
49
+ EOS
50
+
51
+ class_eval(function)
52
+ end
53
+
54
+ module Util
55
+ def self.checklist(args)
56
+ checklist = []
57
+ args.each_with_index do |x, i|
58
+ arg = ((x.class == Array) ? x[0] : x) # support [:bool, true] notation.
59
+ if [:string, :fixnum].include?(arg)
60
+ checklist << "(MonkeySupport::TypeChecks.valid_#{arg}?(arg#{i}))"
61
+ end
62
+ end
63
+ return (checklist.empty? ? nil : "(#{checklist.join(' && ')})")
64
+ end
65
+
66
+ def self.arglist(args, include_defaults)
67
+ arglist = []
68
+ args.each_with_index do |arg, i|
69
+ if (arg.class == Array && include_defaults)
70
+ arglist << "arg#{i} = #{arg[1]}"
71
+ else
72
+ arglist << "arg#{i}"
73
+ end
74
+ end
75
+ return arglist.join(", ")
76
+ end
77
+ end
78
+ end
79
+ end
@@ -1,9 +1,10 @@
1
1
  module MonkeySupport
2
2
  module Memoizable
3
- # This is faster than AS::Memoizeable
3
+ # This is faster than AS::Memoizeable.
4
+ # Less featureful, however.
4
5
  def monkey_memoize(*methods)
5
6
  methods.each do |method|
6
- class_eval( <<"END"
7
+ class_eval <<EOS
7
8
 
8
9
  @__#{method} = {}
9
10
  alias_method :__#{method}, :#{method}
@@ -22,8 +23,7 @@ else
22
23
 
23
24
  end
24
25
 
25
- END
26
- )
26
+ EOS
27
27
 
28
28
  end
29
29
  end
@@ -1,24 +1,35 @@
1
1
  module MonkeySupport
2
2
  module TypeChecks
3
3
 
4
- def is_fixnum?(obj)
4
+ # NOTE: This exists, but it'll still be a lot faster to just call
5
+ # obj.class == Fixnum in the calling code, rather than resolving
6
+ # MonkeySupport::TypeChecks.is_fixnum? each time.
7
+ def self.valid_fixnum?(obj)
5
8
  obj.class == Fixnum
6
9
  end
7
10
 
11
+ # So I really don't want to deal with multiple string encodings in C.
12
+ # 1.8.7 doesn't support them, so it'll just check that we actually have a String.
13
+ # in 1.9, I need to check that the string is ascii-encoded too.
14
+ # It's also possible to force_encoding on a string that contains only ascii
15
+ # characters, but is non-ascii-encoded. I'm not currently handling that here,
16
+ # since this function returns a boolean, and I kind of want to keep it that way.
17
+ #
18
+ # Moral: Make sure your default string encoding in 1.9.1 is ASCII-8BIT.
8
19
  if '1.9'.respond_to?(:force_encoding)
9
20
  ASCII_ENCODING = Encoding.find("ASCII-8BIT")
10
21
  if Encoding.default_external == ASCII_ENCODING
11
- def is_ascii_string?(obj)
22
+ def self.valid_string?(obj)
12
23
  (obj.class == String) && obj.encoding == ASCII_ENCODING
13
24
  end
14
25
  else
15
- def is_ascii_string?(obj)
26
+ def self.valid_string?(obj)
16
27
  #TODO: Check ascii_only? and force_encoding here.
17
28
  (obj.class == String) && obj.encoding == ASCII_ENCODING
18
29
  end
19
30
  end
20
31
  else # <1.9
21
- def is_ascii_string?(obj)
32
+ def self.valid_string?(obj)
22
33
  obj.class == String
23
34
  end
24
35
  end
data/lib/monkeysupport.rb CHANGED
@@ -1,7 +1,7 @@
1
- module MonkeySupport
2
- end
1
+ require 'monkeysupport_c'
3
2
 
4
3
  require 'monkeysupport/type_checks'
4
+ require 'monkeysupport/c_proxy'
5
5
  require 'monkeysupport/memoizable'
6
- require 'active_support_c'
7
- require 'monkeysupport/inflector'
6
+
7
+ require 'monkeysupport/activesupport/inflector'
@@ -5,14 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{monkeysupport}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Burke Libbey"]
12
12
  s.date = %q{2009-09-04}
13
13
  s.description = %q{MonkeySupport provides C implementations for some of the more intensive string manipulation methods in activesupport. ActionView is up next.}
14
14
  s.email = %q{burke@burkelibbey.org}
15
- s.extensions = ["ext/extconf.rb"]
15
+ s.extensions = ["ext/monkeysupport_c/extconf.rb"]
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE",
18
18
  "README.rdoc"
@@ -24,32 +24,20 @@ Gem::Specification.new do |s|
24
24
  "README.rdoc",
25
25
  "Rakefile",
26
26
  "VERSION",
27
- "ext/Makefile",
28
- "ext/Makefile",
29
- "ext/active_support_c.c",
30
- "ext/active_support_c.c",
31
- "ext/core_ext/string/access.c",
32
- "ext/core_ext/string/access.c",
33
- "ext/core_ext/string/access.h",
34
- "ext/core_ext/string/access.h",
35
- "ext/core_ext/string/filters.c",
36
- "ext/core_ext/string/filters.c",
37
- "ext/core_ext/string/filters.h",
38
- "ext/core_ext/string/filters.h",
39
- "ext/core_ext/string/starts_ends_with.c",
40
- "ext/core_ext/string/starts_ends_with.c",
41
- "ext/core_ext/string/starts_ends_with.h",
42
- "ext/core_ext/string/starts_ends_with.h",
43
- "ext/extconf.rb",
44
- "ext/extconf.rb",
45
- "ext/inflector.c",
46
- "ext/inflector.c",
47
- "ext/inflector.h",
48
- "ext/inflector.h",
27
+ "ext/monkeysupport_c/extconf.rb",
28
+ "ext/monkeysupport_c/extconf.rb",
29
+ "ext/monkeysupport_c/src/activesupport_inflector.c",
30
+ "ext/monkeysupport_c/src/activesupport_inflector.c",
31
+ "ext/monkeysupport_c/src/activesupport_inflector.h",
32
+ "ext/monkeysupport_c/src/activesupport_inflector.h",
33
+ "ext/monkeysupport_c/src/monkeysupport_c.c",
34
+ "ext/monkeysupport_c/src/monkeysupport_c.c",
49
35
  "lib/monkeysupport.rb",
50
36
  "lib/monkeysupport.rb",
51
- "lib/monkeysupport/inflector.rb",
52
- "lib/monkeysupport/inflector.rb",
37
+ "lib/monkeysupport/activesupport/inflector.rb",
38
+ "lib/monkeysupport/activesupport/inflector.rb",
39
+ "lib/monkeysupport/c_proxy.rb",
40
+ "lib/monkeysupport/c_proxy.rb",
53
41
  "lib/monkeysupport/memoizable.rb",
54
42
  "lib/monkeysupport/memoizable.rb",
55
43
  "lib/monkeysupport/type_checks.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: burke-monkeysupport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burke Libbey
@@ -27,7 +27,7 @@ email: burke@burkelibbey.org
27
27
  executables: []
28
28
 
29
29
  extensions:
30
- - ext/extconf.rb
30
+ - ext/monkeysupport_c/extconf.rb
31
31
  extra_rdoc_files:
32
32
  - LICENSE
33
33
  - README.rdoc
@@ -38,19 +38,13 @@ files:
38
38
  - README.rdoc
39
39
  - Rakefile
40
40
  - VERSION
41
- - ext/Makefile
42
- - ext/active_support_c.c
43
- - ext/core_ext/string/access.c
44
- - ext/core_ext/string/access.h
45
- - ext/core_ext/string/filters.c
46
- - ext/core_ext/string/filters.h
47
- - ext/core_ext/string/starts_ends_with.c
48
- - ext/core_ext/string/starts_ends_with.h
49
- - ext/extconf.rb
50
- - ext/inflector.c
51
- - ext/inflector.h
41
+ - ext/monkeysupport_c/extconf.rb
42
+ - ext/monkeysupport_c/src/activesupport_inflector.c
43
+ - ext/monkeysupport_c/src/activesupport_inflector.h
44
+ - ext/monkeysupport_c/src/monkeysupport_c.c
52
45
  - lib/monkeysupport.rb
53
- - lib/monkeysupport/inflector.rb
46
+ - lib/monkeysupport/activesupport/inflector.rb
47
+ - lib/monkeysupport/c_proxy.rb
54
48
  - lib/monkeysupport/memoizable.rb
55
49
  - lib/monkeysupport/type_checks.rb
56
50
  - monkeysupport.gemspec
@@ -58,7 +52,6 @@ files:
58
52
  - test/test_helper.rb
59
53
  has_rdoc: false
60
54
  homepage: http://github.com/burke/monkeysupport
61
- licenses:
62
55
  post_install_message:
63
56
  rdoc_options:
64
57
  - --charset=UTF-8
@@ -79,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
72
  requirements: []
80
73
 
81
74
  rubyforge_project:
82
- rubygems_version: 1.3.5
75
+ rubygems_version: 1.2.0
83
76
  signing_key:
84
77
  specification_version: 3
85
78
  summary: Monkeypatching Rails with C since 2009
data/ext/Makefile DELETED
@@ -1,157 +0,0 @@
1
-
2
- SHELL = /bin/sh
3
-
4
- #### Start of system configuration section. ####
5
-
6
- srcdir = .
7
- topdir = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0
8
- hdrdir = $(topdir)
9
- VPATH = $(srcdir):$(topdir):$(hdrdir)
10
- exec_prefix = $(prefix)
11
- prefix = $(DESTDIR)/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr
12
- sharedstatedir = $(prefix)/com
13
- mandir = $(DESTDIR)/usr/share/man
14
- psdir = $(docdir)
15
- oldincludedir = $(DESTDIR)/usr/include
16
- localedir = $(datarootdir)/locale
17
- bindir = $(exec_prefix)/bin
18
- libexecdir = $(exec_prefix)/libexec
19
- sitedir = $(DESTDIR)/Library/Ruby/Site
20
- htmldir = $(docdir)
21
- vendorarchdir = $(vendorlibdir)/$(sitearch)
22
- includedir = $(prefix)/include
23
- infodir = $(DESTDIR)/usr/share/info
24
- vendorlibdir = $(vendordir)/$(ruby_version)
25
- sysconfdir = $(prefix)/etc
26
- libdir = $(exec_prefix)/lib
27
- sbindir = $(exec_prefix)/sbin
28
- rubylibdir = $(libdir)/ruby/$(ruby_version)
29
- docdir = $(datarootdir)/doc/$(PACKAGE)
30
- dvidir = $(docdir)
31
- vendordir = $(libdir)/ruby/vendor_ruby
32
- datarootdir = $(prefix)/share
33
- pdfdir = $(docdir)
34
- archdir = $(rubylibdir)/$(arch)
35
- sitearchdir = $(sitelibdir)/$(sitearch)
36
- datadir = $(datarootdir)
37
- localstatedir = $(prefix)/var
38
- sitelibdir = $(sitedir)/$(ruby_version)
39
-
40
- CC = gcc
41
- LIBRUBY = $(LIBRUBY_SO)
42
- LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
43
- LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
44
- LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)
45
-
46
- RUBY_EXTCONF_H =
47
- CFLAGS = -fno-common -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common $(cflags)
48
- INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
49
- DEFS =
50
- CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags)
51
- CXXFLAGS = $(CFLAGS)
52
- ldflags = -L. -arch i386 -arch x86_64
53
- dldflags =
54
- archflag =
55
- DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
56
- LDSHARED = cc -arch i386 -arch x86_64 -pipe -bundle -undefined dynamic_lookup
57
- AR = ar
58
- EXEEXT =
59
-
60
- RUBY_INSTALL_NAME = ruby
61
- RUBY_SO_NAME = ruby
62
- arch = universal-darwin10.0
63
- sitearch = universal-darwin10.0
64
- ruby_version = 1.8
65
- ruby = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
66
- RUBY = $(ruby)
67
- RM = rm -f
68
- MAKEDIRS = mkdir -p
69
- INSTALL = /usr/bin/install -c
70
- INSTALL_PROG = $(INSTALL) -m 0755
71
- INSTALL_DATA = $(INSTALL) -m 644
72
- COPY = cp
73
-
74
- #### End of system configuration section. ####
75
-
76
- preload =
77
-
78
- libpath = . $(libdir)
79
- LIBPATH = -L. -L$(libdir)
80
- DEFFILE =
81
-
82
- CLEANFILES = mkmf.log
83
- DISTCLEANFILES =
84
-
85
- extout =
86
- extout_prefix =
87
- target_prefix =
88
- LOCAL_LIBS =
89
- LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl
90
- SRCS = active_support_c.c inflector.c
91
- OBJS = active_support_c.o inflector.o
92
- TARGET = active_support_c
93
- DLLIB = $(TARGET).bundle
94
- EXTSTATIC =
95
- STATIC_LIB =
96
-
97
- BINDIR = $(bindir)
98
- RUBYCOMMONDIR = $(sitedir)$(target_prefix)
99
- RUBYLIBDIR = $(sitelibdir)$(target_prefix)
100
- RUBYARCHDIR = $(sitearchdir)$(target_prefix)
101
-
102
- TARGET_SO = $(DLLIB)
103
- CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
104
- CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
105
-
106
- all: $(DLLIB)
107
- static: $(STATIC_LIB)
108
-
109
- clean:
110
- @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
111
-
112
- distclean: clean
113
- @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
114
- @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
115
-
116
- realclean: distclean
117
- install: install-so install-rb
118
-
119
- install-so: $(RUBYARCHDIR)
120
- install-so: $(RUBYARCHDIR)/$(DLLIB)
121
- $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
122
- $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
123
- install-rb: pre-install-rb install-rb-default
124
- install-rb-default: pre-install-rb-default
125
- pre-install-rb: Makefile
126
- pre-install-rb-default: Makefile
127
- $(RUBYARCHDIR):
128
- $(MAKEDIRS) $@
129
-
130
- site-install: site-install-so site-install-rb
131
- site-install-so: install-so
132
- site-install-rb: install-rb
133
-
134
- .SUFFIXES: .c .m .cc .cxx .cpp .C .o
135
-
136
- .cc.o:
137
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
138
-
139
- .cxx.o:
140
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
141
-
142
- .cpp.o:
143
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
144
-
145
- .C.o:
146
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
147
-
148
- .c.o:
149
- $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
150
-
151
- $(DLLIB): $(OBJS)
152
- @-$(RM) $@
153
- $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
154
-
155
-
156
-
157
- $(OBJS): ruby.h defines.h
@@ -1,27 +0,0 @@
1
- #include "inflector.h"
2
- #include "core_ext/string/starts_ends_with.h"
3
- #include "core_ext/string/access.h"
4
- #include "core_ext/string/filters.h"
5
-
6
- #include "ruby.h"
7
-
8
- void
9
- Init_active_support_c()
10
- {
11
- VALUE mActiveSupport = rb_define_module("ActiveSupport");
12
- VALUE cASC = rb_define_class_under(mActiveSupport, "ASC", rb_cObject);
13
-
14
- /* ActiveSupport::ASC.camelize("my_string") */
15
- rb_define_singleton_method(cASC, "inflector_camelize", inflector_camelize, 2);
16
- rb_define_singleton_method(cASC, "inflector_demodulize", inflector_demodulize, 1);
17
- rb_define_singleton_method(cASC, "inflector_dasherize", inflector_dasherize, 1);
18
- rb_define_singleton_method(cASC, "inflector_foreign_key", inflector_foreign_key, 2);
19
- rb_define_singleton_method(cASC, "inflector_ordinalize", inflector_ordinalize, 1);
20
- rb_define_singleton_method(cASC, "inflector_parameterize", inflector_parameterize, 2);
21
- rb_define_singleton_method(cASC, "inflector_underscore", inflector_underscore, 1);
22
-
23
- /* rb_define_singleton_method(cASC, "core_ext_string_at", core_ext_string_at, 1); */
24
- /* rb_define_singleton_method(cASC, "core_ext_string_to", core_ext_string_to, 1); */
25
- /* rb_define_singleton_method(cASC, "core_ext_string_from", core_ext_string_from, 1); */
26
- /* rb_define_singleton_method(cASC, "core_ext_string_first", core_ext_string_first, 1); */
27
- }
@@ -1,157 +0,0 @@
1
- #include <assert.h>
2
- #include <string.h>
3
- #include <stdlib.h>
4
-
5
- #include "access.h"
6
- #include "ruby.h"
7
-
8
- VALUE
9
- core_ext_string_at(VALUE rstr, VALUE rposition)
10
- {
11
- Check_Type(rstr, T_STRING);
12
- Check_Type(rposition, T_FIXNUM);
13
-
14
- int position = FIX2INT(rposition);
15
- int len = RString(rstr)->len;
16
- struct RString *ret;
17
-
18
- if (position < 0) { // Allow for negative indices
19
- position += len;
20
- }
21
-
22
- if ((position < 0) || (position > len)) { // still out of bounds
23
- ret->ptr = calloc(1, sizeof(char));
24
- ret->len = 0;
25
- } else {
26
- len -= position;
27
- ret->len = len;
28
- ret->ptr = malloc((len+1)*sizeof(char));
29
- memcpy(ret->ptr, RString(rstr)->ptr + position, len);
30
- }
31
-
32
- return ret;
33
- }
34
-
35
- void
36
- test_core_ext_string_at()
37
- {
38
- char *test = "0123456789";
39
- assert(!strcmp(core_ext_string_at(test, 0), "0"));
40
- assert(!strcmp(core_ext_string_at(test, 1), "1"));
41
- assert(!strcmp(core_ext_string_at(test, 9), "9"));
42
- assert(!strcmp(core_ext_string_at(test, 10), ""));
43
- assert(!strcmp(core_ext_string_at(test, 15), ""));
44
- assert(!strcmp(core_ext_string_at(test, -1), "9"));
45
- assert(!strcmp(core_ext_string_at(test, -2), "8"));
46
- assert(!strcmp(core_ext_string_at(test, -10), "0"));
47
- assert(!strcmp(core_ext_string_at(test, -11), ""));
48
- assert(!strcmp(core_ext_string_at(test, -15), ""));
49
- }
50
-
51
- VALUE
52
- core_ext_string_first(VALUE rstr, VALUE rposition)
53
- {
54
- Check_Type(rstr, T_STRING);
55
- Check_Type(rposition, T_FIXNUM);
56
-
57
- //int len = strlen(str);
58
- return Qnil;
59
- }
60
-
61
- void
62
- test_core_ext_string_first()
63
- {
64
- char *test = "0123456789";
65
- assert(!strcmp(core_ext_string_first(test, 0), "0123456789"));
66
- assert(!strcmp(core_ext_string_first(test, 1), "0"));
67
- assert(!strcmp(core_ext_string_first(test, 2), "01"));
68
- assert(!strcmp(core_ext_string_first(test, 9), "012345678"));
69
- assert(!strcmp(core_ext_string_first(test, 10), "0123456789"));
70
- assert(!strcmp(core_ext_string_first(test, 15), "0123456789"));
71
- assert(!strcmp(core_ext_string_first(test, -1), "012345678"));
72
- assert(!strcmp(core_ext_string_first(test, -2), "01234567"));
73
- assert(!strcmp(core_ext_string_first(test, -10), ""));
74
- assert(!strcmp(core_ext_string_first(test, -11), ""));
75
- assert(!strcmp(core_ext_string_first(test, -15), ""));
76
- }
77
-
78
- VALUE
79
- core_ext_string_from(VALUE rstr, VALUE rposition)
80
- {
81
- Check_Type(rstr, T_STRING);
82
- Check_Type(rposition, T_FIXNUM);
83
-
84
- int len = RCORE_EXT_STRING_LEN(rstr)
85
-
86
- if (position < 0) {
87
- position += len; // -10 + 10 = 0
88
- }
89
-
90
- if (position > len || position < 0) {
91
- position = len;
92
- }
93
-
94
- return str + position;
95
- }
96
-
97
- void
98
- test_core_ext_string_from()
99
- {
100
- char *test = "0123456789";
101
- assert(!strcmp(core_ext_string_from(test, 0), "0123456789"));
102
- assert(!strcmp(core_ext_string_from(test, 1), "123456789"));
103
- assert(!strcmp(core_ext_string_from(test, 9), "9"));
104
- assert(!strcmp(core_ext_string_from(test, 10), ""));
105
- assert(!strcmp(core_ext_string_from(test, 15), ""));
106
- assert(!strcmp(core_ext_string_from(test, -1), "9"));
107
- assert(!strcmp(core_ext_string_from(test, -2), "89"));
108
- assert(!strcmp(core_ext_string_from(test, -10), "0123456789"));
109
- assert(!strcmp(core_ext_string_from(test, -11), ""));
110
- assert(!strcmp(core_ext_string_from(test, -15), ""));
111
- }
112
-
113
- VALUE
114
- core_ext_string_to(VALUE rstr, VALUE rposition)
115
- {
116
- int position = FIX2INT(rposition);
117
-
118
- int len = RString(rstr)->len;
119
- struct RString ret;
120
-
121
- if (position < 0) { // allow for negative indices
122
- position += len;
123
- }
124
-
125
- if (position > len) { // past top bound
126
- ret->len = len;
127
- ret->ptr = malloc((len+1)*sizeof(char));
128
- memcpy(ret->ptr, RString(rstr)->ptr, len);
129
- } else if (position < 0) { // under bottom bound
130
- ret->ptr = calloc(1, sizeof(char));
131
- ret->len = 0;
132
- } else {
133
- ret->len = position + 1;
134
- ret->ptr = malloc((position + 2) * sizeof(char));
135
-
136
- memcpy(ret->ptr, RString(rstr)->ptr, position+1);
137
- *(ret->ptr + position + 1) = '\0';
138
- }
139
-
140
- return ret;
141
- }
142
-
143
- void
144
- test_core_ext_string_to()
145
- {
146
- char *test = "0123456789";
147
- assert(!strcmp(core_ext_string_to(test, 0), "0"));
148
- assert(!strcmp(core_ext_string_to(test, 1), "01"));
149
- assert(!strcmp(core_ext_string_to(test, 9), "0123456789"));
150
- assert(!strcmp(core_ext_string_to(test, 10), "0123456789"));
151
- assert(!strcmp(core_ext_string_to(test, 15), "0123456789"));
152
- assert(!strcmp(core_ext_string_to(test, -1), "0123456789"));
153
- assert(!strcmp(core_ext_string_to(test, -2), "012345678"));
154
- assert(!strcmp(core_ext_string_to(test, -10), "0"));
155
- assert(!strcmp(core_ext_string_to(test, -11), ""));
156
- assert(!strcmp(core_ext_string_to(test, -15), ""));
157
- }
@@ -1,6 +0,0 @@
1
- #pragma once
2
-
3
- #include "ruby.h"
4
-
5
- VALUE core_ext_string_from(VALUE str, VALUE position);
6
- VALUE core_ext_string_to(VALUE str, VALUE position);
@@ -1,52 +0,0 @@
1
- #include <stdbool.h>
2
- #include <string.h>
3
- #include <stdlib.h>
4
-
5
- #include "filters.h"
6
-
7
- static bool /* Ugly, but fast! */
8
- _is_space(char chr)
9
- {
10
- if (chr > 13) {
11
- return (chr == 32);
12
- } else {
13
- return (chr == 9 || chr == 10 || chr == 12 || chr == 13);
14
- }
15
- }
16
-
17
- VALUE
18
- string_squish(VALUE rstr)
19
- {
20
- int ilen = RString(rstr)->len;
21
- int olen = ilen;
22
- char *ip = RString(rstr)->ptr;
23
- bool in_space = true;
24
- int i;
25
- struct RString ret;
26
- ret->ptr = (char *)malloc(len+1)*(sizeof (char));
27
- char *op = ret->ptr;
28
-
29
-
30
- for (i = 0; i < ilen; i++, ip++) {
31
- if (_is_space(*ip)) {
32
- if (in_space) {
33
- olen--;
34
- } else {
35
- in_space = true;
36
- *op++ = ' ';
37
- }
38
- } else {
39
- in_space = false;
40
- *op++ = *ip;
41
- }
42
- }
43
-
44
- if (*(op-1) == ' ') {
45
- *(op-1) = '\0';
46
- olen--;
47
- }
48
-
49
- ret->len = olen;
50
- return ret;
51
- }
52
-
@@ -1,5 +0,0 @@
1
- #pragma once
2
-
3
- #include "ruby.h"
4
-
5
- VALUE string_squish(VALUE rstr);
@@ -1,68 +0,0 @@
1
- #include <assert.h>
2
- #include <stdbool.h>
3
- #include <string.h>
4
- #include <ctype.h>
5
-
6
- #include "starts_ends_with.h"
7
- #include "ruby.h"
8
-
9
- VALUE
10
- string_starts_with(VALUE str, VALUE substr)
11
- {
12
- int sublen = RString(substr)->len;
13
- char *p1 = RString(str)->ptr;
14
- char *p2 = RString(substr)->ptr;
15
-
16
- while (sublen--) {
17
- if (*p1++ != *p2++) {
18
- return Qfalse;
19
- }
20
- }
21
-
22
- return Qtrue;
23
- }
24
-
25
- void
26
- test_starts_with()
27
- {
28
- assert(string_starts_with("asdf", "") == true);
29
- assert(string_starts_with("asdf", "asdfasdf") == false);
30
- assert(string_starts_with("", "asdfasdf") == false);
31
- assert(string_starts_with("", "") == true);
32
- }
33
-
34
- VALUE
35
- string_ends_with(VALUE str, VALUE substr)
36
- {
37
- int l_str, l_substr;
38
- char *p_str, *p_substr;
39
-
40
- l_str = RString(str)->len;
41
- l_substr = RString(substr)->len;
42
-
43
- if (l_substr > l_str) {
44
- return Qfalse;
45
- }
46
-
47
- p_str = RString(str)->ptr + l_str;
48
- p_substr = RString(substr)->ptr + l_substr;
49
-
50
-
51
- while (p_substr >= RString(substr)->ptr) {
52
- if (*p_substr-- != *p_str--) {
53
- return Qfale;
54
- }
55
- }
56
-
57
- return Qtrue;
58
- }
59
-
60
- void
61
- test_ends_with()
62
- {
63
- assert(string_ends_with("asdf", "") == true);
64
- assert(string_ends_with("asdf", "asdfasdf") == false);
65
- assert(string_ends_with("", "asdfasdf") == false);
66
- assert(string_ends_with("", "") == true);
67
- }
68
-
@@ -1,6 +0,0 @@
1
- #pragma once
2
-
3
- #include "ruby.h"
4
-
5
- VALUE string_starts_with(VALUE str, VALUE substr);
6
- VALUE string_ends_with(VALUE str, VALUE substr);
data/ext/extconf.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'mkmf'
2
- extension_name = 'active_support_c'
3
- dir_config(extension_name)
4
- create_makefile(extension_name)
data/ext/inflector.h DELETED
@@ -1,10 +0,0 @@
1
- #pragma once
2
- #include "ruby.h"
3
-
4
- VALUE inflector_underscore(VALUE self, VALUE str);
5
- VALUE inflector_parameterize(VALUE self, VALUE str, VALUE sep);
6
- VALUE inflector_dasherize(VALUE self, VALUE str);
7
- VALUE inflector_demodulize(VALUE self, VALUE str);
8
- VALUE inflector_camelize(VALUE self, VALUE str, VALUE first_letter_uppercase);
9
- VALUE inflector_foreign_key(VALUE self, VALUE str, VALUE use_underscore);
10
- VALUE inflector_ordinalize(VALUE self, VALUE n);
@@ -1,75 +0,0 @@
1
- module ActiveSupport
2
- module Inflector
3
-
4
- extend MonkeySupport::Memoizable
5
- extend MonkeySupport::TypeChecks
6
- monkey_memoize :pluralize, :singularize, :humanize
7
-
8
- alias_method :__camelize, :camelize
9
- def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
10
- if is_ascii_string?(lower_case_and_underscored_word)
11
- ActiveSupport::ASC.inflector_camelize(lower_case_and_underscored_word.to_s, first_letter_in_uppercase)
12
- else
13
- __camelize(lower_case_and_underscored_word, first_letter_in_uppercase)
14
- end
15
- end
16
-
17
- alias_method :__underscore, :underscore
18
- def underscore(camel_cased_word)
19
- if is_ascii_string?(camel_cased_word)
20
- ActiveSupport::ASC.inflector_underscore(camel_cased_word)
21
- else
22
- __underscore(camel_cased_word)
23
- end
24
- end
25
-
26
- alias_method :__dasherize, :dasherize
27
- def dasherize(underscored_word)
28
- if is_ascii_string?(underscored_word)
29
- ActiveSupport::ASC.inflector_dasherize(underscored_word)
30
- else
31
- __dasherize(underscored_word)
32
- end
33
- end
34
-
35
- alias_method :__demodulize, :demodulize
36
- def demodulize(class_name_in_module)
37
- if is_ascii_string?(class_name_in_module)
38
- ActiveSupport::ASC.inflector_demodulize(class_name_in_module)
39
- else
40
- __demodulize(class_name_in_module)
41
- end
42
- end
43
-
44
- alias_method :__parameterize, :parameterize
45
- def parameterize(string, sep = '-')
46
- parameterized_string = transliterate(string)
47
- if is_ascii_string?(parameterized_string) && is_ascii_string?(sep)
48
- ActiveSupport::ASC.inflector_parameterize(parameterized_string.to_s, sep)
49
- else
50
- __parameterize(string, sep)
51
- end
52
- end
53
-
54
- alias_method :__foreign_key, :foreign_key
55
- def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
56
- if is_ascii_string?(class_name)
57
- ActiveSupport::ASC.inflector_foreign_key(class_name, separate_class_name_and_id_with_underscore)
58
- else
59
- __foreign_key(class_name, separate_class_name_and_id_with_underscore)
60
- end
61
- end
62
-
63
- alias_method :__ordinalize, :ordinalize
64
- def ordinalize(number)
65
- x = number.to_i
66
- if is_fixnum?(x)
67
- ActiveSupport::ASC.inflector_ordinalize(number.to_i)
68
- else
69
- __ordinalize(number)
70
- end
71
- end
72
-
73
- end
74
- end
75
-