curl_escape 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bench.rb +5 -5
- data/ext/curl_escape/curl_escape.c +27 -29
- data/lib/curl_escape/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 608c203ad1eb50f307905ac89d5a2b8ace3477c2
|
4
|
+
data.tar.gz: 242ff7d0f8a8c5e564065e99416f83f7bd7d15ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7a7225a5e790764589e7878b87b5517311b85d6275e9d0bf2b283df8291c4c1380654f97e3d36a77b5c55b160deef2a4d6e31ef8618dca405714dce4ede93ba
|
7
|
+
data.tar.gz: e7f941949d0cf7f345e19a773029e79daa65047cbe61c0aadafbc5121aed7956a5823cac101eea8295ad75e1b747c96ae75684c632b1f776a9902dd62549c98d
|
data/bench.rb
CHANGED
@@ -6,13 +6,13 @@ require_relative './lib/curl_escape'
|
|
6
6
|
|
7
7
|
Benchmark.ips do |x|
|
8
8
|
x.config(time: 15, warmup: 5)
|
9
|
-
x.report("cgi_escape")
|
10
|
-
x.report("curl_escape") { CurlEscape.escape("'Stop!' said
|
9
|
+
x.report("cgi_escape") { CGI.escape("'Stop!' said~Fred") }
|
10
|
+
x.report("curl_escape") { CurlEscape.escape("'Stop!' said~Fred") }
|
11
11
|
x.compare!
|
12
12
|
end
|
13
13
|
|
14
|
-
p
|
15
|
-
p CurlEscape.escape("'Stop!' said~Fred foo
|
14
|
+
p CGI.escape("'~Stop!' said~Fred foo~~~hoge")
|
15
|
+
p CurlEscape.escape("'~Stop!' said~Fred foo~~~hoge")
|
16
16
|
|
17
|
-
p
|
17
|
+
p CGI.escape("'日本語あいうえお")
|
18
18
|
p CurlEscape.escape("'日本語あいうえお")
|
@@ -3,12 +3,12 @@
|
|
3
3
|
#include <ruby.h>
|
4
4
|
#include <ruby/encoding.h>
|
5
5
|
|
6
|
-
|
6
|
+
#define EXPAND_SIZE 40
|
7
7
|
|
8
|
-
VALUE ruby_curl_escape(VALUE self, VALUE str) {
|
9
|
-
int
|
8
|
+
static VALUE ruby_curl_escape(VALUE self, VALUE str) {
|
9
|
+
int n, pos, len;
|
10
10
|
char c;
|
11
|
-
char *cStr, *cOutput
|
11
|
+
char *cStr, *cOutput;
|
12
12
|
char escaped_tilde[3] = "%7E";
|
13
13
|
VALUE output;
|
14
14
|
rb_encoding *enc;
|
@@ -22,47 +22,45 @@ VALUE ruby_curl_escape(VALUE self, VALUE str) {
|
|
22
22
|
cOutput = curl_easy_escape(curl, cStr, strlen(cStr));
|
23
23
|
|
24
24
|
pos = 0;
|
25
|
-
buf = alloc_output_buffer(cOutput);
|
26
25
|
if (cOutput) {
|
27
|
-
for (
|
26
|
+
for (n = 0; (c = *(cOutput + n)) != '\0'; n++) {
|
28
27
|
if (c == '~') {
|
29
|
-
|
30
|
-
|
28
|
+
if (n - pos >= 2) {
|
29
|
+
memcpy(cOutput + pos, escaped_tilde, 3);
|
30
|
+
pos += 2;
|
31
|
+
} else {
|
32
|
+
cOutput = realloc(cOutput, strlen(cOutput) + EXPAND_SIZE);
|
33
|
+
len = strlen(cOutput + n);
|
34
|
+
memmove(cOutput + n + EXPAND_SIZE, cOutput + n, len + 1);
|
35
|
+
n += EXPAND_SIZE;
|
36
|
+
memcpy(cOutput + pos, escaped_tilde, 3);
|
37
|
+
pos += 2;
|
38
|
+
}
|
31
39
|
} else if (c != '%') {
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
40
|
+
if (pos != n) {
|
41
|
+
*(cOutput + pos) = c;
|
42
|
+
}
|
43
|
+
} else if (strncmp(cOutput + n, "%20", 3) == 0) {
|
44
|
+
*(cOutput + pos) = '+';
|
45
|
+
n += 2;
|
36
46
|
} else {
|
37
|
-
|
47
|
+
if (pos != n) {
|
48
|
+
*(cOutput + pos) = c;
|
49
|
+
}
|
38
50
|
}
|
39
51
|
pos++;
|
40
52
|
}
|
41
|
-
|
53
|
+
*(cOutput + pos) = '\0';
|
42
54
|
|
43
55
|
enc = rb_enc_get(str);
|
44
|
-
output = rb_enc_str_new_cstr(
|
56
|
+
output = rb_enc_str_new_cstr(cOutput, enc);
|
45
57
|
curl_free(cOutput);
|
46
|
-
free(buf);
|
47
58
|
return output;
|
48
59
|
} else {
|
49
60
|
return Qnil;
|
50
61
|
}
|
51
62
|
}
|
52
63
|
|
53
|
-
char *alloc_output_buffer(char *cOutput) {
|
54
|
-
int i, tilde_cnt;
|
55
|
-
char *buf;
|
56
|
-
tilde_cnt = 0;
|
57
|
-
for (i = 0; *(cOutput + i) != '\0'; i++) {
|
58
|
-
if (*(cOutput + i) == '~') {
|
59
|
-
tilde_cnt++;
|
60
|
-
}
|
61
|
-
}
|
62
|
-
buf = (char *)malloc(i + tilde_cnt * 2);
|
63
|
-
return buf;
|
64
|
-
}
|
65
|
-
|
66
64
|
void Init_curl_escape(void) {
|
67
65
|
VALUE module = rb_define_module("CurlEscape");
|
68
66
|
rb_define_singleton_method(module, "escape", ruby_curl_escape, 1);
|
data/lib/curl_escape/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curl_escape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joker1007
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|