[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndex/Splitter/ZopeSplitter/src - ZopeSplitter.c:1.5.10.1

Andreas Jung andreas@zope.com
Mon, 7 Jan 2002 18:48:27 -0500


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndex/Splitter/ZopeSplitter/src
In directory cvs.zope.org:/tmp/cvs-serv17712/src

Modified Files:
      Tag: ajung-textindexng-branch
	ZopeSplitter.c 
Log Message:
added new split() function to split complete string in one run.
split() returns the splitted words as list. This approach makes
the splitter depending on the size of the input string up to 50%
faster



=== Zope/lib/python/Products/PluginIndexes/TextIndex/Splitter/ZopeSplitter/src/ZopeSplitter.c 1.5 => 1.5.10.1 ===
-
+ 
   Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
   
   This software is subject to the provisions of the Zope Public License,
@@ -274,6 +274,31 @@
     return word;
 }
 
+
+static PyObject *
+Splitter_split(Splitter*self)
+{
+    PyObject *list=NULL,*word=NULL;
+
+    UNLESS(list = PyList_New(0)) return NULL;
+
+    Splitter_reset(self);
+
+    while (1) {
+        Py_XDECREF(word);
+
+        UNLESS(word = next_word(self,NULL,NULL)) return NULL;
+
+        if (word == Py_None) {
+            return list;
+        }
+
+        PyList_Append(list,word);
+    }
+
+    return list;
+}
+
 static PyObject *
 Splitter_slice(Splitter *self, int i, int j)
 {
@@ -359,8 +384,12 @@
 
 static struct PyMethodDef Splitter_methods[] =
     {
+        { "split", (PyCFunction)Splitter_split, 0,
+            "split() -- Split complete string in one run"
+        },
+
         { "pos", (PyCFunction)Splitter_pos, 0,
-            "pos(index) -- Return the starting and ending position of a token"
+          "pos(index) -- Return the starting and ending position of a token"
         },
 
         { "indexes", (PyCFunction)Splitter_indexes, METH_VARARGS,