summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-08-16 22:03:11 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-08-16 22:03:11 (GMT)
commitef8d95c4987cc5dd358e718c992c6bb629380702 (patch)
treed2a587c813ca20d453608e309d393e5829cd2b1a /Objects
parent405038ac1c49f8d02e43d9542e70bc3beb2820c1 (diff)
downloadcpython-ef8d95c4987cc5dd358e718c992c6bb629380702.zip
cpython-ef8d95c4987cc5dd358e718c992c6bb629380702.tar.gz
cpython-ef8d95c4987cc5dd358e718c992c6bb629380702.tar.bz2
Issue #9425: Create Py_UNICODE_strncmp() function
The code is based on strncmp() of the libiberty library, function in the public domain.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 676c693..9fd342b 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9986,6 +9986,23 @@ Py_UNICODE_strcmp(const Py_UNICODE *s1, const Py_UNICODE *s2)
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)
{