curl_escape 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8390d31939a8de3b2c4c1bb52d1d77898c8c0f7
4
- data.tar.gz: c16f6b8f2a78bc496e5634b175aad69ddb85ba8a
3
+ metadata.gz: 55be49ada64c12d1e7d0bbd158f564503728a235
4
+ data.tar.gz: 9017ed915571561a448339e296634ed9b5c8c824
5
5
  SHA512:
6
- metadata.gz: ceb049e7c505ca7c76be84001d0407bc087eef8c0ce368980d909b535fe382b6fe6928dc924565dc3ab0c302b4976bbb8e13a9943be6b5c874d40d35da7c1477
7
- data.tar.gz: 892b19c1a63591f33bb3d54d8591ee774f1f70da0ae4455f1058f4da39a2b9d4cc9fc883b55d9cadc3f1b4e3fb305fccc12d0ed19853c05e0a5a49e6795a0923
6
+ metadata.gz: 721f4544d8503376390464694b7e98b8184249e63e4975c8ce322285f6c150db4c0e8bbe0b0ce3c43948358f5340667919d6b81a70d24c87c75588eaff62eba8
7
+ data.tar.gz: 7031c858e2c48907ef19fcb7bf487f801dd586a44c82a60ef187d46848df4802b031eb9b2c30fbdb33a8e8be10e1a075ffc8e84ff9916243cdf323b0e5d85ef4
@@ -3,47 +3,66 @@
3
3
  #include <ruby.h>
4
4
  #include <ruby/encoding.h>
5
5
 
6
+ char *alloc_output_buffer(char *cOutput);
7
+
6
8
  VALUE ruby_curl_escape(VALUE self, VALUE str) {
7
- int cnt;
9
+ int cnt, pos;
10
+ char c;
11
+ char *cStr, *cOutput, *buf;
12
+ char escaped_tilde[3] = "%7E";
8
13
  VALUE output;
14
+ rb_encoding *enc;
9
15
 
10
16
  static CURL *curl;
11
17
  if (!curl) {
12
18
  curl = curl_easy_init();
13
19
  }
14
20
 
15
- char *cStr = StringValueCStr(str);
16
- char *cOutput = curl_easy_escape(curl, cStr, strlen(cStr));
17
-
18
- int pos = 0;
19
- char buf[strlen(cOutput) * 3];
21
+ cStr = StringValueCStr(str);
22
+ cOutput = curl_easy_escape(curl, cStr, strlen(cStr));
20
23
 
24
+ pos = 0;
25
+ buf = alloc_output_buffer(cOutput);
21
26
  if (cOutput) {
22
- for (cnt = 0; *(cOutput + cnt) != '\0'; cnt++) {
23
- if (strncmp(cOutput + cnt, "%20", 3) == 0) {
27
+ for (cnt = 0; (c = *(cOutput + cnt)) != '\0'; cnt++) {
28
+ if (c == '~') {
29
+ memcpy(buf + pos, escaped_tilde, 3);
30
+ pos += 2;
31
+ } else if (c != '%') {
32
+ buf[pos] = c;
33
+ } else if (strncmp(cOutput + cnt, "%20", 3) == 0) {
24
34
  buf[pos] = '+';
25
35
  cnt += 2;
26
- } else if (*(cOutput + cnt) == '~') {
27
- buf[pos] = '%';
28
- buf[pos+1] = '7';
29
- buf[pos+2] = 'E';
30
- pos += 2;
31
36
  } else {
32
- buf[pos] = *(cOutput + cnt);
37
+ buf[pos] = c;
33
38
  }
34
39
  pos++;
35
40
  }
36
- buf[pos++] = '\0';
41
+ buf[pos] = '\0';
37
42
 
38
- rb_encoding* enc = rb_enc_get(str);
43
+ enc = rb_enc_get(str);
39
44
  output = rb_enc_str_new_cstr(buf, enc);
40
45
  curl_free(cOutput);
46
+ free(buf);
41
47
  return output;
42
48
  } else {
43
49
  return Qnil;
44
50
  }
45
51
  }
46
52
 
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
+
47
66
  void Init_curl_escape(void) {
48
67
  VALUE module = rb_define_module("CurlEscape");
49
68
  rb_define_singleton_method(module, "escape", ruby_curl_escape, 1);
@@ -1,3 +1,3 @@
1
1
  module CurlEscape
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - joker1007
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2016-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler