| OLD | NEW |
| 1 /* | 1 /* |
| 2 string_format.h -- implementation of string.format(). | 2 string_format.h -- implementation of string.format(). |
| 3 | 3 |
| 4 It uses the Objects/stringlib conventions, so that it can be | 4 It uses the Objects/stringlib conventions, so that it can be |
| 5 compiled for both unicode and string objects. | 5 compiled for both unicode and string objects. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 /* Defines for Python 2.6 compatability */ | 9 /* Defines for Python 2.6 compatability */ |
| 10 #if PY_VERSION_HEX < 0x03000000 | 10 #if PY_VERSION_HEX < 0x03000000 |
| (...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 (iternextfunc)formatteriter_next, /* tp_iternext */ | 1173 (iternextfunc)formatteriter_next, /* tp_iternext */ |
| 1174 formatteriter_methods, /* tp_methods */ | 1174 formatteriter_methods, /* tp_methods */ |
| 1175 0, | 1175 0, |
| 1176 }; | 1176 }; |
| 1177 | 1177 |
| 1178 /* unicode_formatter_parser is used to implement | 1178 /* unicode_formatter_parser is used to implement |
| 1179 string.Formatter.vformat. it parses a string and returns tuples | 1179 string.Formatter.vformat. it parses a string and returns tuples |
| 1180 describing the parsed elements. It's a wrapper around | 1180 describing the parsed elements. It's a wrapper around |
| 1181 stringlib/string_format.h's MarkupIterator */ | 1181 stringlib/string_format.h's MarkupIterator */ |
| 1182 static PyObject * | 1182 static PyObject * |
| 1183 formatter_parser(STRINGLIB_OBJECT *self) | 1183 formatter_parser(PyObject *ignored, STRINGLIB_OBJECT *self) |
| 1184 { | 1184 { |
| 1185 formatteriterobject *it; | 1185 formatteriterobject *it; |
| 1186 | 1186 |
| 1187 it = PyObject_New(formatteriterobject, &PyFormatterIter_Type); | 1187 it = PyObject_New(formatteriterobject, &PyFormatterIter_Type); |
| 1188 if (it == NULL) | 1188 if (it == NULL) |
| 1189 return NULL; | 1189 return NULL; |
| 1190 | 1190 |
| 1191 /* take ownership, give the object to the iterator */ | 1191 /* take ownership, give the object to the iterator */ |
| 1192 Py_INCREF(self); | 1192 Py_INCREF(self); |
| 1193 it->str = self; | 1193 it->str = self; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1308 0}; | 1308 0}; |
| 1309 | 1309 |
| 1310 /* unicode_formatter_field_name_split is used to implement | 1310 /* unicode_formatter_field_name_split is used to implement |
| 1311 string.Formatter.vformat. it takes an PEP 3101 "field name", and | 1311 string.Formatter.vformat. it takes an PEP 3101 "field name", and |
| 1312 returns a tuple of (first, rest): "first", the part before the | 1312 returns a tuple of (first, rest): "first", the part before the |
| 1313 first '.' or '['; and "rest", an iterator for the rest of the field | 1313 first '.' or '['; and "rest", an iterator for the rest of the field |
| 1314 name. it's a wrapper around stringlib/string_format.h's | 1314 name. it's a wrapper around stringlib/string_format.h's |
| 1315 field_name_split. The iterator it returns is a | 1315 field_name_split. The iterator it returns is a |
| 1316 FieldNameIterator */ | 1316 FieldNameIterator */ |
| 1317 static PyObject * | 1317 static PyObject * |
| 1318 formatter_field_name_split(STRINGLIB_OBJECT *self) | 1318 formatter_field_name_split(PyObject *ignored, STRINGLIB_OBJECT *self) |
| 1319 { | 1319 { |
| 1320 SubString first; | 1320 SubString first; |
| 1321 Py_ssize_t first_idx; | 1321 Py_ssize_t first_idx; |
| 1322 fieldnameiterobject *it; | 1322 fieldnameiterobject *it; |
| 1323 | 1323 |
| 1324 PyObject *first_obj = NULL; | 1324 PyObject *first_obj = NULL; |
| 1325 PyObject *result = NULL; | 1325 PyObject *result = NULL; |
| 1326 | 1326 |
| 1327 it = PyObject_New(fieldnameiterobject, &PyFieldNameIter_Type); | 1327 it = PyObject_New(fieldnameiterobject, &PyFieldNameIter_Type); |
| 1328 if (it == NULL) | 1328 if (it == NULL) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1350 goto done; | 1350 goto done; |
| 1351 | 1351 |
| 1352 /* return a tuple of values */ | 1352 /* return a tuple of values */ |
| 1353 result = PyTuple_Pack(2, first_obj, it); | 1353 result = PyTuple_Pack(2, first_obj, it); |
| 1354 | 1354 |
| 1355 done: | 1355 done: |
| 1356 Py_XDECREF(it); | 1356 Py_XDECREF(it); |
| 1357 Py_XDECREF(first_obj); | 1357 Py_XDECREF(first_obj); |
| 1358 return result; | 1358 return result; |
| 1359 } | 1359 } |
| OLD | NEW |