[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndex/Splitter/UnicodeSplitter/src - UnicodeSplitter.c:1.4
Andreas Jung
andreas@zope.com
Wed, 17 Oct 2001 11:29:50 -0400
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndex/Splitter/UnicodeSplitter/src
In directory cvs.zope.org:/tmp/cvs-serv4941/src
Modified Files:
UnicodeSplitter.c
Log Message:
added new 'encoding' parameter to change default encoding
=== Zope/lib/python/Products/PluginIndexes/TextIndex/Splitter/UnicodeSplitter/src/UnicodeSplitter.c 1.3 => 1.4 ===
}
+static char *splitter_args[]={"encoding",NULL};
+
static PyObject *
get_Splitter(PyObject *modinfo, PyObject *args,PyObject *keywds)
{
- Splitter *self;
- PyObject *doc, *unicodedoc,*synstop=NULL;
+ Splitter *self=NULL;
+ PyObject *doc=NULL, *unicodedoc=NULL,*synstop=NULL;
+ char *encoding = "latin1";
if (! (self = PyObject_NEW(Splitter, &SplitterType))) return NULL;
- if (! (PyArg_ParseTuple(args,"O|O",&doc,&synstop))) return NULL;
+ if (! (PyArg_ParseTupleAndKeywords(args,keywds,"O|Os",splitter_args,&doc,&synstop,&encoding))) return NULL;
+
#ifdef DEBUG
puts("got text");
@@ -294,11 +298,10 @@
fflush(stdout);
#endif
+
if (PyString_Check(doc)) {
- // This sux a bit. The default encoding should be ascii or latin1.
- // But there must be better support to pass an optional encoding parameter
- unicodedoc = PyUnicode_FromEncodedObject(doc,"latin1","strict");
+ unicodedoc = PyUnicode_FromEncodedObject(doc,encoding,"strict");
if (! unicodedoc) goto err;
@@ -325,8 +328,8 @@
static struct PyMethodDef Splitter_module_methods[] =
{
- { "UnicodeSplitter", (PyCFunction)get_Splitter, METH_VARARGS,
- "UnicodeSplitter(doc[,synstop]) -- Return a word splitter"
+ { "UnicodeSplitter", (PyCFunction)get_Splitter, METH_VARARGS|METH_KEYWORDS,
+ "UnicodeSplitter(doc[,synstop][,encoding='latin1']) -- Return a word splitter"
},
{ NULL, NULL }
};