KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > modules > sre > ScannerObject


1 /*
2  * Copyright 2000 Finn Bock
3  *
4  * This program contains material copyrighted by:
5  * Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
6  *
7  * This version of the SRE library can be redistributed under CNRI's
8  * Python 1.6 license. For any other use, please contact Secret Labs
9  * AB (info@pythonware.com).
10  *
11  * Portions of this engine have been developed in cooperation with
12  * CNRI. Hewlett-Packard provided funding for 1.6 integration and
13  * other compatibility work.
14  */

15
16 package org.python.modules.sre;
17
18 import org.python.core.*;
19
20 public class ScannerObject extends PyObject {
21     PatternObject pattern;
22     String JavaDoc string;
23     SRE_STATE state;
24
25     public MatchObject match() {
26         state.state_reset();
27         state.ptr = state.start;
28
29         int status = state.SRE_MATCH(pattern.code, 0, 1);
30         MatchObject match = pattern._pattern_new_match(state, string, status);
31
32         if (status == 0 || state.ptr == state.start)
33             state.start = state.ptr + 1;
34         else
35             state.start = state.ptr;
36
37         return match;
38     }
39
40
41     public MatchObject search() {
42         state.state_reset();
43         state.ptr = state.start;
44
45         int status = state.SRE_SEARCH(pattern.code, 0);
46         MatchObject match = pattern._pattern_new_match(state, string, status);
47
48         if (status == 0 || state.ptr == state.start)
49             state.start = state.ptr + 1;
50         else
51             state.start = state.ptr;
52
53         return match;
54     }
55 }
56
57
58
59
60
Popular Tags