File: ref_c_matchdata.xml

package info (click to toggle)
rubybook 0.2-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,252 kB
  • ctags: 1,043
  • sloc: xml: 60,486; makefile: 25
file content (356 lines) | stat: -rw-r--r-- 9,072 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<ppdoc>
<copyright>
    Copyright (c) 2001 by Addison Wesley Longman.  This
    material may be distributed only subject to the terms and
    conditions set forth in the Open Publication License, v1.0 or
    later (the latest version is presently available at
    http://www.opencontent.org/openpub/).
</copyright>
<class name="MatchData" super="Object" type="class">
<p/>
  <tt>MatchData</tt> is the type of the special variable <var>$~</var>,
  and is the type of the object returned by <cim><file>regexp</file><front>Regexp</front><back>match</back><mref>match</mref></cim> and
  <cim><file>regexp</file><front>Regexp</front><back>last_match</back><mref>last_match</mref></cim>. It
  encapsulates all the results of a pattern match, results normally
  accessed through the special variables <tt>$&amp;</tt>, <tt>$'</tt>,
  <tt>$`</tt>, <tt>$1</tt>, <tt>$2</tt>, and so on.
<p/>
  <methods type="instance">
        <method name="[ ]" ref="_ob_cb">
      <callseq>
                  <obj>mtch</obj>[<obj>i</obj>] <returns><obj>anObject</obj></returns><br/><obj>mtch</obj>[<obj>start</obj>, <obj>length</obj>] <returns><obj>anArray</obj></returns><br/><obj>mtch</obj>[<obj>aRange</obj>] <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
        Match Reference---<tt>MatchData</tt> acts as an array, and may
        be accessed using the normal array indexing techniques.
        <obj>mtch</obj>[0] is equivalent to the special variable <var>$&amp;</var>, and
        returns the entire matched string. <obj>mtch</obj>[1], <obj>mtch</obj>[2], and so
        on return the
        values of the matched backreferences (portions of the pattern
        between parentheses).
<p/>
<codefragment>
<fullcode><![CDATA[         m = /(.)(.)(\d+)(\d)/.match("THX1138.")
         m[0]
         m[1, 2]
         m[1..3]
         m[-3, 2]
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>m<nbsp/>=<nbsp/>/(.)(.)(\d+)(\d)/.match("THX1138.")</tt></td>
</tr>
<tr>
  <td><tt>m[0]</tt></td>
  <td>&#187;</td>
  <td><tt>"HX1138"</tt></td>
</tr>
<tr>
  <td><tt>m[1,<nbsp/>2]</tt></td>
  <td>&#187;</td>
  <td><tt>["H",<nbsp/>"X"]</tt></td>
</tr>
<tr>
  <td><tt>m[1..3]</tt></td>
  <td>&#187;</td>
  <td><tt>["H",<nbsp/>"X",<nbsp/>"113"]</tt></td>
</tr>
<tr>
  <td><tt>m[-3,<nbsp/>2]</tt></td>
  <td>&#187;</td>
  <td><tt>["X",<nbsp/>"113"]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="begin" ref="begin">
      <callseq>
        <obj>mtch</obj>.begin( <obj>n</obj> ) <returns><obj>anInteger</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the offset of the start of the <em>n</em>th element of the
      match array in the string.
<p/>
<codefragment>
<fullcode><![CDATA[         m = /(.)(.)(\d+)(\d)/.match("THX1138.")
         m.begin(0)
         m.begin(2)
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>m<nbsp/>=<nbsp/>/(.)(.)(\d+)(\d)/.match("THX1138.")</tt></td>
</tr>
<tr>
  <td><tt>m.begin(0)</tt></td>
  <td>&#187;</td>
  <td><tt>1</tt></td>
</tr>
<tr>
  <td><tt>m.begin(2)</tt></td>
  <td>&#187;</td>
  <td><tt>2</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="end" ref="end">
      <callseq>
        <obj>mtch</obj>.end( <obj>n</obj> ) <returns><obj>anInteger</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the offset of the character immediately following the
      end of the <em>n</em>th element of the match array in the string.
<p/>
<codefragment>
<fullcode><![CDATA[         m = /(.)(.)(\d+)(\d)/.match("THX1138.")
         m.end(0)
         m.end(2)
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>m<nbsp/>=<nbsp/>/(.)(.)(\d+)(\d)/.match("THX1138.")</tt></td>
</tr>
<tr>
  <td><tt>m.end(0)</tt></td>
  <td>&#187;</td>
  <td><tt>7</tt></td>
</tr>
<tr>
  <td><tt>m.end(2)</tt></td>
  <td>&#187;</td>
  <td><tt>3</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="length" ref="length">
      <callseq>
        <obj>mtch</obj>.length <returns><obj>anInteger</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the number of elements in the match array.
<p/>
<codefragment>
<fullcode><![CDATA[         m = /(.)(.)(\d+)(\d)/.match("THX1138.")
         m.length
         m.size
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>m<nbsp/>=<nbsp/>/(.)(.)(\d+)(\d)/.match("THX1138.")</tt></td>
</tr>
<tr>
  <td><tt>m.length</tt></td>
  <td>&#187;</td>
  <td><tt>5</tt></td>
</tr>
<tr>
  <td><tt>m.size</tt></td>
  <td>&#187;</td>
  <td><tt>5</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="offset" ref="offset">
      <callseq>
        <obj>mtch</obj>.offset( <obj>n</obj> ) <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a two-element array containing the beginning and ending
      offsets of the <em>n</em>th match.
<p/>
<codefragment>
<fullcode><![CDATA[         m = /(.)(.)(\d+)(\d)/.match("THX1138.")
         m.offset(0)
         m.offset(4)
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>m<nbsp/>=<nbsp/>/(.)(.)(\d+)(\d)/.match("THX1138.")</tt></td>
</tr>
<tr>
  <td><tt>m.offset(0)</tt></td>
  <td>&#187;</td>
  <td><tt>[1,<nbsp/>7]</tt></td>
</tr>
<tr>
  <td><tt>m.offset(4)</tt></td>
  <td>&#187;</td>
  <td><tt>[6,<nbsp/>7]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="post_match" ref="post_match">
      <callseq>
        <obj>mtch</obj>.post_match <returns><obj>aString</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the portion of the original string after the current
      match. Equivalent to the special variable <var>$'</var>.
<p/>
<codefragment>
<fullcode><![CDATA[         m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
         m.post_match
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>m<nbsp/>=<nbsp/>/(.)(.)(\d+)(\d)/.match("THX1138:<nbsp/>The<nbsp/>Movie")</tt></td>
</tr>
<tr>
  <td><tt>m.post_match</tt></td>
  <td>&#187;</td>
  <td><tt>":<nbsp/>The<nbsp/>Movie"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="pre_match" ref="pre_match">
      <callseq>
        <obj>mtch</obj>.pre_match <returns><obj>aString</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the portion of the original string before the current
      match. Equivalent to the special variable <var>$`</var>.
<p/>
<codefragment>
<fullcode><![CDATA[         m = /(.)(.)(\d+)(\d)/.match("THX1138.")
         m.pre_match
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>m<nbsp/>=<nbsp/>/(.)(.)(\d+)(\d)/.match("THX1138.")</tt></td>
</tr>
<tr>
  <td><tt>m.pre_match</tt></td>
  <td>&#187;</td>
  <td><tt>"T"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="size" ref="size">
      <callseq>
        <obj>mtch</obj>.size <returns><obj>anInteger</obj></returns>
      </callseq>
      <desc>
<p/>
      A synonym for <cim><file>matchdata</file><front>MatchData</front><back>length</back><mref>length</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="string" ref="string">
      <callseq>
        <obj>mtch</obj>.string <returns><obj>aString</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a frozen copy of the string passed in to <tt>match</tt>.
<p/>
<codefragment>
<fullcode><![CDATA[         m = /(.)(.)(\d+)(\d)/.match("THX1138.")
         m.string
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>m<nbsp/>=<nbsp/>/(.)(.)(\d+)(\d)/.match("THX1138.")</tt></td>
</tr>
<tr>
  <td><tt>m.string</tt></td>
  <td>&#187;</td>
  <td><tt>"THX1138."</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="to_a" ref="to_a">
      <callseq>
        <obj>mtch</obj>.to_a <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the array of matches.
<p/>
<codefragment>
<fullcode><![CDATA[         m = /(.)(.)(\d+)(\d)/.match("THX1138.")
         m.to_a
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>m<nbsp/>=<nbsp/>/(.)(.)(\d+)(\d)/.match("THX1138.")</tt></td>
</tr>
<tr>
  <td><tt>m.to_a</tt></td>
  <td>&#187;</td>
  <td><tt>["HX1138",<nbsp/>"H",<nbsp/>"X",<nbsp/>"113",<nbsp/>"8"]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="to_s" ref="to_s">
      <callseq>
        <obj>mtch</obj>.to_s <returns><obj>aString</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the entire matched string.
<p/>
<codefragment>
<fullcode><![CDATA[         m = /(.)(.)(\d+)(\d)/.match("THX1138.")
         m.to_s
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>m<nbsp/>=<nbsp/>/(.)(.)(\d+)(\d)/.match("THX1138.")</tt></td>
</tr>
<tr>
  <td><tt>m.to_s</tt></td>
  <td>&#187;</td>
  <td><tt>"HX1138"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
  </methods>
<p/>
</class>
</ppdoc>