fast_xs 0.6 → 0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -7,12 +7,10 @@
7
7
  http://intertwingly.net/stories/2005/09/28/xchar.rb
8
8
  http://intertwingly.net/blog/2005/09/28/XML-Cleansing
9
9
 
10
- _why also packages a slightly modified version in the latest version
11
- of Hpricot (not-yet-released) that also escapes '"' to """ (which
12
- is optional).
10
+ _why also packages an older version with Hpricot (patch in progress).
11
+ It should be compatible with the latest version of this code.
13
12
 
14
- This is an exact translation (to the best of my knowledge :) of Sam's
15
- original implementation, so it does not escape """. The version
16
- of XML::Builder packaged with Rails also uses Sam's version, and
13
+ This is an almost exact translation (to the best of my knowledge :) of
14
+ Sam's original implementation, but it does escape """.
17
15
  XML::Builder as packaged in Rails 2.0 will be automatically use
18
16
  fast_xs if available.
data/Rakefile CHANGED
@@ -13,16 +13,16 @@ begin
13
13
  rev = Time.at(rev.split("\n")[1].to_i).strftime('%Y%m%d.%H%M%S')
14
14
  rescue
15
15
  end
16
- version ||= ENV['VERSION'] || '0.6' + (rev && rev.length > 0 ? ".#{rev}" : '')
16
+ version ||= ENV['VERSION'] || '0.7' + (rev && rev.length > 0 ? ".#{rev}" : '')
17
17
  pkg = "#{name}-#{version}"
18
18
  bin = "*.{so,o}"
19
19
  archlib = "lib/#{::Config::CONFIG['arch']}"
