01: /*
02: * Copyright 2000 Finn Bock
03: *
04: * This program contains material copyrighted by:
05: * Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
06: *
07: * This version of the SRE library can be redistributed under CNRI's
08: * Python 1.6 license. For any other use, please contact Secret Labs
09: * 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: public PatternObject pattern;
22: PyString 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,
31: status);
32:
33: if (status == 0 || state.ptr == state.start)
34: state.start = state.ptr + 1;
35: else
36: state.start = state.ptr;
37:
38: return match;
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,
47: status);
48:
49: if (status == 0 || state.ptr == state.start)
50: state.start = state.ptr + 1;
51: else
52: state.start = state.ptr;
53:
54: return match;
55: }
56: }
|