[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndex/Splitter/UnicodeSplitter/src - UnicodeSplitter.c:1.2
Andreas Jung
andreas@zope.com
Wed, 17 Oct 2001 10:37:38 -0400
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndex/Splitter/UnicodeSplitter/src
In directory cvs.zope.org:/tmp/cvs-serv25855/src
Modified Files:
UnicodeSplitter.c
Log Message:
code cleanup
=== Zope/lib/python/Products/PluginIndexes/TextIndex/Splitter/UnicodeSplitter/src/UnicodeSplitter.c 1.1 => 1.2 ===
} else res = word;
- return res;
+ return res;
}
static void
@@ -67,15 +67,9 @@
return NULL;
}
- item=PyList_GetItem(self->list , i);
+ item=PyList_GET_ITEM(self->list , i);
Py_INCREF(item);
-
-#ifdef DEBUG
- printf("\n\tItem %d",i);
- PyObject_Print(item,stdout,0);
- fflush(stdout);
-#endif
return item;
}
@@ -90,10 +84,10 @@
if (! (r=PyList_New(0))) return NULL;
for (i=0;i<PyList_Size(self->list);i++) {
- item=PyList_GetItem(self->list,i);
+ item=PyList_GET_ITEM(self->list,i);
if (PyUnicode_Compare(word,item)==0) {
- index=PyInt_FromLong(i);
+ index=PyInt_FromLong(i);
if(!index) return NULL;
Py_INCREF(item);
PyList_Append(r,index);
@@ -194,8 +188,6 @@
register Py_UNICODE ch;
ch = *s;
- *s = Py_UNICODE_TOLOWER(ch);
-
#ifdef DEBUG
printf("%d %c %d\n",i,ch,ch);
fflush(stdout);
@@ -256,6 +248,39 @@
}
+
+static
+void fixlower(PyUnicodeObject *self)
+{
+ int len = self->length;
+ Py_UNICODE *s = self->str;
+
+ while (len-- > 0) {
+ register Py_UNICODE ch;
+
+ ch = Py_UNICODE_TOLOWER(*s);
+ if (ch != *s) *s = ch;
+ s++;
+ }
+}
+
+
+static
+PyUnicodeObject *prepareString(PyUnicodeObject *o)
+
+{
+ PyUnicodeObject *u;
+
+ u = (PyUnicodeObject*) PyUnicode_FromUnicode(NULL, o->length);
+ if (u == NULL) return NULL;
+
+ Py_UNICODE_COPY(u->str, o->str, o->length);
+ fixlower(u);
+
+ return u;
+}
+
+
static PyObject *
get_Splitter(PyObject *modinfo, PyObject *args,PyObject *keywds)
{
@@ -274,7 +299,7 @@
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");
if (! unicodedoc) goto err;
@@ -291,7 +316,7 @@
Py_INCREF(synstop);
} else self->synstop=NULL;
- splitUnicodeString(self,(PyUnicodeObject *)unicodedoc);
+ splitUnicodeString(self,prepareString((PyUnicodeObject *) unicodedoc));
return (PyObject*)self;