mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Add a format specifier %V to PyUnicode_FromFormat(), that works similar to %U,
but requires an additional char * that will be used if the unicode object is NULL. Use %V in descrobject.c and classobject.c.
This commit is contained in:
parent
3ef72bb0a9
commit
d7fb7644da
3 changed files with 66 additions and 44 deletions
|
@ -631,6 +631,18 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
|
|||
n += PyUnicode_GET_SIZE(obj);
|
||||
break;
|
||||
}
|
||||
case 'V':
|
||||
{
|
||||
PyObject *obj = va_arg(count, PyObject *);
|
||||
const char *str = va_arg(count, const char *);
|
||||
assert(obj || str);
|
||||
assert(!obj || PyUnicode_Check(obj));
|
||||
if (obj)
|
||||
n += PyUnicode_GET_SIZE(obj);
|
||||
else
|
||||
n += strlen(str);
|
||||
break;
|
||||
}
|
||||
case 'S':
|
||||
{
|
||||
PyObject *obj = va_arg(count, PyObject *);
|
||||
|
@ -775,6 +787,19 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
|
|||
s += size;
|
||||
break;
|
||||
}
|
||||
case 'V':
|
||||
{
|
||||
PyObject *obj = va_arg(vargs, PyObject *);
|
||||
const char *str = va_arg(vargs, const char *);
|
||||
if (obj) {
|
||||
Py_ssize_t size = PyUnicode_GET_SIZE(obj);
|
||||
Py_UNICODE_COPY(s, PyUnicode_AS_UNICODE(obj), size);
|
||||
s += size;
|
||||
} else {
|
||||
appendstring(str);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'S':
|
||||
case 'R':
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue