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
137c34c0
Kaydet (Commit)
137c34c0
authored
Eyl 29, 2010
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #9979: Create function PyUnicode_AsWideCharString().
üst
41a64a53
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
16 deletions
+80
-16
unicode.rst
Doc/c-api/unicode.rst
+13
-0
unicodeobject.h
Include/unicodeobject.h
+17
-2
NEWS
Misc/NEWS
+2
-0
unicodeobject.c
Objects/unicodeobject.c
+48
-14
No files found.
Doc/c-api/unicode.rst
Dosyayı görüntüle @
137c34c0
...
...
@@ -462,6 +462,19 @@ wchar_t support for platforms which support it:
required by the application.
.. cfunction:: wchar_t* PyUnicode_AsWideCharString(PyUnicodeObject *unicode, Py_ssize_t *size)
Convert the Unicode object to a wide character string. The output string
always ends with a nul character. If *size* is not *NULL*, write the number
of wide characters (including the nul character) into *\*size*.
Returns a buffer allocated by :cfunc:`PyMem_Alloc` (use :cfunc:`PyMem_Free`
to free it) on success. On error, returns *NULL*, *\*size* is undefined and
raises a :exc:`MemoryError`.
.. versionadded:: 3.2
.. _builtincodecs:
Built-in Codecs
...
...
Include/unicodeobject.h
Dosyayı görüntüle @
137c34c0
...
...
@@ -99,8 +99,8 @@ Copyright (c) Corporation for National Research Initiatives.
#endif
/* If the compiler provides a wchar_t type we try to support it
through the interface functions PyUnicode_FromWideChar()
and
PyUnicode_AsWideChar(). */
through the interface functions PyUnicode_FromWideChar()
,
PyUnicode_AsWideChar()
and PyUnicode_AsWideCharString()
. */
#ifdef HAVE_USABLE_WCHAR_T
# ifndef HAVE_WCHAR_H
...
...
@@ -156,6 +156,7 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define PyUnicode_AsUnicode PyUnicodeUCS2_AsUnicode
# define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS2_AsUnicodeEscapeString
# define PyUnicode_AsWideChar PyUnicodeUCS2_AsWideChar
# define PyUnicode_AsWideCharString PyUnicodeUCS2_AsWideCharString
# define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist
# define PyUnicode_Compare PyUnicodeUCS2_Compare
# define PyUnicode_CompareWithASCII PyUnicodeUCS2_CompareASCII
...
...
@@ -239,6 +240,7 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define PyUnicode_AsUnicode PyUnicodeUCS4_AsUnicode
# define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS4_AsUnicodeEscapeString
# define PyUnicode_AsWideChar PyUnicodeUCS4_AsWideChar
# define PyUnicode_AsWideCharString PyUnicodeUCS4_AsWideCharString
# define PyUnicode_ClearFreeList PyUnicodeUCS4_ClearFreelist
# define PyUnicode_Compare PyUnicodeUCS4_Compare
# define PyUnicode_CompareWithASCII PyUnicodeUCS4_CompareWithASCII
...
...
@@ -570,6 +572,19 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_AsWideChar(
Py_ssize_t
size
/* size of buffer */
);
/* Convert the Unicode object to a wide character string. The output string
always ends with a nul character. If size is not NULL, write the number of
wide characters (including the nul character) into *size.
Returns a buffer allocated by PyMem_Alloc() (use PyMem_Free() to free it)
on success. On error, returns NULL, *size is undefined and raises a
MemoryError. */
PyAPI_FUNC
(
wchar_t
*
)
PyUnicode_AsWideCharString
(
PyUnicodeObject
*
unicode
,
/* Unicode object */
Py_ssize_t
*
size
/* number of characters of the result */
);
#endif
/* --- Unicode ordinals --------------------------------------------------- */
...
...
Misc/NEWS
Dosyayı görüntüle @
137c34c0
...
...
@@ -10,6 +10,8 @@ What's New in Python 3.2 Alpha 3?
Core and Builtins
-----------------
- Issue #9979: Create function PyUnicode_AsWideCharString().
- Issue #7397: Mention that importlib.import_module() is probably what someone
really wants to be using in __import__'s docstring.
...
...
Objects/unicodeobject.c
Dosyayı görüntüle @
137c34c0
...
...
@@ -1153,9 +1153,26 @@ PyUnicode_FromFormat(const char *format, ...)
return
ret
;
}
Py_ssize_t
PyUnicode_AsWideChar
(
PyUnicodeObject
*
unicode
,
wchar_t
*
w
,
Py_ssize_t
size
)
static
void
unicode_aswidechar
(
PyUnicodeObject
*
unicode
,
wchar_t
*
w
,
Py_ssize_t
size
)
{
#if Py_UNICODE_SIZE == SIZEOF_WCHAR_T
memcpy
(
w
,
unicode
->
str
,
size
*
sizeof
(
wchar_t
));
#else
register
Py_UNICODE
*
u
;
register
Py_ssize_t
i
;
u
=
PyUnicode_AS_UNICODE
(
unicode
);
for
(
i
=
size
;
i
>
0
;
i
--
)
*
w
++
=
*
u
++
;
#endif
}
Py_ssize_t
PyUnicode_AsWideChar
(
PyUnicodeObject
*
unicode
,
wchar_t
*
w
,
Py_ssize_t
size
)
{
if
(
unicode
==
NULL
)
{
PyErr_BadInternalCall
();
...
...
@@ -1166,17 +1183,7 @@ Py_ssize_t PyUnicode_AsWideChar(PyUnicodeObject *unicode,
if
(
size
>
PyUnicode_GET_SIZE
(
unicode
))
size
=
PyUnicode_GET_SIZE
(
unicode
)
+
1
;
#if Py_UNICODE_SIZE == SIZEOF_WCHAR_T
memcpy
(
w
,
unicode
->
str
,
size
*
sizeof
(
wchar_t
));
#else
{
register
Py_UNICODE
*
u
;
register
Py_ssize_t
i
;
u
=
PyUnicode_AS_UNICODE
(
unicode
);
for
(
i
=
size
;
i
>
0
;
i
--
)
*
w
++
=
*
u
++
;
}
#endif
unicode_aswidechar
(
unicode
,
w
,
size
);
if
(
size
>
PyUnicode_GET_SIZE
(
unicode
))
return
PyUnicode_GET_SIZE
(
unicode
);
...
...
@@ -1184,6 +1191,33 @@ Py_ssize_t PyUnicode_AsWideChar(PyUnicodeObject *unicode,
return
size
;
}
wchar_t
*
PyUnicode_AsWideCharString
(
PyUnicodeObject
*
unicode
,
Py_ssize_t
*
size
)
{
wchar_t
*
buffer
;
Py_ssize_t
buflen
;
if
(
unicode
==
NULL
)
{
PyErr_BadInternalCall
();
return
NULL
;
}
if
((
PY_SSIZE_T_MAX
/
sizeof
(
wchar_t
)
-
1
)
<
PyUnicode_GET_SIZE
(
unicode
))
{
PyErr_NoMemory
();
return
NULL
;
}
buflen
=
PyUnicode_GET_SIZE
(
unicode
)
+
1
;
/* copy L'\0' */
buffer
=
PyMem_MALLOC
(
buflen
*
sizeof
(
wchar_t
));
if
(
buffer
==
NULL
)
{
PyErr_NoMemory
();
return
NULL
;
}
unicode_aswidechar
(
unicode
,
buffer
,
buflen
);
return
buffer
;
}
#endif
PyObject
*
PyUnicode_FromOrdinal
(
int
ordinal
)
...
...
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