@@ -360,6 +360,36 @@ writer_write_widechar(PyObject *self_raw, PyObject *args)
360360}
361361
362362
363+ static PyObject *
364+ writer_write_ucs4 (PyObject * self_raw , PyObject * args )
365+ {
366+ WriterObject * self = (WriterObject * )self_raw ;
367+ if (writer_check (self ) < 0 ) {
368+ return NULL ;
369+ }
370+
371+ PyObject * str ;
372+ Py_ssize_t size ;
373+ if (!PyArg_ParseTuple (args , "Un" , & str , & size )) {
374+ return NULL ;
375+ }
376+ Py_ssize_t len = PyUnicode_GET_LENGTH (str );
377+ size = Py_MIN (size , len );
378+
379+ Py_UCS4 * ucs4 = PyUnicode_AsUCS4Copy (str );
380+ if (ucs4 == NULL ) {
381+ return NULL ;
382+ }
383+
384+ int res = PyUnicodeWriter_WriteUCS4 (self -> writer , ucs4 , size );
385+ PyMem_Free (ucs4 );
386+ if (res < 0 ) {
387+ return NULL ;
388+ }
389+ Py_RETURN_NONE ;
390+ }
391+
392+
363393static PyObject *
364394writer_write_str (PyObject * self_raw , PyObject * args )
365395{
@@ -484,6 +514,7 @@ static PyMethodDef writer_methods[] = {
484514 {"write_char" , _PyCFunction_CAST (writer_write_char ), METH_VARARGS },
485515 {"write_utf8" , _PyCFunction_CAST (writer_write_utf8 ), METH_VARARGS },
486516 {"write_widechar" , _PyCFunction_CAST (writer_write_widechar ), METH_VARARGS },
517+ {"write_ucs4" , _PyCFunction_CAST (writer_write_ucs4 ), METH_VARARGS },
487518 {"write_str" , _PyCFunction_CAST (writer_write_str ), METH_VARARGS },
488519 {"write_repr" , _PyCFunction_CAST (writer_write_repr ), METH_VARARGS },
489520 {"write_substring" , _PyCFunction_CAST (writer_write_substring ), METH_VARARGS },
0 commit comments