[Python-checkins] r84111 - in python/branches/py3k: Include/unicodeobject.h Objects/unicodeobject.c

victor.stinner python-checkins at python.org
Tue Aug 17 00:03:11 CEST 2010


Author: victor.stinner
Date: Tue Aug 17 00:03:11 2010
New Revision: 84111

Log:
Issue #9425: Create Py_UNICODE_strncmp() function

The code is based on strncmp() of the libiberty library,
function in the public domain.

Modified:
   python/branches/py3k/Include/unicodeobject.h
   python/branches/py3k/Objects/unicodeobject.c

Modified: python/branches/py3k/Include/unicodeobject.h
==============================================================================
--- python/branches/py3k/Include/unicodeobject.h	(original)
+++ python/branches/py3k/Include/unicodeobject.h	Tue Aug 17 00:03:11 2010
@@ -1613,23 +1613,38 @@
     Py_UNICODE ch       /* Unicode character */
     );
 
-PyAPI_FUNC(size_t) Py_UNICODE_strlen(const Py_UNICODE *u);
+PyAPI_FUNC(size_t) Py_UNICODE_strlen(
+    const Py_UNICODE *u
+    );
 
 PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcpy(
-    Py_UNICODE *s1, const Py_UNICODE *s2);
+    Py_UNICODE *s1,
+    const Py_UNICODE *s2);
 
 PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strncpy(
-    Py_UNICODE *s1, const Py_UNICODE *s2, size_t n);
+    Py_UNICODE *s1,
+    const Py_UNICODE *s2,
+    size_t n);
 
 PyAPI_FUNC(int) Py_UNICODE_strcmp(
-    const Py_UNICODE *s1, const Py_UNICODE *s2);
+    const Py_UNICODE *s1,
+    const Py_UNICODE *s2
+    );
+
+PyAPI_FUNC(int) Py_UNICODE_strncmp(
+    const Py_UNICODE *s1,
+    const Py_UNICODE *s2,
+    size_t n
+    );
 
 PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr(
-    const Py_UNICODE *s, Py_UNICODE c
+    const Py_UNICODE *s,
+    Py_UNICODE c
     );
 
 PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr(
-    const Py_UNICODE *s, Py_UNICODE c
+    const Py_UNICODE *s,
+    Py_UNICODE c
     );
 
 #ifdef __cplusplus

Modified: python/branches/py3k/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k/Objects/unicodeobject.c	(original)
+++ python/branches/py3k/Objects/unicodeobject.c	Tue Aug 17 00:03:11 2010
@@ -9986,6 +9986,23 @@
     return 0;
 }
 
+int
+Py_UNICODE_strncmp(const Py_UNICODE *s1, const Py_UNICODE *s2, size_t n)
+{
+    register Py_UNICODE u1, u2;
+    for (; n != 0; n--) {
+        u1 = *s1;
+        u2 = *s2;
+        if (u1 != u2)
+            return (u1 < u2) ? -1 : +1;
+        if (u1 == '\0')
+            return 0;
+        s1++;
+        s2++;
+    }
+    return 0;
+}
+
 Py_UNICODE*
 Py_UNICODE_strchr(const Py_UNICODE *s, Py_UNICODE c)
 {


More information about the Python-checkins mailing list