1 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 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 |