[Python-checkins] CVS: python/dist/src/Modules _sre.c,2.73,2.74

Fredrik Lundh effbot@users.sourceforge.net
2001年10月24日 15:16:32 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv10490/Modules
Modified Files:
	_sre.c 
Log Message:
(experimental) "finditer" method/function. this works pretty much
like findall, but returns an iterator (which returns match objects)
instead of a list of strings/tuples.
Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.73
retrieving revision 2.74
diff -C2 -d -r2.73 -r2.74
*** _sre.c	2001年10月22日 21:18:08	2.73
--- _sre.c	2001年10月24日 22:16:30	2.74
***************
*** 36,39 ****
--- 36,40 ----
 * 2001年10月21日 fl added sub/subn primitive
 * 2001年10月22日 fl check for literal sub/subn templates
+ * 2001年10月24日 fl added finditer primitive (for 2.2 only)
 *
 * Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
***************
*** 1955,1958 ****
--- 1956,1983 ----
 }
 
+ #if PY_VERSION_HEX >= 0x02020000
+ static PyObject*
+ pattern_finditer(PatternObject* pattern, PyObject* args)
+ {
+ PyObject* scanner;
+ PyObject* search;
+ PyObject* iterator;
+ 
+ scanner = pattern_scanner(pattern, args);
+ if (!scanner)
+ return NULL;
+ 
+ search = PyObject_GetAttrString(scanner, "search");
+ Py_DECREF(scanner);
+ if (!search)
+ return NULL;
+ 
+ iterator = PyCallIter_New(search, Py_None);
+ Py_DECREF(search);
+ 
+ return iterator;
+ }
+ #endif
+ 
 static PyObject*
 pattern_split(PatternObject* self, PyObject* args, PyObject* kw)
***************
*** 2332,2335 ****
--- 2357,2363 ----
 {"split", (PyCFunction) pattern_split, METH_VARARGS|METH_KEYWORDS},
 {"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS},
+ #if PY_VERSION_HEX >= 0x02020000
+ {"finditer", (PyCFunction) pattern_finditer, METH_VARARGS},
+ #endif
 {"scanner", (PyCFunction) pattern_scanner, METH_VARARGS},
 {"__copy__", (PyCFunction) pattern_copy, METH_VARARGS},

AltStyle によって変換されたページ (->オリジナル) /