20
- CLEAN.include ["ext/fast_xs/#{bin}", "lib/**/#{bin}",
21
- 'ext/fast_xs/Makefile', '**/.*.sw?', '*.gem', '.config',
20
+ CLEAN.include ["ext/**/#{bin}", "lib/**/#{bin}",
21
+ 'ext/**/Makefile', '**/.*.sw?', '*.gem', '.config',
22
22
  'pkg']
23
23
  rdoc_opts = ['--quiet', '--title', 'fast_xs notes', '--main', 'README',
24
24
  '--inline-source']
25
- pkg_files = %w(CHANGELOG COPYING README Rakefile) +
25
+ pkg_files = %w(COPYING README Rakefile) +
26
26
  Dir.glob("{test,lib}/**/*.rb") +
27
27
  Dir.glob("ext/**/*.{c,rb,h}")
28
28
 
@@ -33,12 +33,12 @@ spec = Gem::Specification.new do |s|
33
33
  s.platform = Gem::Platform::RUBY
34
34
  s.has_rdoc = true
35
35
  s.rdoc_options += rdoc_opts
36
- s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
36
+ s.extra_rdoc_files = ["README", "COPYING"]
37
37
  s.summary = "excessively fast escaping"
38
38
  s.description = s.summary
39
39
  s.author = "Eric Wong"
40
40
  s.email = 'normalperson@yhbt.net'
41
- s.homepage = 'http://bogonips.org/fast_xs/'
41
+ s.homepage = 'http://bogomips.org/fast_xs/'
42
42
  s.files = pkg_files
43
43
  s.require_paths = [archlib, "lib"]
44
44
  s.extensions = FileList["ext/**/extconf.rb"].to_a
@@ -74,7 +74,7 @@ Rake::RDocTask.new do |rdoc|
74
74
  rdoc.rdoc_dir = 'doc/rdoc'
75
75
  rdoc.options += rdoc_opts
76
76
  rdoc.main = "README"
77
- rdoc.rdoc_files.add ['README', 'CHANGELOG', 'COPYING' ]
77
+ rdoc.rdoc_files.add ['README', 'COPYING' ]
78
78
  end
79
79
 
80
80
  Rake::GemPackageTask.new(spec) do |p|
@@ -82,7 +82,7 @@ Rake::GemPackageTask.new(spec) do |p|
82
82
  p.gem_spec = spec
83
83
  end
84
84
 
85
- ['fast_xs'].each do |extension|
85
+ %w(fast_xs fast_xs_extra).each do |extension|
86
86
  ext = "ext/#{extension}"
87
87
  ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
88
88
  ext_files = FileList[
@@ -114,7 +114,7 @@ task "lib" do
114
114
  end
115
115
 
116
116
  desc "Compiles the Ruby extension"
117
- task :compile => [:fast_xs] do
117
+ task :compile => %w(fast_xs fast_xs_extra) do
118
118
  if Dir.glob(File.join(archlib,"fast_xs.*")).empty?
119
119
  STDERR.puts 'Gem failed to build'
120
120
  exit(1)
@@ -123,9 +123,9 @@ end
123
123
 
124
124
  task :install do
125
125
  sh %{rake package}
126
- sh %{sudo gem install pkg/#{name}-#{version}}
126
+ sh %{gem install pkg/#{name}-#{version}}
127
127
  end
128
128
 
129
129
  task :uninstall => [:clean] do
130
- sh %{sudo gem uninstall #{name}}
130
+ sh %{gem uninstall #{name}}
131
131
  end
@@ -1,7 +1,5 @@
1
1
  #include <ruby.h>
2
2
  #include <assert.h>
3
- #include <sys/time.h>
4
- #include <sys/resource.h>
5
3
  #include "ruby_1_9_compat.h"
6
4
  #include "fast_xs_type.h"
7
5
  #include "gcc.h"
@@ -82,6 +80,8 @@ static size_t escape(char *buf, int n)
82
80
  /* handle ASCII first */
83
81
  if (likely(n < 128)) {
84
82
  if (likely(n >= 0x20 || n == '\t' || n == '\n' || n == '\r')) {
83
+ if (unlikely(n == '"'))
84
+ return_const_len("&quot;");
85
85
  if (unlikely(n == '&'))
86
86
  return_const_len("&amp;");
87
87
  if (unlikely(n == '<'))
@@ -144,6 +144,8 @@ static VALUE fast_xs(VALUE self)
144
144
  tmp++) {
145
145
  int n = NUM2INT(*tmp);
146
146
  if (likely(n < 128)) {
147
+ if (unlikely(n == '"'))
148
+ s_len += (sizeof("&quot;") - 2);
147
149
  if (unlikely(n == '&'))
148
150
  s_len += (sizeof("&amp;") - 2);
149
151
  if (unlikely(n == '>' || n == '<'))
@@ -166,158 +168,6 @@ static VALUE fast_xs(VALUE self)
166
168
  return rv;
167
169
  }
168
170
 
169
- /*
170
- * This is coding agnostic, and works on each byte, so some multibyte
171
- * character sets may not be fully supported (but UTF-8 should be).
172
- * This is meant to be 100% compatible with the
173
- * ERB::Util::escape_html and CGI::escapeHTML methods
174
- */
175
- static VALUE fast_xs_html(VALUE self)
176
- {
177
- long i;
178
- char *s;
179
- size_t new_len = RSTRING_LEN(self);
180
- char *new_str;
181
- VALUE rv;
182
-
183
- for (s = RSTRING_PTR(self), i = RSTRING_LEN(self); --i >= 0; ++s) {
184
- if (unlikely(*s == '&'))
185
- new_len += (sizeof("&amp;") - 2);
186
- else if (unlikely(*s == '<' || *s == '>'))
187
- new_len += (sizeof("&gt;") - 2);
188
- else if (unlikely(*s == '"'))
189
- new_len += (sizeof("&quot;") - 2);
190
- }
191
-
192
- rv = rb_str_new(NULL, new_len);
193
- new_str = RSTRING_PTR(rv);
194
-
195
- #define append_const(buf, x) do { \
196
- buf = memcpy(buf, x, sizeof(x) - 1) + sizeof(x) - 1; \
197
- } while (0)
198
-
199
- for (s = RSTRING_PTR(self), i = RSTRING_LEN(self); --i >= 0; ++s) {
200
- if (unlikely(*s == '&'))
201
- append_const(new_str, "&amp;");
202
- else if (unlikely(*s == '<'))
203
- append_const(new_str, "&lt;");
204
- else if (unlikely(*s == '>'))
205
- append_const(new_str, "&gt;");
206
- else if (unlikely(*s == '"'))
207
- append_const(new_str, "&quot;");
208
- else
209
- *new_str++ = *s;
210
- }
211
-
212
- #undef append_const
213
-
214
- return rv;
215
- }
216
-
217
- #define CGI_URI_OK(x) \
218
- ((x >= 'a' && x <= 'z') || \
219
- (x >= 'A' && x <= 'Z') || \
220
- (x >= '0' && x <= '9') || \
221
- (x == '.' || x == '-' || x == '_'))
222
-
223
- static inline VALUE _xs_uri_encode(VALUE self, const unsigned int space_to_plus)
224
- {
225
- long i;
226
- char *s;
227
- size_t new_len = RSTRING_LEN(self);
228
- char *new_str;
229
- VALUE rv;
230
-
231
- for (s = RSTRING_PTR(self), i = RSTRING_LEN(self); --i >= 0; ++s) {
232
- if (likely(CGI_URI_OK(*s)) || (space_to_plus && *s == ' '))
233
- continue;
234
- new_len += 2;
235
- }
236
-
237
- rv = rb_str_new(NULL, new_len);
238
- new_str = RSTRING_PTR(rv);
239
-
240
- for (s = RSTRING_PTR(self), i = RSTRING_LEN(self); --i >= 0; ++s) {
241
- if (likely(CGI_URI_OK(*s)))
242
- *new_str++ = *s;
243
- else if (space_to_plus && *s == ' ')
244
- *new_str++ = '+';
245
- else {
246
- static const char cgi_digitmap[] = "0123456789ABCDEF";
247
- new_str[2] = cgi_digitmap[(*s % 16)];
248
- new_str[1] = cgi_digitmap[((*s/16) % 16)];
249
- new_str[0] = '%';
250
- new_str += 3;
251
- }
252
- }
253
-
254
- return rv;
255
- }
256
-
257
- /*
258
- * Compatible with ERB::Util::url_encode / ERB::Util::u, this iterates
259
- * through each byte, so multibyte character sets may not supported (but
260
- * UTF-8 should be).
261
- */
262
- static VALUE fast_xs_url(VALUE self)
263
- {
264
- return _xs_uri_encode(self, 0);
265
- }
266
-
267
- /*
268
- * Compatible with CGI::escape(), this iterates through each byte, so
269
- * multibyte character sets may not supported (but UTF-8 should be).
270
- */
271
- static VALUE fast_xs_cgi(VALUE self)
272
- {
273
- return _xs_uri_encode(self, 1);
274
- }
275
-
276
- static VALUE _uxs_uri(VALUE self, const unsigned int plus_to_space)
277
- {
278
- char *s, *new_str;
279
- long i;
280
- size_t new_len = RSTRING_LEN(self);
281
- VALUE rv;
282
-
283
- for (s = RSTRING_PTR(self), i = RSTRING_LEN(self);
284
- --i >= 0;
285
- ++s) {
286
- if (unlikely(*s == '%') &&
287
- likely(is_hex(s[1])) &&
288
- likely(is_hex(s[2]))) {
289
- new_len -= 2;
290
- s += 2;
291
- i -= 2;
292
- }
293
- }
294
-
295
- rv = rb_str_new(NULL, new_len);
296
- new_str = RSTRING_PTR(rv);
297
-
298
- for (s = RSTRING_PTR(self), i = RSTRING_LEN(self);
299
- --i >= 0;
300
- ++s, ++new_str) {
301
- if (plus_to_space && unlikely(*s == '+'))
302
- *new_str = ' ';
303
- else if (unlikely(*s == '%') &&
304
- likely(is_hex(s[1])) &&
305
- likely(is_hex(s[2]))) {
306
- *new_str = hexpair_to_int(s[1], s[2]);
307
- s += 2;
308
- i -= 2;
309
- } else
310
- *new_str = *s;
311
- }
312
-
313
- return rv;
314
- }
315
-
316
- static VALUE fast_uxs_cgi(VALUE self)
317
- {
318
- return _uxs_uri(self, 1);
319
- }
320
-
321
171
  void Init_fast_xs(void)
322
172
  {
323
173
  assert(cp_1252[159 - 128] == 376); /* just in case I skipped a line */
@@ -329,8 +179,4 @@ void Init_fast_xs(void)
329
179
  rb_global_variable(&C_fmt);
330
180
 
331
181
  rb_define_method(rb_cString, "fast_xs", fast_xs, 0);
332
- rb_define_method(rb_cString, "fast_xs_html", fast_xs_html, 0);
333
- rb_define_method(rb_cString, "fast_xs_cgi", fast_xs_cgi, 0);
334
- rb_define_method(rb_cString, "fast_uxs_cgi", fast_uxs_cgi, 0);
335
- rb_define_method(rb_cString, "fast_xs_url", fast_xs_url, 0);
336
182
  }
@@ -0,0 +1,5 @@
1
+ require 'mkmf'
2
+ have_header('assert.h') or exit
3
+ find_header('gcc.h', '../fast_xs')
4
+ dir_config('fast_xs_extra')
5
+ create_makefile('fast_xs_extra')
@@ -0,0 +1,165 @@
1
+ #include <ruby.h>
2
+ #include <assert.h>
3
+ #include "ruby_1_9_compat.h"
4
+ #include "fast_xs_type.h"
5
+ #include "gcc.h"
6
+
7
+ /*
8
+ * This is coding agnostic, and works on each byte, so some multibyte
9
+ * character sets may not be fully supported (but UTF-8 should be).
10
+ * This is meant to be 100% compatible with the
11
+ * ERB::Util::escape_html and CGI::escapeHTML methods
12
+ */
13
+ static VALUE fast_xs_html(VALUE self)
14
+ {
15
+ long i;
16
+ char *s;
17
+ size_t new_len = RSTRING_LEN(self);
18
+ char *new_str;
19
+ VALUE rv;
20
+
21
+ for (s = RSTRING_PTR(self), i = RSTRING_LEN(self); --i >= 0; ++s) {
22
+ if (unlikely(*s == '&'))
23
+ new_len += (sizeof("&amp;") - 2);
24
+ else if (unlikely(*s == '<' || *s == '>'))
25
+ new_len += (sizeof("&gt;") - 2);
26
+ else if (unlikely(*s == '"'))
27
+ new_len += (sizeof("&quot;") - 2);
28
+ }
29
+
30
+ rv = rb_str_new(NULL, new_len);
31
+ new_str = RSTRING_PTR(rv);
32
+
33
+ #define append_const(buf, x) do { \
34
+ buf = memcpy(buf, x, sizeof(x) - 1) + sizeof(x) - 1; \
35
+ } while (0)
36
+
37
+ for (s = RSTRING_PTR(self), i = RSTRING_LEN(self); --i >= 0; ++s) {
38
+ if (unlikely(*s == '&'))
39
+ append_const(new_str, "&amp;");
40
+ else if (unlikely(*s == '<'))
41
+ append_const(new_str, "&lt;");
42
+ else if (unlikely(*s == '>'))
43
+ append_const(new_str, "&gt;");
44
+ else if (unlikely(*s == '"'))
45
+ append_const(new_str, "&quot;");
46
+ else
47
+ *new_str++ = *s;
48
+ }
49
+
50
+ #undef append_const
51
+
52
+ return rv;
53
+ }
54
+
55
+ #define CGI_URI_OK(x) \
56
+ ((x >= 'a' && x <= 'z') || \
57
+ (x >= 'A' && x <= 'Z') || \
58
+ (x >= '0' && x <= '9') || \
59
+ (x == '.' || x == '-' || x == '_'))
60
+
61
+ static inline VALUE _xs_uri_encode(VALUE self, const unsigned int space_to_plus)
62
+ {
63
+ long i;
64
+ char *s;
65
+ size_t new_len = RSTRING_LEN(self);
66
+ char *new_str;
67
+ VALUE rv;
68
+
69
+ for (s = RSTRING_PTR(self), i = RSTRING_LEN(self); --i >= 0; ++s) {
70
+ if (likely(CGI_URI_OK(*s)) || (space_to_plus && *s == ' '))
71
+ continue;
72
+ new_len += 2;
73
+ }
74
+
75
+ rv = rb_str_new(NULL, new_len);
76
+ new_str = RSTRING_PTR(rv);
77
+
78
+ for (s = RSTRING_PTR(self), i = RSTRING_LEN(self); --i >= 0; ++s) {
79
+ if (likely(CGI_URI_OK(*s)))
80
+ *new_str++ = *s;
81
+ else if (space_to_plus && *s == ' ')
82
+ *new_str++ = '+';
83
+ else {
84
+ static const char cgi_digitmap[] = "0123456789ABCDEF";
85
+ new_str[2] = cgi_digitmap[(*s % 16)];
86
+ new_str[1] = cgi_digitmap[((*s/16) % 16)];
87
+ new_str[0] = '%';
88
+ new_str += 3;
89
+ }
90
+ }
91
+
92
+ return rv;
93
+ }
94
+
95
+ /*
96
+ * Compatible with ERB::Util::url_encode / ERB::Util::u, this iterates
97
+ * through each byte, so multibyte character sets may not supported (but
98
+ * UTF-8 should be).
99
+ */
100
+ static VALUE fast_xs_url(VALUE self)
101
+ {
102
+ return _xs_uri_encode(self, 0);
103
+ }
104
+
105
+ /*
106
+ * Compatible with CGI::escape(), this iterates through each byte, so
107
+ * multibyte character sets may not supported (but UTF-8 should be).
108
+ */
109
+ static VALUE fast_xs_cgi(VALUE self)
110
+ {
111
+ return _xs_uri_encode(self, 1);
112
+ }
113
+
114
+ static VALUE _uxs_uri(VALUE self, const unsigned int plus_to_space)
115
+ {
116
+ char *s, *new_str;
117
+ long i;
118
+ size_t new_len = RSTRING_LEN(self);
119
+ VALUE rv;
120
+
121
+ for (s = RSTRING_PTR(self), i = RSTRING_LEN(self);
122
+ --i >= 0;
123
+ ++s) {
124
+ if (unlikely(*s == '%') &&
125
+ likely(is_hex(s[1])) &&
126
+ likely(is_hex(s[2]))) {
127
+ new_len -= 2;
128
+ s += 2;
129
+ i -= 2;
130
+ }
131
+ }
132
+
133
+ rv = rb_str_new(NULL, new_len);
134
+ new_str = RSTRING_PTR(rv);
135
+
136
+ for (s = RSTRING_PTR(self), i = RSTRING_LEN(self);
137
+ --i >= 0;
138
+ ++s, ++new_str) {
139
+ if (plus_to_space && unlikely(*s == '+'))
140
+ *new_str = ' ';
141
+ else if (unlikely(*s == '%') &&
142
+ likely(is_hex(s[1])) &&
143
+ likely(is_hex(s[2]))) {
144
+ *new_str = hexpair_to_int(s[1], s[2]);
145
+ s += 2;
146
+ i -= 2;
147
+ } else
148
+ *new_str = *s;
149
+ }
150
+
151
+ return rv;
152
+ }
153
+
154
+ static VALUE fast_uxs_cgi(VALUE self)
155
+ {
156
+ return _uxs_uri(self, 1);
157
+ }
158
+
159
+ void Init_fast_xs_extra(void)
160
+ {
161
+ rb_define_method(rb_cString, "fast_xs_html", fast_xs_html, 0);
162
+ rb_define_method(rb_cString, "fast_xs_cgi", fast_xs_cgi, 0);
163
+ rb_define_method(rb_cString, "fast_uxs_cgi", fast_uxs_cgi, 0);
164
+ rb_define_method(rb_cString, "fast_xs_url", fast_xs_url, 0);
165
+ }
@@ -1,4 +1,5 @@
1
1
  require 'fast_xs'
2
+ require 'fast_xs_extra'
2
3
 
3
4
  class CGI
4
5
  def CGI::escapeHTML(value); value.fast_xs_html; end
@@ -13,6 +13,7 @@ class TestXmlEscaping < Test::Unit::TestCase
13
13
  assert_equal '&amp;', '&'.fast_xs # ampersand
14
14
  assert_equal '&lt;', '<'.fast_xs # left angle bracket
15
15
  assert_equal '&gt;', '>'.fast_xs # right angle bracket
16
+ assert_equal '&quot;', '"'.fast_xs # double quote
16
17
  end
17
18
 
18
19
  def test_invalid
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4.7
3
- specification_version: 2
4
2
  name: fast_xs
5
3
  version: !ruby/object:Gem::Version
6
- version: "0.6"
7
- date: 2008-02-20 00:00:00 -08:00
8
- summary: excessively fast escaping
9
- require_paths:
10
- - lib/i486-linux
11
- - lib
12
- email: normalperson@yhbt.net
13
- homepage: http://bogonips.org/fast_xs/
14
- rubyforge_project:
15
- description: excessively fast escaping
4
+ version: "0.7"
5
+ platform: ruby
6
+ authors:
7
+ - Eric Wong
16
8
  autorequire:
17
- default_executable:
18
9
  bindir: bin
19
- has_rdoc: true
20
- required_ruby_version: !ruby/object:Gem::Requirement
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
25
- version:
26
- required_rubygems_version: !ruby/object:Gem::Requirement
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- version: "0"
31
- version:
32
- platform: ruby
33
- signing_key:
34
10
  cert_chain: []
35
11
 
36
- post_install_message:
37
- authors:
38
- - Eric Wong
12
+ date: 2009-02-07 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: excessively fast escaping
17
+ email: normalperson@yhbt.net
18
+ executables: []
19
+
20
+ extensions:
21
+ - ext/fast_xs/extconf.rb
22
+ - ext/fast_xs_extra/extconf.rb
23
+ extra_rdoc_files:
24
+ - README
25
+ - COPYING
39
26
  files:
40
- - CHANGELOG
41
27
  - COPYING
42
28
  - README
43
29
  - Rakefile
@@ -46,12 +32,15 @@ files:
46
32
  - test/test_erb_util_module_overrides.rb
47
33
  - lib/fast_xs_monkey_patcher.rb
48
34
  - ext/fast_xs/fast_xs.c
35
+ - ext/fast_xs_extra/fast_xs_extra.c
49
36
  - ext/fast_xs/extconf.rb
37
+ - ext/fast_xs_extra/extconf.rb
38
+ - ext/fast_xs/gcc.h
50
39
  - ext/fast_xs/ruby_1_9_compat.h
51
40
  - ext/fast_xs/fast_xs_type.h
52
- - ext/fast_xs/gcc.h
53
- test_files: []
54
-
41
+ has_rdoc: true
42
+ homepage: http://bogomips.org/fast_xs/
43
+ post_install_message:
55
44
  rdoc_options:
56
45
  - --quiet
57
46
  - --title
@@ -59,15 +48,27 @@ rdoc_options:
59
48
  - --main
60
49
  - README
61
50
  - --inline-source
62
- extra_rdoc_files:
63
- - README
64
- - CHANGELOG
65
- - COPYING
66
- executables: []
67
-
68
- extensions:
69
- - ext/fast_xs/extconf.rb
51
+ require_paths:
52
+ - lib/x86_64-linux
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
70
66
  requirements: []
71
67
 
72
- dependencies: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.1
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: excessively fast escaping
73
+ test_files: []
73
74
 
data/CHANGELOG DELETED
@@ -1,8 +0,0 @@
1
- = 0.2
2
- === 6th December, 2007
3
- * First real release
4
- * added fast_xs_html and fast_xs_cgi methods
5
-
6
- = 0.1
7
- === 3rd October, 2007
8
- * initial implementation, not officially released