code_zauker 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,360 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Class: CodeZauker::Util
8
+
9
+ &mdash; Code Zauker 0.0.3 Documentation
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ relpath = '..';
19
+ if (relpath != '') relpath += '/';
20
+ </script>
21
+
22
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
23
+
24
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
25
+
26
+
27
+ </head>
28
+ <body>
29
+ <script type="text/javascript" charset="utf-8">
30
+ if (window.top.frames.main) document.body.className = 'frames';
31
+ </script>
32
+
33
+ <div id="header">
34
+ <div id="menu">
35
+
36
+ <a href="../_index.html">Index (U)</a> &raquo;
37
+ <span class='title'><span class='object_link'><a href="../CodeZauker.html" title="CodeZauker (module)">CodeZauker</a></span></span>
38
+ &raquo;
39
+ <span class="title">Util</span>
40
+
41
+
42
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
43
+ </div>
44
+
45
+ <div id="search">
46
+
47
+ <a id="class_list_link" href="#">Class List</a>
48
+
49
+ <a id="method_list_link" href="#">Method List</a>
50
+
51
+ <a id="file_list_link" href="#">File List</a>
52
+
53
+ </div>
54
+ <div class="clear"></div>
55
+ </div>
56
+
57
+ <iframe id="search_frame"></iframe>
58
+
59
+ <div id="content"><h1>Class: CodeZauker::Util
60
+
61
+
62
+
63
+ </h1>
64
+
65
+ <dl class="box">
66
+
67
+ <dt class="r1">Inherits:</dt>
68
+ <dd class="r1">
69
+ <span class="inheritName">Object</span>
70
+
71
+ <ul class="fullTree">
72
+ <li>Object</li>
73
+
74
+ <li class="next">CodeZauker::Util</li>
75
+
76
+ </ul>
77
+ <a href="#" class="inheritanceTree">show all</a>
78
+
79
+ </dd>
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+ <dt class="r2 last">Defined in:</dt>
90
+ <dd class="r2 last">lib/code_zauker.rb</dd>
91
+
92
+ </dl>
93
+ <div class="clear"></div>
94
+
95
+ <h2>Overview</h2><div class="docstring">
96
+ <div class="discussion">
97
+
98
+ <h1>Basic utility class</h1>
99
+
100
+
101
+ </div>
102
+ </div>
103
+ <div class="tags">
104
+
105
+
106
+ </div>
107
+
108
+
109
+
110
+
111
+
112
+ <h2>
113
+ Instance Method Summary
114
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
115
+ </h2>
116
+
117
+ <ul class="summary">
118
+
119
+ <li class="public ">
120
+ <span class="summary_signature">
121
+
122
+ <a href="#ensureUTF8-instance_method" title="#ensureUTF8 (instance method)">- (Object) <strong>ensureUTF8</strong>(untrusted_string) </a>
123
+
124
+
125
+
126
+ </span>
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+ <span class="summary_desc"><div class='inline'>
136
+ <h1>Ensure Data are correctly imported</h1>
137
+
138
+ <p><a
139
+ href="http://blog.grayproductions.net/articles/ruby_19s_string">blog.grayproductions.net/articles/ruby_19s_string</a>
140
+ This code try to "guess" the right encoding switching to ISO-8859-1 if
141
+ UTF-8 is not valid.</p>
142
+ </div></span>
143
+
144
+ </li>
145
+
146
+
147
+ <li class="public ">
148
+ <span class="summary_signature">
149
+
150
+ <a href="#mixCase-instance_method" title="#mixCase (instance method)">- (Object) <strong>mixCase</strong>(trigram) </a>
151
+
152
+
153
+
154
+ </span>
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+ <span class="summary_desc"><div class='inline'>
164
+ <p>Compute all the possible case-mixed trigrams It works for every string size
165
+ TODO: Very bad implementation, need improvements.</p>
166
+ </div></span>
167
+
168
+ </li>
169
+
170
+
171
+ </ul>
172
+
173
+
174
+
175
+
176
+ <div id="instance_method_details" class="method_details_list">
177
+ <h2>Instance Method Details</h2>
178
+
179
+
180
+ <div class="method_details first">
181
+ <p class="signature first" id="ensureUTF8-instance_method">
182
+
183
+ - (<tt>Object</tt>) <strong>ensureUTF8</strong>(untrusted_string)
184
+
185
+
186
+
187
+ </p><div class="docstring">
188
+ <div class="discussion">
189
+
190
+ <h1>Ensure Data are correctly imported</h1>
191
+
192
+ <p><a
193
+ href="http://blog.grayproductions.net/articles/ruby_19s_string">blog.grayproductions.net/articles/ruby_19s_string</a>
194
+ This code try to "guess" the right encoding switching to ISO-8859-1 if
195
+ UTF-8 is not valid. Tipical use case: an italian source code wronlgy
196
+ interpreted as a UTF-8 whereas it is a ISO-8859 windows code.</p>
197
+
198
+
199
+ </div>
200
+ </div>
201
+ <div class="tags">
202
+
203
+
204
+ </div><table class="source_code">
205
+ <tr>
206
+ <td>
207
+ <pre class="lines">
208
+
209
+
210
+ 56
211
+ 57
212
+ 58
213
+ 59
214
+ 60
215
+ 61
216
+ 62
217
+ 63
218
+ 64
219
+ 65
220
+ 66
221
+ 67
222
+ 68
223
+ 69
224
+ 70
225
+ 71
226
+ 72
227
+ 73</pre>
228
+ </td>
229
+ <td>
230
+ <pre class="code"><span class="info file"># File 'lib/code_zauker.rb', line 56</span>
231
+
232
+ <span class='kw'>def</span> <span class='id identifier rubyid_ensureUTF8'>ensureUTF8</span><span class='lparen'>(</span><span class='id identifier rubyid_untrusted_string'>untrusted_string</span><span class='rparen'>)</span>
233
+ <span class='kw'>if</span> <span class='id identifier rubyid_untrusted_string'>untrusted_string</span><span class='period'>.</span><span class='id identifier rubyid_valid_encoding?'>valid_encoding?</span><span class='lparen'>(</span><span class='rparen'>)</span><span class='op'>==</span><span class='kw'>false</span>
234
+ <span class='comment'>#puts &quot;DEBUG Trouble on #{untrusted_string}&quot;
235
+ </span> <span class='id identifier rubyid_untrusted_string'>untrusted_string</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ISO-8859-1</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
236
+ <span class='comment'># We try ISO-8859-1 tipical windows
237
+ </span> <span class='kw'>begin</span>
238
+ <span class='id identifier rubyid_valid_string'>valid_string</span><span class='op'>=</span><span class='id identifier rubyid_untrusted_string'>untrusted_string</span><span class='period'>.</span><span class='id identifier rubyid_encode'>encode</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>UTF-8</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='lbrace'>{</span> <span class='symbol'>:undef</span> <span class='op'>=&gt;</span><span class='symbol'>:replace</span><span class='comma'>,</span> <span class='symbol'>:invalid</span> <span class='op'>=&gt;</span> <span class='symbol'>:replace</span><span class='rbrace'>}</span> <span class='rparen'>)</span>
239
+ <span class='kw'>rescue</span> <span class='const'>Encoding</span><span class='op'>::</span><span class='const'>InvalidByteSequenceError</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
240
+ <span class='id identifier rubyid_raise'>raise</span> <span class='id identifier rubyid_e'>e</span>
241
+ <span class='kw'>end</span>
242
+ <span class='comment'># if valid_string != untrusted_string
243
+ </span> <span class='comment'># puts &quot;CONVERTED #{valid_string} Works?#{valid_string.valid_encoding?}&quot;
244
+ </span> <span class='comment'># end
245
+ </span> <span class='kw'>return</span> <span class='id identifier rubyid_valid_string'>valid_string</span>
246
+ <span class='kw'>else</span>
247
+ <span class='kw'>return</span> <span class='id identifier rubyid_untrusted_string'>untrusted_string</span>
248
+ <span class='kw'>end</span>
249
+ <span class='kw'>end</span></pre>
250
+ </td>
251
+ </tr>
252
+ </table>
253
+ </div>
254
+
255
+ <div class="method_details ">
256
+ <p class="signature " id="mixCase-instance_method">
257
+
258
+ - (<tt>Object</tt>) <strong>mixCase</strong>(trigram)
259
+
260
+
261
+
262
+ </p><div class="docstring">
263
+ <div class="discussion">
264
+
265
+ <p>Compute all the possible case-mixed trigrams It works for every string size
266
+ TODO: Very bad implementation, need improvements</p>
267
+
268
+
269
+ </div>
270
+ </div>
271
+ <div class="tags">
272
+
273
+
274
+ </div><table class="source_code">
275
+ <tr>
276
+ <td>
277
+ <pre class="lines">
278
+
279
+
280
+ 19
281
+ 20
282
+ 21
283
+ 22
284
+ 23
285
+ 24
286
+ 25
287
+ 26
288
+ 27
289
+ 28
290
+ 29
291
+ 30
292
+ 31
293
+ 32
294
+ 33
295
+ 34
296
+ 35
297
+ 36
298
+ 37
299
+ 38
300
+ 39
301
+ 40
302
+ 41
303
+ 42
304
+ 43
305
+ 44
306
+ 45
307
+ 46
308
+ 47
309
+ 48</pre>
310
+ </td>
311
+ <td>
312
+ <pre class="code"><span class="info file"># File 'lib/code_zauker.rb', line 19</span>
313
+
314
+ <span class='kw'>def</span> <span class='id identifier rubyid_mixCase'>mixCase</span><span class='lparen'>(</span><span class='id identifier rubyid_trigram'>trigram</span><span class='rparen'>)</span>
315
+ <span class='id identifier rubyid_caseMixedElements'>caseMixedElements</span><span class='op'>=</span><span class='lbracket'>[</span><span class='rbracket'>]</span>
316
+ <span class='id identifier rubyid_lx'>lx</span><span class='op'>=</span><span class='id identifier rubyid_trigram'>trigram</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span>
317
+ <span class='id identifier rubyid_combos'>combos</span><span class='op'>=</span><span class='int'>2</span><span class='op'>**</span><span class='id identifier rubyid_lx'>lx</span>
318
+ <span class='id identifier rubyid_startString'>startString</span><span class='op'>=</span><span class='id identifier rubyid_trigram'>trigram</span><span class='period'>.</span><span class='id identifier rubyid_downcase'>downcase</span>
319
+ <span class='comment'>#puts &quot;Combos... 1..#{combos}... #{startString}&quot;
320
+ </span> <span class='kw'>for</span> <span class='id identifier rubyid_c'>c</span> <span class='kw'>in</span> <span class='int'>0</span><span class='op'>..</span><span class='lparen'>(</span><span class='id identifier rubyid_combos'>combos</span><span class='op'>-</span><span class='int'>1</span><span class='rparen'>)</span> <span class='kw'>do</span>
321
+ <span class='comment'># Make binary
322
+ </span> <span class='id identifier rubyid_maskForStuff'>maskForStuff</span><span class='op'>=</span><span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='lparen'>(</span><span class='int'>2</span><span class='rparen'>)</span>
323
+ <span class='id identifier rubyid_p'>p</span><span class='op'>=</span><span class='int'>0</span>
324
+ <span class='comment'>#puts maskForStuff
325
+ </span> <span class='id identifier rubyid_currentMix'>currentMix</span><span class='op'>=</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_end'>&quot;</span></span>
326
+ <span class='comment'># Pad it
327
+ </span> <span class='kw'>if</span> <span class='id identifier rubyid_maskForStuff'>maskForStuff</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>&lt;</span> <span class='id identifier rubyid_lx'>lx</span>
328
+ <span class='id identifier rubyid_maskForStuff'>maskForStuff</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0</span><span class='tstring_end'>&quot;</span></span><span class='op'>*</span><span class='lparen'>(</span><span class='id identifier rubyid_lx'>lx</span><span class='op'>-</span><span class='id identifier rubyid_maskForStuff'>maskForStuff</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='op'>+</span><span class='id identifier rubyid_maskForStuff'>maskForStuff</span>
329
+ <span class='kw'>end</span>
330
+ <span class='id identifier rubyid_maskForStuff'>maskForStuff</span><span class='period'>.</span><span class='id identifier rubyid_each_char'>each_char</span> <span class='lbrace'>{</span> <span class='op'>|</span> <span class='id identifier rubyid_x'>x</span> <span class='op'>|</span>
331
+ <span class='comment'>#putc x
332
+ </span> <span class='kw'>if</span> <span class='id identifier rubyid_x'>x</span><span class='op'>==</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>1</span><span class='tstring_end'>&quot;</span></span>
333
+ <span class='id identifier rubyid_currentMix'>currentMix</span> <span class='op'>+=</span><span class='id identifier rubyid_startString'>startString</span><span class='lbracket'>[</span><span class='id identifier rubyid_p'>p</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span>
334
+ <span class='kw'>else</span>
335
+ <span class='id identifier rubyid_currentMix'>currentMix</span> <span class='op'>+=</span><span class='id identifier rubyid_startString'>startString</span><span class='lbracket'>[</span><span class='id identifier rubyid_p'>p</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_downcase'>downcase</span>
336
+ <span class='kw'>end</span>
337
+ <span class='comment'>#puts currentMix
338
+ </span> <span class='id identifier rubyid_p'>p</span><span class='op'>+=</span><span class='int'>1</span>
339
+ <span class='rbrace'>}</span>
340
+ <span class='id identifier rubyid_caseMixedElements'>caseMixedElements</span><span class='period'>.</span><span class='id identifier rubyid_push'>push</span><span class='lparen'>(</span><span class='id identifier rubyid_currentMix'>currentMix</span><span class='rparen'>)</span>
341
+ <span class='kw'>end</span>
342
+ <span class='kw'>return</span> <span class='id identifier rubyid_caseMixedElements'>caseMixedElements</span>
343
+ <span class='kw'>end</span></pre>
344
+ </td>
345
+ </tr>
346
+ </table>
347
+ </div>
348
+
349
+ </div>
350
+
351
+ </div>
352
+
353
+ <div id="footer">
354
+ Generated on Fri Feb 3 17:18:43 2012 by
355
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
356
+ 0.7.4 (ruby-1.9.3).
357
+ </div>
358
+
359
+ </body>
360
+ </html>
data/doc/Grep.html ADDED
@@ -0,0 +1,344 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Module: Grep
8
+
9
+ &mdash; Code Zauker 0.0.3 Documentation
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ relpath = '';
19
+ if (relpath != '') relpath += '/';
20
+ </script>
21
+
22
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
25
+
26
+
27
+ </head>
28
+ <body>
29
+ <script type="text/javascript" charset="utf-8">
30
+ if (window.top.frames.main) document.body.className = 'frames';
31
+ </script>
32
+
33
+ <div id="header">
34
+ <div id="menu">
35
+
36
+ <a href="_index.html">Index (G)</a> &raquo;
37
+
38
+
39
+ <span class="title">Grep</span>
40
+
41
+
42
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
43
+ </div>
44
+
45
+ <div id="search">
46
+
47
+ <a id="class_list_link" href="#">Class List</a>
48
+
49
+ <a id="method_list_link" href="#">Method List</a>
50
+
51
+ <a id="file_list_link" href="#">File List</a>
52
+
53
+ </div>
54
+ <div class="clear"></div>
55
+ </div>
56
+
57
+ <iframe id="search_frame"></iframe>
58
+
59
+ <div id="content"><h1>Module: Grep
60
+
61
+
62
+
63
+ </h1>
64
+
65
+ <dl class="box">
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+ <dt class="r1 last">Defined in:</dt>
75
+ <dd class="r1 last">lib/code_zauker/grep.rb</dd>
76
+
77
+ </dl>
78
+ <div class="clear"></div>
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+ <h2>
87
+ Instance Method Summary
88
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
89
+ </h2>
90
+
91
+ <ul class="summary">
92
+
93
+ <li class="public ">
94
+ <span class="summary_signature">
95
+
96
+ <a href="#grep-instance_method" title="#grep (instance method)">- (Object) <strong>grep</strong>(file, pattern, pre_context = 0, post_context = 0, print_filename = true) </a>
97
+
98
+
99
+
100
+ </span>
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+ <span class="summary_desc"><div class='inline'>
110
+ <p>Grep works like a shell grep.</p>
111
+ </div></span>
112
+
113
+ </li>
114
+
115
+
116
+ </ul>
117
+
118
+
119
+
120
+
121
+ <div id="instance_method_details" class="method_details_list">
122
+ <h2>Instance Method Details</h2>
123
+
124
+
125
+ <div class="method_details first">
126
+ <p class="signature first" id="grep-instance_method">
127
+
128
+ - (<tt>Object</tt>) <strong>grep</strong>(file, pattern, pre_context = 0, post_context = 0, print_filename = true)
129
+
130
+
131
+
132
+ </p><div class="docstring">
133
+ <div class="discussion">
134
+
135
+ <p>Grep works like a shell grep. `file' can be either a string, containing the
136
+ name of a file to load and handle, or an IO object (such as $stdin) to deal
137
+ with. `pattern' can be either a string or Regexp object which contains a
138
+ pattern. Patterns as strings treat no part of the string as `special', such
139
+ as '.' or '?' in a regex. `pre_context' and `post_context' determine the
140
+ amount of lines to return that came before or after the content that was
141
+ matched, respectively. If there are overlaps in the context, no duplicates
142
+ will be printed.</p>
143
+
144
+
145
+ </div>
146
+ </div>
147
+ <div class="tags">
148
+
149
+
150
+ </div><table class="source_code">
151
+ <tr>
152
+ <td>
153
+ <pre class="lines">
154
+
155
+
156
+ 58
157
+ 59
158
+ 60
159
+ 61
160
+ 62
161
+ 63
162
+ 64
163
+ 65
164
+ 66
165
+ 67
166
+ 68
167
+ 69
168
+ 70
169
+ 71
170
+ 72
171
+ 73
172
+ 74
173
+ 75
174
+ 76
175
+ 77
176
+ 78
177
+ 79
178
+ 80
179
+ 81
180
+ 82
181
+ 83
182
+ 84
183
+ 85
184
+ 86
185
+ 87
186
+ 88
187
+ 89
188
+ 90
189
+ 91
190
+ 92
191
+ 93
192
+ 94
193
+ 95
194
+ 96
195
+ 97
196
+ 98
197
+ 99
198
+ 100
199
+ 101
200
+ 102
201
+ 103
202
+ 104
203
+ 105
204
+ 106
205
+ 107
206
+ 108
207
+ 109
208
+ 110
209
+ 111
210
+ 112
211
+ 113
212
+ 114
213
+ 115
214
+ 116
215
+ 117
216
+ 118
217
+ 119
218
+ 120
219
+ 121
220
+ 122
221
+ 123
222
+ 124
223
+ 125
224
+ 126
225
+ 127
226
+ 128
227
+ 129
228
+ 130
229
+ 131
230
+ 132
231
+ 133
232
+ 134
233
+ 135
234
+ 136
235
+ 137
236
+ 138
237
+ 139
238
+ 140
239
+ 141</pre>
240
+ </td>
241
+ <td>
242
+ <pre class="code"><span class="info file"># File 'lib/code_zauker/grep.rb', line 58</span>
243
+
244
+ <span class='kw'>def</span> <span class='id identifier rubyid_grep'>grep</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span><span class='comma'>,</span> <span class='id identifier rubyid_pattern'>pattern</span><span class='comma'>,</span> <span class='id identifier rubyid_pre_context'>pre_context</span><span class='op'>=</span><span class='int'>0</span><span class='comma'>,</span> <span class='id identifier rubyid_post_context'>post_context</span><span class='op'>=</span><span class='int'>0</span><span class='comma'>,</span> <span class='id identifier rubyid_print_filename'>print_filename</span><span class='op'>=</span><span class='kw'>true</span><span class='rparen'>)</span>
245
+ <span class='id identifier rubyid_currentline'>currentline</span><span class='op'>=</span><span class='int'>0</span>
246
+ <span class='kw'>if</span> <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span> <span class='const'>String</span>
247
+ <span class='id identifier rubyid_fileName'>fileName</span><span class='op'>=</span><span class='id identifier rubyid_file'>file</span>
248
+ <span class='id identifier rubyid_file'>file</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>r</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
249
+ <span class='kw'>else</span>
250
+ <span class='id identifier rubyid_fileName'>fileName</span><span class='op'>=</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_end'>&quot;</span></span>
251
+ <span class='kw'>end</span>
252
+
253
+ <span class='kw'>if</span> <span class='op'>!</span> <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span> <span class='const'>IO</span>
254
+ <span class='id identifier rubyid_throw'>throw</span> <span class='const'>IOError</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>File must be the name of an existing file or IO object</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
255
+ <span class='kw'>end</span>
256
+
257
+ <span class='kw'>if</span> <span class='id identifier rubyid_pattern'>pattern</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span> <span class='const'>String</span>
258
+ <span class='id identifier rubyid_pattern'>pattern</span> <span class='op'>=</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='embexpr_beg'>#{</span><span class='const'>Regexp</span><span class='period'>.</span><span class='id identifier rubyid_escape'>escape</span><span class='lparen'>(</span><span class='id identifier rubyid_pattern'>pattern</span><span class='rparen'>)</span><span class='rbrace'>}</span><span class='regexp_end'>/</span></span>
259
+ <span class='kw'>end</span>
260
+
261
+ <span class='kw'>if</span> <span class='op'>!</span> <span class='id identifier rubyid_pattern'>pattern</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span> <span class='const'>Regexp</span>
262
+ <span class='id identifier rubyid_throw'>throw</span> <span class='const'>StandardError</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Pattern must be string or regexp</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
263
+ <span class='kw'>end</span>
264
+
265
+ <span class='id identifier rubyid_cache'>cache</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
266
+ <span class='id identifier rubyid_lines'>lines</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
267
+
268
+ <span class='id identifier rubyid_util'>util</span><span class='op'>=</span><span class='const'>CodeZauker</span><span class='op'>::</span><span class='const'>Util</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='rparen'>)</span>
269
+
270
+ <span class='id identifier rubyid_loop'>loop</span> <span class='kw'>do</span>
271
+ <span class='kw'>begin</span>
272
+ <span class='id identifier rubyid_line'>line</span> <span class='op'>=</span> <span class='id identifier rubyid_util'>util</span><span class='period'>.</span><span class='id identifier rubyid_ensureUTF8'>ensureUTF8</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_readline'>readline</span><span class='rparen'>)</span>
273
+
274
+ <span class='id identifier rubyid_currentline'>currentline</span> <span class='op'>+=</span><span class='int'>1</span>
275
+ <span class='id identifier rubyid_cache'>cache</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='kw'>unless</span> <span class='id identifier rubyid_cache'>cache</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>&lt;</span> <span class='id identifier rubyid_pre_context'>pre_context</span>
276
+
277
+ <span class='id identifier rubyid_cache'>cache</span><span class='period'>.</span><span class='id identifier rubyid_push'>push</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_currentline'>currentline</span><span class='rbrace'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_line'>line</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
278
+
279
+ <span class='kw'>if</span> <span class='id identifier rubyid_line'>line</span> <span class='op'>=~</span> <span class='id identifier rubyid_pattern'>pattern</span>
280
+ <span class='id identifier rubyid_lines'>lines</span> <span class='op'>+=</span> <span class='id identifier rubyid_cache'>cache</span>
281
+ <span class='id identifier rubyid_cache'>cache</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
282
+ <span class='kw'>if</span> <span class='id identifier rubyid_post_context'>post_context</span> <span class='op'>&gt;</span> <span class='int'>0</span>
283
+ <span class='id identifier rubyid_post_context'>post_context</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='kw'>do</span>
284
+ <span class='kw'>begin</span>
285
+ <span class='id identifier rubyid_utf8line'>utf8line</span><span class='op'>=</span><span class='id identifier rubyid_util'>util</span><span class='period'>.</span><span class='id identifier rubyid_ensureUTF8'>ensureUTF8</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_readline'>readline</span><span class='rparen'>)</span>
286
+ <span class='id identifier rubyid_lines'>lines</span><span class='period'>.</span><span class='id identifier rubyid_push'>push</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_currentline'>currentline</span><span class='rbrace'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_utf8line'>utf8line</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
287
+ <span class='id identifier rubyid_currentline'>currentline</span> <span class='op'>+=</span><span class='int'>1</span>
288
+ <span class='kw'>rescue</span> <span class='const'>IOError</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
289
+ <span class='kw'>break</span>
290
+ <span class='kw'>end</span>
291
+ <span class='kw'>end</span>
292
+ <span class='kw'>end</span>
293
+ <span class='kw'>end</span>
294
+ <span class='kw'>rescue</span> <span class='const'>IOError</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
295
+ <span class='kw'>break</span>
296
+ <span class='kw'>rescue</span> <span class='const'>ArgumentError</span> <span class='op'>=&gt;</span><span class='id identifier rubyid_e2'>e2</span>
297
+ <span class='comment'># Rethrow a probably UTF-8 fatal error
298
+ </span> <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Pattern Matching failed on \n\t</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_fileName'>fileName</span><span class='rbrace'>}</span><span class='tstring_content'>\n\tLine:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_line'>line</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span>
299
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Encoding of line:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_line'>line</span><span class='period'>.</span><span class='id identifier rubyid_encoding'>encoding</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbrace'>}</span><span class='tstring_content'> Valid? </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_line'>line</span><span class='period'>.</span><span class='id identifier rubyid_valid_encoding?'>valid_encoding?</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span>
300
+ <span class='comment'>#raise e2
301
+ </span> <span class='kw'>end</span>
302
+ <span class='kw'>end</span>
303
+
304
+
305
+ <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_each_line'>each_line</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_untrustedLine'>untrustedLine</span><span class='op'>|</span>
306
+ <span class='id identifier rubyid_cache'>cache</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='kw'>unless</span> <span class='id identifier rubyid_cache'>cache</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>&lt;</span> <span class='id identifier rubyid_pre_context'>pre_context</span>
307
+ <span class='id identifier rubyid_line'>line</span><span class='op'>=</span><span class='id identifier rubyid_util'>util</span><span class='period'>.</span><span class='id identifier rubyid_ensureUTF8'>ensureUTF8</span><span class='lparen'>(</span><span class='id identifier rubyid_untrustedLine'>untrustedLine</span><span class='rparen'>)</span>
308
+ <span class='id identifier rubyid_cache'>cache</span><span class='period'>.</span><span class='id identifier rubyid_push'>push</span><span class='lparen'>(</span><span class='id identifier rubyid_line'>line</span><span class='rparen'>)</span>
309
+
310
+ <span class='kw'>if</span> <span class='id identifier rubyid_line'>line</span> <span class='op'>=~</span> <span class='id identifier rubyid_pattern'>pattern</span>
311
+ <span class='id identifier rubyid_lines'>lines</span> <span class='op'>+=</span> <span class='id identifier rubyid_cache'>cache</span>
312
+ <span class='kw'>if</span> <span class='id identifier rubyid_post_context'>post_context</span> <span class='op'>&gt;</span> <span class='int'>0</span>
313
+ <span class='id identifier rubyid_post_context'>post_context</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='kw'>do</span>
314
+ <span class='kw'>begin</span>
315
+ <span class='id identifier rubyid_utf8line'>utf8line</span><span class='op'>=</span><span class='id identifier rubyid_util'>util</span><span class='period'>.</span><span class='id identifier rubyid_ensureUTF8'>ensureUTF8</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_readline'>readline</span><span class='rparen'>)</span>
316
+ <span class='id identifier rubyid_lines'>lines</span><span class='period'>.</span><span class='id identifier rubyid_push'>push</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_currentline'>currentline</span><span class='rbrace'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_utf8line'>utf8line</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
317
+ <span class='id identifier rubyid_currentline'>currentline</span> <span class='op'>+=</span><span class='int'>1</span>
318
+ <span class='kw'>rescue</span> <span class='const'>Exception</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
319
+ <span class='kw'>break</span>
320
+ <span class='kw'>end</span>
321
+ <span class='kw'>end</span>
322
+ <span class='kw'>end</span>
323
+ <span class='kw'>end</span>
324
+ <span class='kw'>end</span>
325
+
326
+ <span class='kw'>return</span> <span class='id identifier rubyid_lines'>lines</span>
327
+ <span class='kw'>end</span></pre>
328
+ </td>
329
+ </tr>
330
+ </table>
331
+ </div>
332
+
333
+ </div>
334
+
335
+ </div>
336
+
337
+ <div id="footer">
338
+ Generated on Fri Feb 3 17:18:44 2012 by
339
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
340
+ 0.7.4 (ruby-1.9.3).
341
+ </div>
342
+
343
+ </body>
344
+ </html>