KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > modules > _sre


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