diff Objects/unicodeobject.c @ 42047:d678ba0177da

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.
author Walter Dörwald <walter@livinglogic.de>
date Mon, 11 Jun 2007 16:36:59 +0000
parents cd125fe83051
children 4877008074a9
line wrap: on
line diff
--- a/Objects/unicodeobject.c	Mon Jun 11 16:12:10 2007 +0000
+++ b/Objects/unicodeobject.c	Mon Jun 11 16:36:59 2007 +0000
@@ -631,6 +631,18 @@
 				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 @@
 				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':
 			{