Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
cc164232
Kaydet (Commit)
cc164232
authored
Eki 02, 2016
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #28295: Fixed the documentation and added tests for PyUnicode_AsUCS4().
Original patch by Xiang Zhang.
üst
63b5b6fd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
2 deletions
+50
-2
unicode.rst
Doc/c-api/unicode.rst
+1
-1
unicodeobject.h
Include/unicodeobject.h
+1
-1
test_unicode.py
Lib/test/test_unicode.py
+17
-0
_testcapimodule.c
Modules/_testcapimodule.c
+31
-0
No files found.
Doc/c-api/unicode.rst
Dosyayı görüntüle @
cc164232
...
...
@@ -641,7 +641,7 @@ APIs:
Copy the string *u* into a UCS4 buffer, including a null character, if
*copy_null* is set. Returns *NULL* and sets an exception on error (in
particular, a :exc:`
Value
Error` if *buflen* is smaller than the length of
particular, a :exc:`
System
Error` if *buflen* is smaller than the length of
*u*). *buffer* is returned on success.
.. versionadded:: 3.3
...
...
Include/unicodeobject.h
Dosyayı görüntüle @
cc164232
...
...
@@ -749,7 +749,7 @@ PyAPI_FUNC(Py_UCS4) _PyUnicode_FindMaxChar (
#endif
/* Copy the string into a UCS4 buffer including the null character if copy_null
is set. Return NULL and raise an exception on error. Raise a
Value
Error if
is set. Return NULL and raise an exception on error. Raise a
System
Error if
the buffer is smaller than the string. Return buffer on success.
buflen is the length of the buffer in (Py_UCS4) characters. */
...
...
Lib/test/test_unicode.py
Dosyayı görüntüle @
cc164232
...
...
@@ -2687,6 +2687,23 @@ class CAPITest(unittest.TestCase):
self
.
assertEqual
(
size
,
nchar
)
self
.
assertEqual
(
wchar
,
nonbmp
+
'
\0
'
)
# Test PyUnicode_AsUCS4()
@support.cpython_only
def
test_asucs4
(
self
):
from
_testcapi
import
unicode_asucs4
for
s
in
[
'abc'
,
'
\xa1\xa2
'
,
'
\u4f60\u597d
'
,
'a
\U0001f600
'
,
'a
\ud800
b
\udfff
c'
,
'
\ud834\udd1e
'
]:
l
=
len
(
s
)
self
.
assertEqual
(
unicode_asucs4
(
s
,
l
,
1
),
s
+
'
\0
'
)
self
.
assertEqual
(
unicode_asucs4
(
s
,
l
,
0
),
s
+
'
\uffff
'
)
self
.
assertEqual
(
unicode_asucs4
(
s
,
l
+
1
,
1
),
s
+
'
\0\uffff
'
)
self
.
assertEqual
(
unicode_asucs4
(
s
,
l
+
1
,
0
),
s
+
'
\0\uffff
'
)
self
.
assertRaises
(
SystemError
,
unicode_asucs4
,
s
,
l
-
1
,
1
)
self
.
assertRaises
(
SystemError
,
unicode_asucs4
,
s
,
l
-
2
,
0
)
s
=
'
\0
'
.
join
([
s
,
s
])
self
.
assertEqual
(
unicode_asucs4
(
s
,
len
(
s
),
1
),
s
+
'
\0
'
)
self
.
assertEqual
(
unicode_asucs4
(
s
,
len
(
s
),
0
),
s
+
'
\uffff
'
)
@support.cpython_only
def
test_encode_decimal
(
self
):
from
_testcapi
import
unicode_encodedecimal
...
...
Modules/_testcapimodule.c
Dosyayı görüntüle @
cc164232
...
...
@@ -1829,6 +1829,36 @@ unicode_aswidecharstring(PyObject *self, PyObject *args)
return
Py_BuildValue
(
"(Nn)"
,
result
,
size
);
}
static
PyObject
*
unicode_asucs4
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
unicode
,
*
result
;
Py_UCS4
*
buffer
;
int
copy_null
;
Py_ssize_t
str_len
,
buf_len
;
if
(
!
PyArg_ParseTuple
(
args
,
"Unp:unicode_asucs4"
,
&
unicode
,
&
str_len
,
&
copy_null
))
{
return
NULL
;
}
buf_len
=
str_len
+
1
;
buffer
=
PyMem_NEW
(
Py_UCS4
,
buf_len
);
if
(
buffer
==
NULL
)
{
return
PyErr_NoMemory
();
}
memset
(
buffer
,
0
,
sizeof
(
Py_UCS4
)
*
buf_len
);
buffer
[
str_len
]
=
0xffffU
;
if
(
!
PyUnicode_AsUCS4
(
unicode
,
buffer
,
buf_len
,
copy_null
))
{
PyMem_FREE
(
buffer
);
return
NULL
;
}
result
=
PyUnicode_FromKindAndData
(
PyUnicode_4BYTE_KIND
,
buffer
,
buf_len
);
PyMem_FREE
(
buffer
);
return
result
;
}
static
PyObject
*
unicode_encodedecimal
(
PyObject
*
self
,
PyObject
*
args
)
{
...
...
@@ -3884,6 +3914,7 @@ static PyMethodDef TestMethods[] = {
{
"test_widechar"
,
(
PyCFunction
)
test_widechar
,
METH_NOARGS
},
{
"unicode_aswidechar"
,
unicode_aswidechar
,
METH_VARARGS
},
{
"unicode_aswidecharstring"
,
unicode_aswidecharstring
,
METH_VARARGS
},
{
"unicode_asucs4"
,
unicode_asucs4
,
METH_VARARGS
},
{
"unicode_encodedecimal"
,
unicode_encodedecimal
,
METH_VARARGS
},
{
"unicode_transformdecimaltoascii"
,
unicode_transformdecimaltoascii
,
METH_VARARGS
},
{
"unicode_legacy_string"
,
unicode_legacy_string
,
METH_VARARGS
},
...
...
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