diff options
author | Victor Stinner <vstinner@python.org> | 2024-06-17 15:10:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-17 15:10:52 (GMT) |
commit | 5c4235cd8ce00852cfcb2d3a2cb4c66c6c53c4bf (patch) | |
tree | 725bd5f7c416c37c286afde73e488bb2896a910b /Include/cpython | |
parent | 2c7209a3bdf81a289ccd6b80a77497cfcd5732de (diff) | |
download | cpython-5c4235cd8ce00852cfcb2d3a2cb4c66c6c53c4bf.zip cpython-5c4235cd8ce00852cfcb2d3a2cb4c66c6c53c4bf.tar.gz cpython-5c4235cd8ce00852cfcb2d3a2cb4c66c6c53c4bf.tar.bz2 |
gh-119182: Add PyUnicodeWriter C API (#119184)
Diffstat (limited to 'Include/cpython')
-rw-r--r-- | Include/cpython/unicodeobject.h | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index d9b54bc..e5e1b6b 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -444,7 +444,40 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromKindAndData( Py_ssize_t size); -/* --- _PyUnicodeWriter API ----------------------------------------------- */ +/* --- Public PyUnicodeWriter API ----------------------------------------- */ + +typedef struct PyUnicodeWriter PyUnicodeWriter; + +PyAPI_FUNC(PyUnicodeWriter*) PyUnicodeWriter_Create(Py_ssize_t length); +PyAPI_FUNC(void) PyUnicodeWriter_Discard(PyUnicodeWriter *writer); +PyAPI_FUNC(PyObject*) PyUnicodeWriter_Finish(PyUnicodeWriter *writer); + +PyAPI_FUNC(int) PyUnicodeWriter_WriteChar( + PyUnicodeWriter *writer, + Py_UCS4 ch); +PyAPI_FUNC(int) PyUnicodeWriter_WriteUTF8( + PyUnicodeWriter *writer, + const char *str, + Py_ssize_t size); + +PyAPI_FUNC(int) PyUnicodeWriter_WriteStr( + PyUnicodeWriter *writer, + PyObject *obj); +PyAPI_FUNC(int) PyUnicodeWriter_WriteRepr( + PyUnicodeWriter *writer, + PyObject *obj); +PyAPI_FUNC(int) PyUnicodeWriter_WriteSubstring( + PyUnicodeWriter *writer, + PyObject *str, + Py_ssize_t start, + Py_ssize_t end); +PyAPI_FUNC(int) PyUnicodeWriter_Format( + PyUnicodeWriter *writer, + const char *format, + ...); + + +/* --- Private _PyUnicodeWriter API --------------------------------------- */ typedef struct { PyObject *buffer; @@ -466,7 +499,7 @@ typedef struct { /* If readonly is 1, buffer is a shared string (cannot be modified) and size is set to 0. */ unsigned char readonly; -} _PyUnicodeWriter ; +} _PyUnicodeWriter; // Initialize a Unicode writer. // |