* is expensive, don't unless they're actually used.
*/
- _PyUnicodeWriter writer;
- _PyUnicodeWriter_Init(&writer);
- writer.overallocate = 1;
+ PyUnicodeWriter *writer = PyUnicodeWriter_Create(0);
+ if (writer == NULL) {
+ goto Error;
+ }
Py_ssize_t flen = PyUnicode_GET_LENGTH(format);
Py_ssize_t i = 0;
if (ch == 'C') {
n -= 2;
}
- if (_PyUnicodeWriter_WriteSubstring(&writer, format, start, end) < 0) {
+ if (PyUnicodeWriter_WriteSubstring(writer, format, start, end) < 0) {
goto Error;
}
start = i;
- if (_PyUnicodeWriter_WriteASCIIString(&writer, buf, n) < 0) {
+ if (PyUnicodeWriter_WriteUTF8(writer, buf, n) < 0) {
goto Error;
}
continue;
}
assert(replacement != NULL);
assert(PyUnicode_Check(replacement));
- if (_PyUnicodeWriter_WriteSubstring(&writer, format, start, end) < 0) {
+ if (PyUnicodeWriter_WriteSubstring(writer, format, start, end) < 0) {
goto Error;
}
start = i;
- if (_PyUnicodeWriter_WriteStr(&writer, replacement) < 0) {
+ if (PyUnicodeWriter_WriteStr(writer, replacement) < 0) {
goto Error;
}
} /* end while() */
PyObject *newformat;
if (start == 0) {
- _PyUnicodeWriter_Dealloc(&writer);
+ PyUnicodeWriter_Discard(writer);
newformat = Py_NewRef(format);
}
else {
- if (_PyUnicodeWriter_WriteSubstring(&writer, format, start, flen) < 0) {
+ if (PyUnicodeWriter_WriteSubstring(writer, format, start, flen) < 0) {
goto Error;
}
- newformat = _PyUnicodeWriter_Finish(&writer);
+ newformat = PyUnicodeWriter_Finish(writer);
if (newformat == NULL) {
goto Done;
}
return result;
Error:
- _PyUnicodeWriter_Dealloc(&writer);
+ PyUnicodeWriter_Discard(writer);
goto Done;
}