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).
2008-02-17 15:46:49 -04:00
|
|
|
#ifndef STRINGLIB_STRINGDEFS_H
|
|
|
|
#define STRINGLIB_STRINGDEFS_H
|
|
|
|
|
|
|
|
/* this is sort of a hack. there's at least one place (formatting
|
|
|
|
floats) where some stringlib code takes a different path if it's
|
|
|
|
compiled as unicode. */
|
|
|
|
#define STRINGLIB_IS_UNICODE 0
|
|
|
|
|
2008-06-09 01:58:54 -03:00
|
|
|
#define STRINGLIB_OBJECT PyStringObject
|
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).
2008-02-17 15:46:49 -04:00
|
|
|
#define STRINGLIB_CHAR char
|
|
|
|
#define STRINGLIB_TYPE_NAME "string"
|
|
|
|
#define STRINGLIB_PARSE_CODE "S"
|
|
|
|
#define STRINGLIB_EMPTY nullstring
|
2010-01-13 03:55:48 -04:00
|
|
|
#define STRINGLIB_ISSPACE Py_ISSPACE
|
|
|
|
#define STRINGLIB_ISLINEBREAK(x) ((x == '\n') || (x == '\r'))
|
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).
2008-02-17 15:46:49 -04:00
|
|
|
#define STRINGLIB_ISDECIMAL(x) ((x >= '0') && (x <= '9'))
|
|
|
|
#define STRINGLIB_TODECIMAL(x) (STRINGLIB_ISDECIMAL(x) ? (x - '0') : -1)
|
2009-04-27 16:04:37 -03:00
|
|
|
#define STRINGLIB_TOUPPER Py_TOUPPER
|
|
|
|
#define STRINGLIB_TOLOWER Py_TOLOWER
|
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).
2008-02-17 15:46:49 -04:00
|
|
|
#define STRINGLIB_FILL memset
|
2008-06-09 01:58:54 -03:00
|
|
|
#define STRINGLIB_STR PyString_AS_STRING
|
|
|
|
#define STRINGLIB_LEN PyString_GET_SIZE
|
|
|
|
#define STRINGLIB_NEW PyString_FromStringAndSize
|
|
|
|
#define STRINGLIB_RESIZE _PyString_Resize
|
|
|
|
#define STRINGLIB_CHECK PyString_Check
|
2010-01-13 03:55:48 -04:00
|
|
|
#define STRINGLIB_CHECK_EXACT PyString_CheckExact
|
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).
2008-02-17 15:46:49 -04:00
|
|
|
#define STRINGLIB_TOSTR PyObject_Str
|
2008-06-09 01:58:54 -03:00
|
|
|
#define STRINGLIB_GROUPING _PyString_InsertThousandsGrouping
|
Backport of some of the work in r71665 to trunk. This reworks much of
int, long, and float __format__(), and it keeps their implementation
in sync with py3k.
Also added PyOS_double_to_string. This is the "fallback" version
that's also available in trunk, and should be kept in sync with that
code. I'll add an issue to document PyOS_double_to_string in the C
API.
There are many internal cleanups. Externally visible changes include:
- Implement PEP 378, Format Specifier for Thousands Separator, for
floats, ints, and longs.
- Issue #5515: 'n' formatting for ints, longs, and floats handles
leading zero formatting poorly.
- Issue #5772: For float.__format__, don't add a trailing ".0" if
we're using no type code and we have an exponent.
2009-04-22 10:29:05 -03:00
|
|
|
#define STRINGLIB_GROUPING_LOCALE _PyString_InsertThousandsGroupingLocale
|
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).
2008-02-17 15:46:49 -04:00
|
|
|
|
2010-01-13 03:55:48 -04:00
|
|
|
#define STRINGLIB_WANT_CONTAINS_OBJ 1
|
|
|
|
|
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).
2008-02-17 15:46:49 -04:00
|
|
|
#endif /* !STRINGLIB_STRINGDEFS_H */
|