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;
17:
18: import org.python.core.Py;
19: import org.python.core.PyInteger;
20: import org.python.core.PyList;
21: import org.python.core.PyObject;
22: import org.python.core.PyString;
23: import org.python.modules.sre.PatternObject;
24: import org.python.modules.sre.SRE_STATE;
25:
26: public class _sre {
27: public static int MAGIC = SRE_STATE.SRE_MAGIC;
28:
29: public static int CODESIZE = 2;
30:
31: public static PatternObject compile(PyString pattern, int flags,
32: PyObject code, int groups, PyObject groupindex,
33: PyObject indexgroup) {
34: char[] ccode = null;
35: if (code instanceof PyList) {
36: int n = code.__len__();
37: ccode = new char[n];
38: for (int i = 0; i < n; i++)
39: ccode[i] = (char) ((PyInteger) code.__getitem__(i)
40: .__int__()).getValue();
41: } else {
42: throw Py.TypeError("Expected list");
43: }
44:
45: PatternObject po = new PatternObject(pattern, flags, ccode,
46: groups, groupindex, indexgroup);
47: return po;
48: }
49:
50: public static int getcodesize() {
51: return CODESIZE;
52: }
53:
54: public static int getlower(int ch, int flags) {
55: return SRE_STATE.getlower(ch, flags);
56: }
57: }
|