Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1e7205a6
Commit
1e7205a6
authored
Jul 04, 2000
by
Marc-André Lemburg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bill Tutt:
Make unicode_compare a true UTF-16 compare function (includes support for surrogates).
parent
4b0200e3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
6 deletions
+29
-6
Objects/unicodeobject.c
Objects/unicodeobject.c
+29
-6
No files found.
Objects/unicodeobject.c
View file @
1e7205a6
...
...
@@ -3045,22 +3045,45 @@ unicode_center(PyUnicodeObject *self, PyObject *args)
return
(
PyObject
*
)
pad
(
self
,
left
,
marg
-
left
,
' '
);
}
/* speedy UTF-16 code point order comparison */
/* gleaned from: */
/* http://www-4.ibm.com/software/developer/library/utf16.html?dwzone=unicode */
static
unsigned
short
utf16Fixup
[
32
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0x2000
,
0xf800
,
0xf800
,
0xf800
,
0xf800
};
static
int
unicode_compare
(
PyUnicodeObject
*
str1
,
PyUnicodeObject
*
str2
)
{
int
len1
,
len2
;
Py_UNICODE
*
s1
=
str1
->
str
;
Py_UNICODE
*
s2
=
str2
->
str
;
len1
=
str1
->
length
;
len2
=
str2
->
length
;
while
(
len1
>
0
&&
len2
>
0
)
{
int
cmp
=
(
*
s1
++
)
-
(
*
s2
++
);
if
(
cmp
)
/* This should make Christian happy! */
return
(
cmp
<
0
)
?
-
1
:
(
cmp
!=
0
);
len1
--
,
len2
--
;
unsigned
short
c1
,
c2
;
/* 16 bits */
int
diff
;
/* 32 bits */
c1
=
*
s1
++
;
c2
=
*
s2
++
;
if
(
c1
>
(
1
<<
11
)
*
26
)
c1
+=
utf16Fixup
[
c1
>>
11
];
if
(
c2
>
(
1
<<
11
)
*
26
)
c2
+=
utf16Fixup
[
c2
>>
11
];
/* now c1 and c2 are in UTF-32-compatible order */
diff
=
(
int
)
c1
-
(
int
)
c2
;
if
(
diff
)
return
(
diff
<
0
)
?
-
1
:
(
diff
!=
0
);
len1
--
;
len2
--
;
}
return
(
len1
<
len2
)
?
-
1
:
(
len1
!=
len2
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment