mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Merge 150c685373
into 61dd9fdad7
This commit is contained in:
commit
7fcc364645
3 changed files with 15 additions and 7 deletions
|
@ -240,6 +240,11 @@ class UnicodeNamesTest(unittest.TestCase):
|
|||
x.decode, 'unicode-escape'
|
||||
)
|
||||
|
||||
def test_issue80667(self):
|
||||
self.assertEqual(str(b'\\N{cjK UniFIeD idEogRAph-732B}', "unicode-escape"), '猫')
|
||||
self.assertEqual(str(b'\\N{cjK UniFIeD idEogRAph-732b}', "unicode-escape"), '猫')
|
||||
self.assertEqual(str(b'\\N{haNGul SYllABle WAe}', "unicode-escape"), '왜')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Literals using the ``\N{name}`` escape syntax can now construct CJK
|
||||
ideographs and Hangul syllables using case-insensitive names.
|
|
@ -1362,7 +1362,7 @@ find_syllable(const char *str, int *len, int *pos, int count, int column)
|
|||
len1 = Py_SAFE_DOWNCAST(strlen(s), size_t, int);
|
||||
if (len1 <= *len)
|
||||
continue;
|
||||
if (strncmp(str, s, len1) == 0) {
|
||||
if (PyOS_strnicmp(str, s, len1) == 0) {
|
||||
*len = len1;
|
||||
*pos = i;
|
||||
}
|
||||
|
@ -1394,7 +1394,7 @@ _getcode(const char* name, int namelen, Py_UCS4* code)
|
|||
* PUA */
|
||||
|
||||
/* Check for hangul syllables. */
|
||||
if (strncmp(name, "HANGUL SYLLABLE ", 16) == 0) {
|
||||
if (PyOS_strnicmp(name, "HANGUL SYLLABLE ", 16) == 0) {
|
||||
int len, L = -1, V = -1, T = -1;
|
||||
const char *pos = name + 16;
|
||||
find_syllable(pos, &len, &L, LCount, 0);
|
||||
|
@ -1412,7 +1412,7 @@ _getcode(const char* name, int namelen, Py_UCS4* code)
|
|||
}
|
||||
|
||||
/* Check for unified ideographs. */
|
||||
if (strncmp(name, "CJK UNIFIED IDEOGRAPH-", 22) == 0) {
|
||||
if (PyOS_strnicmp(name, "CJK UNIFIED IDEOGRAPH-", 22) == 0) {
|
||||
/* Four or five hexdigits must follow. */
|
||||
unsigned int v;
|
||||
v = 0;
|
||||
|
@ -1422,10 +1422,11 @@ _getcode(const char* name, int namelen, Py_UCS4* code)
|
|||
return 0;
|
||||
while (namelen--) {
|
||||
v *= 16;
|
||||
if (*name >= '0' && *name <= '9')
|
||||
v += *name - '0';
|
||||
else if (*name >= 'A' && *name <= 'F')
|
||||
v += *name - 'A' + 10;
|
||||
Py_UCS1 c = Py_TOUPPER(*name);
|
||||
if (c >= '0' && c <= '9')
|
||||
v += c - '0';
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
v += c - 'A' + 10;
|
||||
else
|
||||
return 0;
|
||||
name++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue