[Python-checkins] CVS: python/dist/src/Modules _sre.c,2.41,2.42
Fredrik Lundh
python-dev@python.org
Thu, 21 Sep 2000 10:03:28 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv14094/Modules
Modified Files:
_sre.c
Log Message:
- fixed yet another gcc -pedantic warning
- added experimental "expand" method to match objects
- don't use the buffer interface on unicode strings
Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.41
retrieving revision 2.42
diff -C2 -r2.41 -r2.42
*** _sre.c 2000/09/02 16:36:57 2.41
--- _sre.c 2000/09/21 17:03:25 2.42
***************
*** 5,22 ****
*
* partial history:
! * 99-10-24 fl created (based on existing template matcher code)
! * 00-03-06 fl first alpha, sort of (0.5)
! * 00-06-30 fl added fast search optimization (0.9.3)
! * 00-06-30 fl added assert (lookahead) primitives, etc (0.9.4)
! * 00-07-02 fl added charset optimizations, etc (0.9.5)
! * 00-07-03 fl store code in pattern object, lookbehind, etc
! * 00-07-08 fl added regs attribute
! * 00-07-21 fl reset lastindex in scanner methods (0.9.6)
! * 00-08-01 fl fixes for 1.6b1 (0.9.8)
! * 00-08-03 fl added recursion limit
! * 00-08-07 fl use PyOS_CheckStack() if available
! * 00-08-08 fl changed findall to return empty strings instead of None
! * 00-08-27 fl properly propagate memory errors
! * 00-09-02 fl return -1 instead of None for start/end/span
*
* Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
--- 5,24 ----
*
* partial history:
! * 1999-10-24 fl created (based on existing template matcher code)
! * 2000-03-06 fl first alpha, sort of (0.5)
! * 2000-06-30 fl added fast search optimization (0.9.3)
! * 2000-06-30 fl added assert (lookahead) primitives, etc (0.9.4)
! * 2000-07-02 fl added charset optimizations, etc (0.9.5)
! * 2000-07-03 fl store code in pattern object, lookbehind, etc
! * 2000-07-08 fl added regs attribute
! * 2000-07-21 fl reset lastindex in scanner methods (0.9.6)
! * 2000-08-01 fl fixes for 1.6b1 (0.9.8)
! * 2000-08-03 fl added recursion limit
! * 2000-08-07 fl use PyOS_CheckStack() if available
! * 2000-08-08 fl changed findall to return empty strings instead of None
! * 2000-08-27 fl properly propagate memory errors
! * 2000-09-02 fl return -1 instead of None for start/end/span
! * 2000-09-20 fl added expand method
! * 2000-09-21 fl don't use the buffer interface for unicode strings
*
* Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
***************
*** 1046,1050 ****
int status = 0;
int prefix_len = 0;
! int prefix_skip;
SRE_CODE* prefix = NULL;
SRE_CODE* charset = NULL;
--- 1048,1052 ----
int status = 0;
int prefix_len = 0;
! int prefix_skip = 0;
SRE_CODE* prefix = NULL;
SRE_CODE* charset = NULL;
***************
*** 1292,1295 ****
--- 1294,1308 ----
state->lastindex = -1;
+ #if defined(HAVE_UNICODE)
+ if (PyUnicode_Check(string)) {
+ /* unicode strings doesn't always support the buffer interface */
+ ptr = (void*) PyUnicode_AS_DATA(string);
+ bytes = PyUnicode_GET_DATA_SIZE(string);
+ size = PyUnicode_GET_SIZE(string);
+ state->charsize = sizeof(Py_UNICODE);
+
+ } else {
+ #endif
+
/* get pointer to string buffer */
buffer = string->ob_type->tp_as_buffer;
***************
*** 1308,1312 ****
/* determine character size */
-
#if PY_VERSION_HEX >= 0x01060000
size = PyObject_Size(string);
--- 1321,1324 ----
***************
*** 1326,1329 ****
--- 1338,1345 ----
}
+ #if defined(HAVE_UNICODE)
+ }
+ #endif
+
/* adjust boundaries */
if (start < 0)
***************
*** 1859,1862 ****
--- 1875,1892 ----
static PyObject*
+ match_expand(MatchObject* self, PyObject* args)
+ {
+ PyObject* template;
+ if (!PyArg_ParseTuple(args, "O:expand", &template))
+ return NULL;
+
+ /* delegate to Python code */
+ return call(
+ "_expand",
+ Py_BuildValue("OOO", self->pattern, self, template)
+ );
+ }
+
+ static PyObject*
match_group(MatchObject* self, PyObject* args)
{
***************
*** 2095,2098 ****
--- 2125,2129 ----
{"groups", (PyCFunction) match_groups, 1},
{"groupdict", (PyCFunction) match_groupdict, 1},
+ {"expand", (PyCFunction) match_expand, 1},
{NULL, NULL}
};