uv-rays 1.0.1 → 1.0.2

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: dc6d9fc79e303664f5075b3cf62ac95b39bb31fb
4
- data.tar.gz: 37890f4da2011b596342e3b7089c83bc4cd52f6c
3
+ metadata.gz: d9129069a6f55b2da01da10a313ac480c64f82b0
4
+ data.tar.gz: 31e6c36a166ff84b21a3b2471c58f3f0e07bac86
5
5
  SHA512:
6
- metadata.gz: d5647c3b81f76b2b48a17c59c607d558d2b5792541f90130019cade6cb47d2546071157bc086540fc48eb903aee90b9d92b0958ab110c4b663d970050dc27e7d
7
- data.tar.gz: 4d200630c7d495bd2955721502b0cf45b2376cfcbc048d8a0d164564d64e73326d5be1a9b8c475fa8245af0e612226e94d410d147882c8f958960cfffd6e48c8
6
+ metadata.gz: 6d4a72b09ecbd97658880a7bc92fd4b9401705fef7f1f5ba74cd69b77d5138bac02cedce6b189357d187508a7feccd61e6bfe5ddeef567d2390bbb7c195d7974
7
+ data.tar.gz: 737c20c2d4b99d8c9b7cc162025b27a9e94410355882a17451c0f195f63d3b62daacbfb979a19a15e2a58aa53281511a5e51a619b575289fc4c6bf385d23d23c
@@ -15,11 +15,16 @@ module UV
15
15
  @indicator = options[:indicator]
16
16
  @size_limit = options[:size_limit]
17
17
  @verbose = options[:verbose] if @size_limit
18
+ @encoding = options[:encoding]
18
19
 
19
20
  raise ArgumentError, 'no indicator provided' unless @indicator
20
21
  raise ArgumentError, 'no callback provided' unless @callback
21
22
 
22
23
  @input = ''
24
+ if @encoding
25
+ @input.force_encoding(@encoding)
26
+ @indicator.force_encoding(@encoding) if @indicator.is_a?(String)
27
+ end
23
28
  end
24
29
 
25
30
  # Extract takes an arbitrary string of input data and returns an array of
@@ -32,6 +37,7 @@ module UV
32
37
  #
33
38
  # @param [String] data
34
39
  def extract(data)
40
+ data.force_encoding(@encoding) if @encoding
35
41
  @input << data
36
42
 
37
43
  messages = @input.split(@indicator, -1)
@@ -52,7 +58,7 @@ module UV
52
58
  entities << last[0...result]
53
59
  @input = last[result..-1]
54
60
  else
55
- @input = ''
61
+ reset
56
62
  entities << last
57
63
  end
58
64
  else
@@ -84,7 +90,7 @@ module UV
84
90
  # best we can do with a full buffer.
85
91
  @input = @input[-(@indicator.length - 1)..-1]
86
92
  else
87
- @input = ''
93
+ reset
88
94
  end
89
95
  raise 'input buffer exceeded limit' if @verbose
90
96
  end
@@ -98,7 +104,7 @@ module UV
98
104
  # @return [String]
99
105
  def flush
100
106
  buffer = @input
101
- @input = ''
107
+ reset
102
108
  buffer
103
109
  end
104
110
 
@@ -106,5 +112,14 @@ module UV
106
112
  def empty?
107
113
  @input.empty?
108
114
  end
115
+
116
+
117
+ private
118
+
119
+
120
+ def reset
121
+ @input = ''
122
+ @input.force_encoding(@encoding) if @encoding
123
+ end
109
124
  end
110
125
  end
@@ -25,10 +25,16 @@ module UV
25
25
  @size_limit = options[:size_limit]
26
26
  @min_length = options[:min_length] || 1
27
27
  @verbose = options[:verbose] if @size_limit
28
+ @encoding = options[:encoding]
28
29
 
29
30
  raise ArgumentError, 'no delimiter provided' unless @delimiter
30
31
 
31
32
  @input = ''
33
+ if @encoding
34
+ @input.force_encoding(@encoding)
35
+ @delimiter.force_encoding(@encoding) if @delimiter.is_a?(String)
36
+ @indicator.force_encoding(@encoding) if @indicator.is_a?(String)
37
+ end
32
38
  end
33
39
 
34
40
  # Extract takes an arbitrary string of input data and returns an array of
@@ -41,6 +47,7 @@ module UV
41
47
  #
42
48
  # @param [String] data
43
49
  def extract(data)
50
+ data.force_encoding(@encoding) if @encoding
44
51
  @input << data
45
52
 
46
53
  # Extract token-delimited entities from the input string with the split command.
@@ -72,7 +79,7 @@ module UV
72
79
  # delimiter it would be unfortunate
73
80
  @input = @input[-(@indicator.length - 1)..-1]
74
81
  else
75
- @input = ''
82
+ reset
76
83
  end
77
84
  raise 'input buffer exceeded limit' if @verbose
78
85
  end
@@ -89,7 +96,7 @@ module UV
89
96
  # @return [String]
90
97
  def flush
91
98
  buffer = @input
92
- @input = ''
99
+ reset
93
100
  buffer
94
101
  end
95
102
 
@@ -97,5 +104,14 @@ module UV
97
104
  def empty?
98
105
  @input.empty?
99
106
  end
107
+
108
+
109
+ private
110
+
111
+
112
+ def reset
113
+ @input = ''
114
+ @input.force_encoding(@encoding) if @encoding
115
+ end
100
116
  end
101
117
  end
@@ -1,3 +1,3 @@
1
1
  module UV
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -8,7 +8,8 @@ describe UV::AbstractTokenizer do
8
8
  return 4 if data.length > 3
9
9
  return false
10
10
  },
11
- size_limit: 10
11
+ size_limit: 10,
12
+ encoding: "ASCII-8BIT"
12
13
  })
13
14
  end
14
15
 
@@ -5,7 +5,8 @@ describe UV::BufferedTokenizer do
5
5
 
6
6
  before :each do
7
7
  @buffer = UV::BufferedTokenizer.new({
8
- delimiter: "\n\r"
8
+ delimiter: "\n\r",
9
+ encoding: "ASCII-8BIT"
9
10
  })
10
11
  end
11
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uv-rays
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libuv