decode_www_form_component 0.1

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/CHANGELOG.rdoc ADDED
@@ -0,0 +1 @@
1
+
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ CHANGELOG.rdoc
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ ext/decode_www_form_component/extconf.rb
6
+ ext/decode_www_form_component/decode_www_form_component.c
7
+ lib/decode_www_form_component.rb
data/README.rdoc ADDED
@@ -0,0 +1,40 @@
1
+ = decode_www_form_component
2
+
3
+ * http://github.com/ghazel/decode_www_form_component
4
+
5
+ == DESCRIPTION:
6
+
7
+ This gem adds the `decode_www_form_component` method to .
8
+
9
+ == SYNOPSIS:
10
+
11
+ decode_www_form_component yay
12
+
13
+ == INSTALL:
14
+
15
+ * gem install decode_www_form_component
16
+
17
+ == LICENSE:
18
+
19
+ (The MIT License)
20
+
21
+ Copyright (c) 2012 Greg Hazel
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining
24
+ a copy of this software and associated documentation files (the
25
+ 'Software'), to deal in the Software without restriction, including
26
+ without limitation the rights to use, copy, modify, merge, publish,
27
+ distribute, sublicense, and/or sell copies of the Software, and to
28
+ permit persons to whom the Software is furnished to do so, subject to
29
+ the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be
32
+ included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
35
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
37
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
38
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
39
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ gem 'rake-compiler', '>= 0.4.1'
7
+ require "rake/extensiontask"
8
+
9
+ Hoe.plugins.delete :rubyforge
10
+ Hoe.plugin :minitest
11
+ Hoe.plugin :gemspec # `gem install hoe-gemspec`
12
+ Hoe.plugin :git # `gem install hoe-git`
13
+ Hoe.plugin :debugging # `gem install hoe-debugging`
14
+
15
+ Hoe.spec 'decode_www_form_component' do
16
+ developer('Greg Hazel', 'ghazel@gmail.com')
17
+ self.readme_file = 'README.rdoc'
18
+ self.history_file = 'CHANGELOG.rdoc'
19
+ self.extra_rdoc_files = FileList['*.rdoc']
20
+
21
+ extra_dev_deps << ['rake-compiler', '>= 0.4.1']
22
+
23
+ self.spec_extras = {
24
+ :extensions => ["ext/decode_www_form_component/extconf.rb"]
25
+ }
26
+
27
+ Rake::ExtensionTask.new "decode_www_form_component", spec do |ext|
28
+ ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
29
+ end
30
+ end
31
+
32
+ # vim: syntax=ruby
@@ -0,0 +1,67 @@
1
+ #include <ruby.h>
2
+
3
+
4
+ static VALUE
5
+ decode_uri_changed(VALUE uri, unsigned i)
6
+ {
7
+ char *u = StringValuePtr(uri);
8
+ size_t length = RSTRING_LEN(uri);
9
+ char tmp[3] = {0};
10
+ int j;
11
+ char *r;
12
+ VALUE ret = rb_str_buf_new(length);
13
+ rb_str_cat(ret, u, i+1);
14
+ r = StringValuePtr(ret);
15
+ for (j = i; i < length; i++, j++) {
16
+ switch (u[i]) {
17
+ case '+':
18
+ r[j] = ' ';
19
+ break;
20
+ case '%':
21
+ if (!ISXDIGIT(u[i+1]) || !ISXDIGIT(u[i+2])) {
22
+ return Qnil;
23
+ }
24
+ tmp[0] = u[i+1];
25
+ tmp[1] = u[i+2];
26
+ r[j] = (char)strtol(tmp, NULL, 16);
27
+ i += 2;
28
+ break;
29
+ default:
30
+ r[j] = u[i];
31
+ }
32
+ }
33
+ rb_str_resize(ret, j);
34
+ return ret;
35
+ }
36
+
37
+ static VALUE
38
+ decode_uri(VALUE uri)
39
+ {
40
+ char *u = StringValuePtr(uri);
41
+ size_t length = RSTRING_LEN(uri);
42
+ unsigned i;
43
+ for (i = 0; i < length; i++) {
44
+ switch (u[i]) {
45
+ case '+':
46
+ case '%':
47
+ return decode_uri_changed(uri, i);
48
+ }
49
+ }
50
+ return uri;
51
+ }
52
+
53
+ static VALUE rb_decode_www_form_component_internal(VALUE mod, VALUE string)
54
+ {
55
+ Check_Type(string, T_STRING);
56
+ return decode_uri(string);
57
+ }
58
+
59
+ VALUE URI;
60
+
61
+ void Init_decode_www_form_component()
62
+ {
63
+ URI = rb_define_module("URI");
64
+ rb_define_singleton_method(URI, "decode_www_form_component_internal", rb_decode_www_form_component_internal, 1);
65
+ }
66
+
67
+ /* vim: set noet sws=4 sw=4: */
@@ -0,0 +1,3 @@
1
+ require 'mkmf'
2
+
3
+ create_makefile 'decode_www_form_component'
@@ -0,0 +1,13 @@
1
+ require 'decode_www_form_component.so'
2
+
3
+ module DecodeWwwFormComponent
4
+ VERSION = '0.1'
5
+ end
6
+
7
+ module URI
8
+ def self.decode_www_form_component(str, enc=Encoding::UTF_8)
9
+ r = decode_www_form_component_internal(str)
10
+ raise ArgumentError, "invalid %-encoding (#{str})" if r.nil?
11
+ r.force_encoding(enc)
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decode_www_form_component
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Greg Hazel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.10'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.10'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake-compiler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.4.1
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.4.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: hoe
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ description: This gem adds the `decode_www_form_component` method to .
63
+ email:
64
+ - ghazel@gmail.com
65
+ executables: []
66
+ extensions:
67
+ - ext/decode_www_form_component/extconf.rb
68
+ extra_rdoc_files:
69
+ - CHANGELOG.rdoc
70
+ - Manifest.txt
71
+ - README.rdoc
72
+ files:
73
+ - CHANGELOG.rdoc
74
+ - Manifest.txt
75
+ - README.rdoc
76
+ - Rakefile
77
+ - ext/decode_www_form_component/extconf.rb
78
+ - ext/decode_www_form_component/decode_www_form_component.c
79
+ - lib/decode_www_form_component.rb
80
+ homepage: http://github.com/ghazel/decode_www_form_component
81
+ licenses: []
82
+ post_install_message:
83
+ rdoc_options:
84
+ - --main
85
+ - README.rdoc
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project: decode_www_form_component
102
+ rubygems_version: 1.8.24
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: This gem adds the `decode_www_form_component` method to .
106
+ test_files: []