file_char_licker 0.5.1 → 0.5.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3b866c0fa7744a9271df7c9f32968b8ea2737d7
4
- data.tar.gz: 914c17b71accea0fe80eb1af1bc0763d7115d673
3
+ metadata.gz: bf3b8c9a367c2d28f48e5adde7f0c04e7b20af6c
4
+ data.tar.gz: 5d6475d1a9d874f29e4cf66ca3cf5a1853277cf7
5
5
  SHA512:
6
- metadata.gz: 39c34431afbe701713ed8616430d4e25ee3583ed2953c784c28c2a0212871cea95c013858880bab9415e6d529bf486b4fcbfcf3a0d1fdefe6064dfbb9a0fd624
7
- data.tar.gz: cd3d7d859f29780d5e19e6a63d85b062b3696d7602108f9c9038c2f897c63ebccc4c3b1c24f83e759331a2cd52a72595f4eb2244fdb9aa395a44127fa8901a50
6
+ metadata.gz: 2214067d8af2c76c1764183a344c57090026529b7bbd0dad61d9d15cdf15a0ee3c15cc689e44be12ee94afea5dafaa337f54423f6f911f6db59932e140751acf
7
+ data.tar.gz: e422469995a70ed487854316b545dc3fe6e6ca7c078ca131bee52192ea3e4a18b82db0841a8e7cbeb039f0e1cbfa3c5028bb34137c50a1d4005befe136921370
data/README.ja.md CHANGED
@@ -92,9 +92,7 @@ file.scan_contiguous_min(needle)
92
92
 
93
93
  移動成功時、そのポインタ位置を格納した Integer オブジェクトを返します。正しく移動できなかった場合 (前方に一致する行がなかった場合) 、 nil が返ります。
94
94
 
95
- 実行時のファイルポインタは、行頭を想定しています。
96
-
97
- ### seek_contiguous_max(*args)
95
+ ### seek_contiguous_max
98
96
 
99
97
  ```ruby
100
98
  file.scan_contiguous_min(needle)
@@ -104,8 +102,6 @@ file.scan_contiguous_min(needle)
104
102
 
105
103
  移動成功時、そのポインタ位置を格納した Integer オブジェクトを返します。正しく移動できなかった場合 (後方に一致する行がなかった場合) 、 nil が返ります。
106
104
 
107
- 実行時のファイルポインタは、行頭を想定しています。
108
-
109
105
  ### seek_line_head
110
106
 
111
107
  ```ruby
data/README.md CHANGED
@@ -93,9 +93,7 @@ move the position of file pointer to the start of line that matched the _needle_
93
93
 
94
94
  return Integer object for the position of file pointer if succeed to move. else return nil.
95
95
 
96
- I assume that the position of file pointer is start of line in run.
97
-
98
- ### seek_contiguous_max(*args)
96
+ ### seek_contiguous_max
99
97
 
100
98
  ```ruby
101
99
  file.scan_contiguous_min(needle)
@@ -105,8 +103,6 @@ move the position of file pointer to the end of line that matched the _needle_ a
105
103
 
106
104
  return Integer object for the position of file pointer if succeed to move. else return nil.
107
105
 
108
- I assume that the position of file pointer is start of line in run.
109
-
110
106
  ### seek_line_head
111
107
 
112
108
  ```ruby
@@ -117,4 +113,4 @@ move the position of file pointer to the head of line.
117
113
 
118
114
  ## Author
119
115
 
