Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitffae0ff

Browse files
authored
Add PyUnicodeWriter_WriteASCII() (#145)
1 parentfde4d34 commitffae0ff

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

‎docs/api.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ Python 3.14
136136

137137
See `PyUnicodeWriter_WriteUTF8() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_WriteUTF8>`__.
138138

139+
.. c:function:: int PyUnicodeWriter_WriteASCII(PyUnicodeWriter *writer, const char *str, Py_ssize_t size)
140+
141+
See `PyUnicodeWriter_WriteASCII() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_WriteASCII>`__.
142+
139143
.. c:function:: int PyUnicodeWriter_WriteWideChar(PyUnicodeWriter *writer, const wchar_t *str, Py_ssize_t size)
140144

141145
See `PyUnicodeWriter_WriteWideChar() documentation <https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_WriteWideChar>`__.

‎docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Changelog
22
=========
33

4+
* 2025-06-09: Add ``PyUnicodeWriter_WriteASCII()`` function.
45
* 2025-06-03: Add functions:
56

67
* ``PySys_GetAttr()``

‎pythoncapi_compat.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,18 @@ PyUnicodeWriter_WriteUTF8(PyUnicodeWriter *writer,
14561456
return res;
14571457
}
14581458

1459+
staticinlineint
1460+
PyUnicodeWriter_WriteASCII(PyUnicodeWriter *writer,
1461+
constchar *str, Py_ssize_t size)
1462+
{
1463+
if (size <0) {
1464+
size = (Py_ssize_t)strlen(str);
1465+
}
1466+
1467+
return_PyUnicodeWriter_WriteASCIIString((_PyUnicodeWriter*)writer,
1468+
str, size);
1469+
}
1470+
14591471
staticinlineint
14601472
PyUnicodeWriter_WriteWideChar(PyUnicodeWriter *writer,
14611473
constwchar_t *str, Py_ssize_t size)

‎tests/test_pythoncapi_compat_cext.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,11 @@ test_unicodewriter(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
18471847
gotoerror;
18481848
}
18491849

1850+
// test PyUnicodeWriter_WriteASCII()
1851+
if (PyUnicodeWriter_WriteASCII(writer," non-ASCII",-1)<0) {
1852+
gotoerror;
1853+
}
1854+
18501855
// test PyUnicodeWriter_WriteUTF8()
18511856
if (PyUnicodeWriter_WriteUTF8(writer," valu\xC3\xA9",-1)<0) {
18521857
gotoerror;
@@ -1870,7 +1875,7 @@ test_unicodewriter(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
18701875
if (result==NULL) {
18711876
returnNULL;
18721877
}
1873-
assert(PyUnicode_EqualToUTF8(result,"var=long valu\xC3\xA9 'repr'"));
1878+
assert(PyUnicode_EqualToUTF8(result,"var=longnon-ASCIIvalu\xC3\xA9 'repr'"));
18741879
Py_DECREF(result);
18751880
}
18761881

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp