1991-02-19 12:39:46 +00:00
|
|
|
|
1990-10-14 12:07:46 +00:00
|
|
|
/* String object interface */
|
|
|
|
|
2000-07-09 00:55:06 +00:00
|
|
|
#ifndef Py_STRINGOBJECT_H
|
|
|
|
#define Py_STRINGOBJECT_H
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2001-08-24 18:32:06 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
1990-10-14 12:07:46 +00:00
|
|
|
/*
|
1995-01-12 11:45:45 +00:00
|
|
|
Type PyStringObject represents a character string. An extra zero byte is
|
1990-10-14 12:07:46 +00: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-29 03:29:08 +00:00
|
|
|
/* Caching the hash (ob_shash) saves recalculation of a string's hash value.
|
2002-08-19 21:43:18 +00:00
|
|
|
Interning strings (ob_sstate) tries to ensure that only one string
|
2002-03-29 03:29:08 +00:00
|
|
|
object with a given value exists, so equality tests can be one pointer
|
|
|
|
comparison. This is generally restricted to strings that "look like"
|
|
|
|
Python identifiers, although the intern() builtin can be used to force
|
|
|
|
interning of any string.
|
|
|
|
Together, these sped the interpreter by up to 20%. */
|
1996-07-30 16:42:03 +00:00
|
|
|
|
1990-10-14 12:07:46 +00:00
|
|
|
typedef struct {
|
2000-07-09 00:55:06 +00:00
|
|
|
PyObject_VAR_HEAD
|
|
|
|
long ob_shash;
|
2002-08-19 21:43:18 +00:00
|
|
|
int ob_sstate;
|
2000-07-09 00:55:06 +00:00
|
|
|
char ob_sval[1];
|
1995-01-12 11:45:45 +00:00
|
|
|
} PyStringObject;
|
1990-10-14 12:07:46 +00:00
|
|
|
|
2002-08-19 21:43:18 +00:00
|
|
|
#define SSTATE_NOT_INTERNED 0
|
|
|
|
#define SSTATE_INTERNED_MORTAL 1
|
|
|
|
#define SSTATE_INTERNED_IMMORTAL 2
|
|
|
|
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_DATA(PyTypeObject) PyBaseString_Type;
|
|
|
|
PyAPI_DATA(PyTypeObject) PyString_Type;
|
1990-10-14 12:07:46 +00:00
|
|
|
|
2001-08-30 03:08:07 +00:00
|
|
|
#define PyString_Check(op) PyObject_TypeCheck(op, &PyString_Type)
|
2001-09-11 01:41:59 +00:00
|
|
|
#define PyString_CheckExact(op) ((op)->ob_type == &PyString_Type)
|
1990-10-14 12:07:46 +00:00
|
|
|
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, int);
|
|
|
|
PyAPI_FUNC(PyObject *) PyString_FromString(const char *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyString_FromFormatV(const char*, va_list)
|
2001-10-23 02:21:22 +00:00
|
|
|
__attribute__((format(printf, 1, 0)));
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)
|
2001-10-23 02:21:22 +00:00
|
|
|
__attribute__((format(printf, 1, 2)));
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_FUNC(int) PyString_Size(PyObject *);
|
|
|
|
PyAPI_FUNC(char *) PyString_AsString(PyObject *);
|
2002-08-14 07:46:28 +00:00
|
|
|
PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);
|
|
|
|
PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);
|
|
|
|
PyAPI_FUNC(int) _PyString_Resize(PyObject **, int);
|
|
|
|
PyAPI_FUNC(int) _PyString_Eq(PyObject *, PyObject*);
|
|
|
|
PyAPI_FUNC(PyObject *) PyString_Format(PyObject *, PyObject *);
|
|
|
|
PyAPI_FUNC(PyObject *) _PyString_FormatLong(PyObject*, int, int,
|
2000-09-21 05:43:11 +00:00
|
|
|
int, char**, int*);
|
2002-08-14 07:46:28 +00:00
|
|
|
extern DL_IMPORT(PyObject *) PyString_DecodeEscape(const char *, int,
|
|
|
|
const char *, int,
|
|
|
|
const char *);
|
1990-10-14 12:07:46 +00:00
|
|
|
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_FUNC(void) PyString_InternInPlace(PyObject **);
|
2002-08-19 21:43:18 +00:00
|
|
|
PyAPI_FUNC(void) PyString_InternImmortal(PyObject **);
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_FUNC(PyObject *) PyString_InternFromString(const char *);
|
|
|
|
PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void);
|
1997-01-18 07:53:23 +00:00
|
|
|
|
2002-08-19 21:43:18 +00:00
|
|
|
/* Use only if you know it's a string */
|
|
|
|
#define PyString_CHECK_INTERNED(op) (((PyStringObject *)(op))->ob_sstate)
|
|
|
|
|
1990-10-14 12:07:46 +00:00
|
|
|
/* Macro, trading safety for speed */
|
1997-01-06 22:42:50 +00:00
|
|
|
#define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)
|
|
|
|
#define PyString_GET_SIZE(op) (((PyStringObject *)(op))->ob_size)
|
1993-07-28 09:05:47 +00:00
|
|
|
|
2001-06-16 05:11:17 +00:00
|
|
|
/* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*,
|
|
|
|
x must be an iterable object. */
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_FUNC(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);
|
2001-06-16 05:11:17 +00:00
|
|
|
|
2000-07-06 11:25:40 +00:00
|
|
|
/* --- Generic Codecs ----------------------------------------------------- */
|
|
|
|
|
2001-05-15 12:00:02 +00:00
|
|
|
/* Create an object by decoding the encoded string s of the
|
2000-07-06 11:25:40 +00:00
|
|
|
given size. */
|
|
|
|
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_FUNC(PyObject*) PyString_Decode(
|
2000-07-06 11:25:40 +00:00
|
|
|
const char *s, /* encoded string */
|
|
|
|
int size, /* size of buffer */
|
|
|
|
const char *encoding, /* encoding */
|
|
|
|
const char *errors /* error handling */
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Encodes a char buffer of the given size and returns a
|
2001-05-15 12:00:02 +00:00
|
|
|
Python object. */
|
2000-07-06 11:25:40 +00:00
|
|
|
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_FUNC(PyObject*) PyString_Encode(
|
2000-07-06 11:25:40 +00:00
|
|
|
const char *s, /* string char buffer */
|
|
|
|
int size, /* number of chars to encode */
|
|
|
|
const char *encoding, /* encoding */
|
|
|
|
const char *errors /* error handling */
|
|
|
|
);
|
|
|
|
|
2001-05-15 12:00:02 +00:00
|
|
|
/* Encodes a string object and returns the result as Python
|
2000-07-06 11:25:40 +00:00
|
|
|
object. */
|
|
|
|
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_FUNC(PyObject*) PyString_AsEncodedObject(
|
2001-05-15 12:00:02 +00:00
|
|
|
PyObject *str, /* string object */
|
|
|
|
const char *encoding, /* encoding */
|
|
|
|
const char *errors /* error handling */
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Encodes a string object and returns the result as Python string
|
|
|
|
object.
|
|
|
|
|
|
|
|
If the codec returns an Unicode object, the object is converted
|
|
|
|
back to a string using the default encoding.
|
|
|
|
|
|
|
|
DEPRECATED - use PyString_AsEncodedObject() instead. */
|
|
|
|
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_FUNC(PyObject*) PyString_AsEncodedString(
|
2000-07-06 11:25:40 +00:00
|
|
|
PyObject *str, /* string object */
|
|
|
|
const char *encoding, /* encoding */
|
|
|
|
const char *errors /* error handling */
|
|
|
|
);
|
|
|
|
|
2001-05-15 12:00:02 +00:00
|
|
|
/* Decodes a string object and returns the result as Python
|
|
|
|
object. */
|
|
|
|
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_FUNC(PyObject*) PyString_AsDecodedObject(
|
2001-05-15 12:00:02 +00:00
|
|
|
PyObject *str, /* string object */
|
|
|
|
const char *encoding, /* encoding */
|
|
|
|
const char *errors /* error handling */
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Decodes a string object and returns the result as Python string
|
|
|
|
object.
|
|
|
|
|
|
|
|
If the codec returns an Unicode object, the object is converted
|
|
|
|
back to a string using the default encoding.
|
|
|
|
|
|
|
|
DEPRECATED - use PyString_AsDecodedObject() instead. */
|
|
|
|
|
2002-08-12 07:21:58 +00:00
|
|
|
PyAPI_FUNC(PyObject*) PyString_AsDecodedString(
|
2001-05-15 12:00:02 +00:00
|
|
|
PyObject *str, /* string object */
|
|
|
|
const char *encoding, /* encoding */
|
|
|
|
const char *errors /* error handling */
|
|
|
|
);
|
|
|
|
|
2000-09-19 21:04:18 +00: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 07:21:58 +00:00
|
|
|
PyAPI_FUNC(int) PyString_AsStringAndSize(
|
2000-09-19 21:04:18 +00:00
|
|
|
register PyObject *obj, /* string or Unicode object */
|
|
|
|
register char **s, /* pointer to buffer variable */
|
|
|
|
register int *len /* pointer to length variable or NULL
|
|
|
|
(only possible for 0-terminated
|
|
|
|
strings) */
|
|
|
|
);
|
|
|
|
|
|
|
|
|
1993-07-28 09:05:47 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* !Py_STRINGOBJECT_H */
|