[Python-checkins] CVS: python/dist/src/Objects unicodeobject.c,2.1,2.2

Guido van Rossum guido@cnri.reston.va.us
Mon, 13 Mar 2000 10:55:12 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Objects
In directory eric:/home/guido/hp/mal/py-patched/Objects

Modified Files:
	unicodeobject.c 
Log Message:
Add sq_contains implementation.


Index: unicodeobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.1
retrieving revision 2.2
diff -C2 -r2.1 -r2.2
*** unicodeobject.c	2000/03/10 22:53:23	2.1
--- unicodeobject.c	2000/03/13 15:55:09	2.2
***************
*** 2738,2741 ****
--- 2738,2784 ----
  }
  
+ int PyUnicode_Contains(PyObject *container,
+ 		       PyObject *element)
+ {
+     PyUnicodeObject *u = NULL, *v = NULL;
+     int result;
+     register const Py_UNICODE *p, *e;
+     register Py_UNICODE ch;
+ 
+     /* Coerce the two arguments */
+     u = (PyUnicodeObject *)PyUnicode_FromObject(container);
+     if (u == NULL)
+ 	goto onError;
+     v = (PyUnicodeObject *)PyUnicode_FromObject(element);
+     if (v == NULL)
+ 	goto onError;
+ 
+     /* Check v in u */
+     if (PyUnicode_GET_SIZE(v) != 1) {
+ 	PyErr_SetString(PyExc_TypeError,
+ 			"string member test needs char left operand");
+ 	goto onError;
+     }
+     ch = *PyUnicode_AS_UNICODE(v);
+     p = PyUnicode_AS_UNICODE(u);
+     e = p + PyUnicode_GET_SIZE(u);
+     result = 0;
+     while (p < e) {
+ 	if (*p++ == ch) {
+ 	    result = 1;
+ 	    break;
+ 	}
+     }
+ 
+     Py_DECREF(u);
+     Py_DECREF(v);
+     return result;
+ 
+ onError:
+     Py_XDECREF(u);
+     Py_XDECREF(v);
+     return -1;
+ }
+ 
  /* Concat to string or Unicode object giving a new Unicode object. */
  
***************
*** 3818,3821 ****
--- 3861,3865 ----
      0, 					/* sq_ass_item */
      0, 					/* sq_ass_slice */
+     (objobjproc)PyUnicode_Contains, 	/*sq_contains*/
  };