summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2008-02-17 19:46:49 (GMT)
committerEric Smith <eric@trueblade.com>2008-02-17 19:46:49 (GMT)
commita9f7d6248032c9572b4d2024a1be8bd2823af09f (patch)
tree5465a1051312055678248db0076d314924ee4ebc /Objects/unicodeobject.c
parente139688d34cc12b23d3a310f10d4f440f75f7d08 (diff)
downloadcpython-a9f7d6248032c9572b4d2024a1be8bd2823af09f.zip
cpython-a9f7d6248032c9572b4d2024a1be8bd2823af09f.tar.gz
cpython-a9f7d6248032c9572b4d2024a1be8bd2823af09f.tar.bz2
Backport of PEP 3101, Advanced String Formatting, from py3k.
Highlights: - Adding PyObject_Format. - Adding string.Format class. - Adding __format__ for str, unicode, int, long, float, datetime. - Adding builtin format. - Adding ''.format and u''.format. - str/unicode fixups for formatters. The files in Objects/stringlib that implement PEP 3101 (stringdefs.h, unicodedefs.h, formatter.h, string_format.h) are identical in trunk and py3k. Any changes from here on should be made to trunk, and changes will propogate to py3k).
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 3e15f53..0dca976 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -42,6 +42,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define PY_SSIZE_T_CLEAN
#include "Python.h"
+#include "formatter_unicode.h"
+
#include "unicodeobject.h"
#include "ucnhash.h"
@@ -5059,21 +5061,8 @@ int PyUnicode_EncodeDecimal(Py_UNICODE *s,
/* --- Helpers ------------------------------------------------------------ */
-#define STRINGLIB_CHAR Py_UNICODE
-
-#define STRINGLIB_LEN PyUnicode_GET_SIZE
-#define STRINGLIB_NEW PyUnicode_FromUnicode
-#define STRINGLIB_STR PyUnicode_AS_UNICODE
-
-Py_LOCAL_INLINE(int)
-STRINGLIB_CMP(const Py_UNICODE* str, const Py_UNICODE* other, Py_ssize_t len)
-{
- if (str[0] != other[0])
- return 1;
- return memcmp((void*) str, (void*) other, len * sizeof(Py_UNICODE));
-}
+#include "stringlib/unicodedefs.h"
-#define STRINGLIB_EMPTY unicode_empty
#define FROM_UNICODE
#include "stringlib/fastsearch.h"
@@ -7802,6 +7791,19 @@ unicode_endswith(PyUnicodeObject *self,
}
+/* Implements do_string_format, which is unicode because of stringlib */
+#include "stringlib/string_format.h"
+
+PyDoc_STRVAR(format__doc__,
+"S.format(*args, **kwargs) -> unicode\n\
+\n\
+");
+
+PyDoc_STRVAR(p_format__doc__,
+"S.__format__(format_spec) -> unicode\n\
+\n\
+");
+
static PyObject *
unicode_getnewargs(PyUnicodeObject *v)
@@ -7855,6 +7857,10 @@ static PyMethodDef unicode_methods[] = {
{"isalpha", (PyCFunction) unicode_isalpha, METH_NOARGS, isalpha__doc__},
{"isalnum", (PyCFunction) unicode_isalnum, METH_NOARGS, isalnum__doc__},
{"zfill", (PyCFunction) unicode_zfill, METH_VARARGS, zfill__doc__},
+ {"format", (PyCFunction) do_string_format, METH_VARARGS | METH_KEYWORDS, format__doc__},
+ {"__format__", (PyCFunction) unicode__format__, METH_VARARGS, p_format__doc__},
+ {"_formatter_field_name_split", (PyCFunction) formatter_field_name_split, METH_NOARGS},
+ {"_formatter_parser", (PyCFunction) formatter_parser, METH_NOARGS},
#if 0
{"capwords", (PyCFunction) unicode_capwords, METH_NOARGS, capwords__doc__},
#endif