1991-02-19 08:39:46 -04:00
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/* String object interface */
|
|
|
|
|
2000-07-08 21:55:06 -03:00
|
|
|
#ifndef Py_STRINGOBJECT_H
|
|
|
|
#define Py_STRINGOBJECT_H
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2001-08-24 15:32:06 -03:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/*
|
1995-01-12 07:45:45 -04:00
|
|
|
Type PyStringObject represents a character string. An extra zero byte is
|
1990-10-14 09:07:46 -03:00
|
|
|
reserved at the end to ensure it is zero-terminated, but a size is
|
|
|
|
present so strings with null bytes in them can be represented. This
|
|
|
|
is an immutable object type.
|
|
|
|
|
|
|
|
There are functions to create new string objects, to test
|
|
|
|
an object for string-ness, and to get the
|
|
|
|
string value. The latter function returns a null pointer
|
|
|
|
if the object is not of the proper type.
|
|
|
|
There is a variant that takes an explicit size as well as a
|
|
|
|
variant that assumes a zero-terminated string. Note that none of the
|
|
|
|
functions should be applied to nil objects.
|
|
|
|
*/
|
|
|
|
|
2002-03-28 23:29:08 -04:00
|
|
|
/* Caching the hash (ob_shash) saves recalculation of a string's hash value.
|
2007-11-06 17:34:58 -04:00
|
|
|
This significantly speeds up dict lookups. */
|
1996-07-30 13:42:03 -03:00
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
typedef struct {
|
2000-07-08 21:55:06 -03:00
|
|
|
PyObject_VAR_HEAD
|
|
|
|
long ob_shash;
|
|
|
|
char ob_sval[1];
|
2004-10-28 13:32:00 -03:00
|
|
|
|
|
|
|
/* Invariants:
|
|
|
|
* ob_sval contains space for 'ob_size+1' elements.
|
|
|
|
* ob_sval[ob_size] == 0.
|
|
|
|
* ob_shash is the hash of the string or -1 if not computed yet.
|
|
|
|
*/
|
1995-01-12 07:45:45 -04:00
|
|
|
} PyStringObject;
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_DATA(PyTypeObject) PyString_Type;
|
2007-11-29 18:35:39 -04:00
|
|
|
PyAPI_DATA(PyTypeObject) PyStringIter_Type;
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2007-02-25 16:39:11 -04:00
|
|
|
#define PyString_Check(op) \
|
2007-12-18 22:45:37 -04:00
|
|
|
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS)
|
|
|
|
#define PyString_CheckExact(op) (Py_TYPE(op) == &PyString_Type)
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2006-02-15 13:27:45 -04:00
|
|
|
PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyString_FromString(const char *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyString_FromFormatV(const char*, va_list)
|
2002-09-15 11:09:54 -03:00
|
|
|
Py_GCC_ATTRIBUTE((format(printf, 1, 0)));
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)
|
2002-09-15 11:09:54 -03:00
|
|
|
Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
|
2006-02-15 13:27:45 -04:00
|
|
|
PyAPI_FUNC(Py_ssize_t) PyString_Size(PyObject *);
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(char *) PyString_AsString(PyObject *);
|
2002-08-14 04:46:28 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);
|
|
|
|
PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);
|
2006-02-15 13:27:45 -04:00
|
|
|
PyAPI_FUNC(int) _PyString_Resize(PyObject **, Py_ssize_t);
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyString_Format(PyObject *, PyObject *);
|
|
|
|
PyAPI_FUNC(PyObject *) _PyString_FormatLong(PyObject*, int, int,
|
2000-09-21 02:43:11 -03:00
|
|
|
int, char**, int*);
|
2007-10-26 16:34:40 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyString_DecodeEscape(const char *, Py_ssize_t,
|
2006-02-15 13:27:45 -04:00
|
|
|
const char *, Py_ssize_t,
|
2002-08-14 04:46:28 -03:00
|
|
|
const char *);
|
1990-10-14 09:07:46 -03:00
|
|
|
|
|
|
|
/* Macro, trading safety for speed */
|
2007-11-06 17:34:58 -04:00
|
|
|
#define PyString_AS_STRING(op) (assert(PyString_Check(op)), \
|
|
|
|
(((PyStringObject *)(op))->ob_sval))
|
2007-12-18 22:45:37 -04:00
|
|
|
#define PyString_GET_SIZE(op) (assert(PyString_Check(op)),Py_SIZE(op))
|
1993-07-28 06:05:47 -03:00
|
|
|
|
2001-06-16 02:11:17 -03:00
|
|
|
/* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*,
|
|
|
|
x must be an iterable object. */
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);
|
2001-06-16 02:11:17 -03:00
|
|
|
|
2000-09-19 18:04:18 -03:00
|
|
|
/* Provides access to the internal data buffer and size of a string
|
|
|
|
object or the default encoded version of an Unicode object. Passing
|
|
|
|
NULL as *len parameter will force the string buffer to be
|
|
|
|
0-terminated (passing a string with embedded NULL characters will
|
|
|
|
cause an exception). */
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(int) PyString_AsStringAndSize(
|
2000-09-19 18:04:18 -03:00
|
|
|
register PyObject *obj, /* string or Unicode object */
|
|
|
|
register char **s, /* pointer to buffer variable */
|
2006-02-15 13:27:45 -04:00
|
|
|
register Py_ssize_t *len /* pointer to length variable or NULL
|
2000-09-19 18:04:18 -03:00
|
|
|
(only possible for 0-terminated
|
|
|
|
strings) */
|
|
|
|
);
|
2007-10-26 16:34:40 -03:00
|
|
|
|
Merged revisions 63078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
When forward porting this, I added _PyUnicode_InsertThousandsGrouping.
........
r63078 | eric.smith | 2008-05-11 15:52:48 -0400 (Sun, 11 May 2008) | 14 lines
Addresses issue 2802: 'n' formatting for integers.
Adds 'n' as a format specifier for integers, to mirror the same
specifier which is already available for floats. 'n' is the same as
'd', but inserts the current locale-specific thousands grouping.
I added this as a stringlib function, but it's only used by str type,
not unicode. This is because of an implementation detail in
unicode.format(), which does its own str->unicode conversion. But the
unicode version will be needed in 3.0, and it may be needed by other
code eventually in 2.6 (maybe decimal?), so I left it as a stringlib
implementation. As long as the unicode version isn't instantiated,
there's no overhead for this.
........
2008-05-11 18:00:57 -03:00
|
|
|
/* Using the current locale, insert the thousands grouping
|
|
|
|
into the string pointed to by buffer. For the argument descriptions,
|
|
|
|
see Objects/stringlib/localeutil.h */
|
|
|
|
|
|
|
|
PyAPI_FUNC(int) _PyString_InsertThousandsGrouping(char *buffer,
|
|
|
|
Py_ssize_t len,
|
|
|
|
char *plast,
|
|
|
|
Py_ssize_t buf_size,
|
|
|
|
Py_ssize_t *count,
|
|
|
|
int append_zero_char);
|
|
|
|
|
2007-11-06 17:34:58 -04:00
|
|
|
/* Flags used by string formatting */
|
|
|
|
#define F_LJUST (1<<0)
|
|
|
|
#define F_SIGN (1<<1)
|
|
|
|
#define F_BLANK (1<<2)
|
|
|
|
#define F_ALT (1<<3)
|
|
|
|
#define F_ZERO (1<<4)
|
2000-09-19 18:04:18 -03:00
|
|
|
|
1993-07-28 06:05:47 -03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* !Py_STRINGOBJECT_H */
|