120
- [indeep-xyz](http://indeep.xyz/)
116
+ [indeep-xyz](http://indeep.xyz/) (Japanese language)
@@ -31,11 +31,19 @@ module FileCharLicker
31
31
  file.seek(pos)
32
32
  max = seek_contiguous_max(needle) || pos
33
33
 
34
+ # for debug
35
+ # p [
36
+ # pos: pos,
37
+ # min: min,
38
+ # max: max
39
+ # ].to_s
40
+ # sleep 0.05
41
+
34
42
  # read
35
43
  # - require succeed scan processes
36
44
  if max > min
37
45
  file.seek(min)
38
- result = file.read(max - min).chomp
46
+ result = file.read(max - min)
39
47
  end
40
48
 
41
49
  result
@@ -77,13 +85,17 @@ module FileCharLicker
77
85
 
78
86
  char = backward_char
79
87
 
80
- break if char.nil?
88
+ if char.nil?
89
+ file.rewind
90
+ break
91
+ end
81
92
 
82
93
  # backward pos as bytesize of char
83
94
  file.seek(-(char.bytesize), IO::SEEK_CUR)
84
95
 
85
- result.insert(0, char)
86
96
  break if char.match(reg) && result.scan(reg).size > size
97
+
98
+ result.insert(0, char)
87
99
  end
88
100
 
89
101
  result
@@ -131,6 +143,9 @@ module FileCharLicker
131
143
  file = @file
132
144
  max = nil
133
145
 
146
+ # move to head of line
147
+ seek_line_head
148
+
134
149
  loop do
135
150
 
136
151
  # file#pos before #forward_lines
@@ -141,9 +156,9 @@ module FileCharLicker
141
156
 
142
157
  # for debug
143
158
  # p [
144
- # lines: lines,
159
+ # lines: lines,
145
160
  # lines_pos: lines_pos,
146
- # file_pos: file.pos
161
+ # file_pos: file.pos
147
162
  # ].to_s
148
163
  # sleep 0.05
149
164
 
@@ -153,17 +168,28 @@ module FileCharLicker
153
168
 
154
169
  lines_end_pos = str_byte_index(lines, /(\r\n|\r|\n)+?/, lines_pos)
155
170
 
156
- if file.eof?
157
- max = (lines_end_pos.nil?) ? file.size : pos_old + lines_end_pos
171
+ if lines_end_pos.nil?
172
+ max = file.size if file.eof?
158
173
  break
159
- else
160
- max = pos_old + lines_end_pos
161
-
162
- break if lines_end_pos < lines.bytesize - 1
163
174
  end
164
175
 
176
+ max = pos_old + lines_end_pos
177
+
178
+ # for debug
179
+ # p [
180
+ # lines: lines,
181
+ # lines_bytesize: lines.bytesize,
182
+ # lines_pos: lines_pos,
183
+ # lines_end_pos: lines_end_pos,
184
+ # file_pos: file.pos
185
+ # ].to_s
186
+ # sleep 0.05
187
+
188
+ break if file.eof?
189
+ break if lines_end_pos < lines.size - 1
165
190
  end
166
191
 
192
+ file.seek(max) unless max.nil?
167
193
  max
168
194
  end
169
195
 
@@ -182,6 +208,9 @@ module FileCharLicker
182
208
  file = @file
183
209
  min = nil
184
210
 
211
+ # move to head of line
212
+ seek_line_head
213
+
185
214
  loop do
186
215
 
187
216
  lines = backward_lines(step_lines)
@@ -200,11 +229,16 @@ module FileCharLicker
200
229
  break
201
230
  else
202
231
 
203
- min = file_pos + lines_pos
232
+ min = file_pos + lines_pos
233
+
234
+ # if not first line, add 1 to result
235
+ min += 1 if file_pos > 0
236
+
204
237
  break if lines_pos > 0 || file_pos < 1
205
238
  end
206
239
  end
207
240
 
241
+ file.seek(min) unless min.nil?
208
242
  min
209
243
  end
210
244
 
@@ -16,6 +16,9 @@ module FileCharLicker
16
16
  def around_lines(*args)
17
17
 
18
18
  lines = super(*args)
19
+ # p @nkf_option
20
+ # p NKF.nkf('-w', lines)
21
+ # p lines
19
22
  NKF.nkf(@nkf_option, lines)
20
23
  end
21
24
 
@@ -82,7 +85,13 @@ module FileCharLicker
82
85
  mb_idx = haystack.index(needle, offset)
83
86
 
84
87
  unless mb_idx.nil?
85
- result = haystack.slice(0..mb_idx).bytesize - 1
88
+
89
+ if mb_idx < 1
90
+ result = 0
91
+ else
92
+ matched = haystack.slice(0..mb_idx)
93
+ result = matched.bytesize - matched[-1].bytesize
94
+ end
86
95
  end
87
96
 
88
97
  result
@@ -1,3 +1,3 @@
1
1
  module FileCharLicker
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_char_licker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - indeep-xyz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-08 00:00:00.000000000 Z
11
+ date: 2014-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler