-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy path_sre.java
More file actions
49 lines (42 loc) · 1.65 KB
/
_sre.java
File metadata and controls
49 lines (42 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright 2000 Finn Bock
*
* This program contains material copyrighted by:
* Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
*
* This version of the SRE library can be redistributed under CNRI's
* Python 1.6 license. For any other use, please contact Secret Labs
* AB (info@pythonware.com).
*
* Portions of this engine have been developed in cooperation with
* CNRI. Hewlett-Packard provided funding for 1.6 integration and
* other compatibility work.
*/
package org.python.modules;
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.modules.sre.PatternObject;
import org.python.modules.sre.SRE_STATE;
public class _sre {
public static int MAGIC = SRE_STATE.SRE_MAGIC;
// probably the right number for Jython since we are UTF-16.
public static int MAXREPEAT = 65535;
// workaround the fact that H, I types are unsigned, but we are not really using them as such
// XXX: May not be the right size, but I suspect it is -- see sre_compile.py
public static int CODESIZE = 4;
public static PatternObject compile(PyString pattern, int flags, PyObject code, int groups,
PyObject groupindex, PyObject indexgroup) {
int[] ccode = new int[code.__len__()];
int i = 0;
for (PyObject item : code.asIterable()) {
ccode[i++] = (int)item.asLong();
}
return new PatternObject(pattern, flags, ccode, groups, groupindex, indexgroup);
}
public static int getcodesize() {
return CODESIZE;
}
public static int getlower(int ch, int flags) {
return SRE_STATE.getlower(ch, flags);
}
}