1991-02-19 20:39:46 +08:00
|
|
|
|
1990-10-14 20:07:46 +08:00
|
|
|
/* String object interface */
|
|
|
|
|
2000-07-09 08:55:06 +08:00
|
|
|
#ifndef Py_STRINGOBJECT_H
|
|
|
|
#define Py_STRINGOBJECT_H
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2001-08-25 02:32:06 +08:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
1990-10-14 20:07:46 +08:00
|
|
|
/*
|
1995-01-12 19:45:45 +08:00
|
|
|
Type PyStringObject represents a character string. An extra zero byte is
|
1990-10-14 20:07:46 +08: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 11:29:08 +08:00
|
|
|
/* Caching the hash (ob_shash) saves recalculation of a string's hash value.
|
2002-08-20 05:43:18 +08:00
|
|
|
Interning strings (ob_sstate) tries to ensure that only one string
|
2002-03-29 11:29:08 +08: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-31 00:42:03 +08:00
|
|
|
|
1990-10-14 20:07:46 +08:00
|
|
|
typedef struct {
|
2000-07-09 08:55:06 +08:00
|
|
|
PyObject_VAR_HEAD
|
|
|
|
long ob_shash;
|
2002-08-20 05:43:18 +08:00
|
|
|
int ob_sstate;
|
2000-07-09 08:55:06 +08:00
|
|
|
char ob_sval[1];
|
1995-01-12 19:45:45 +08:00
|
|
|
} PyStringObject;
|
1990-10-14 20:07:46 +08:00
|
|
|
|
2002-08-20 05:43:18 +08:00
|
|
|
#define SSTATE_NOT_INTERNED 0
|
|
|
|
#define SSTATE_INTERNED_MORTAL 1
|
|
|
|
#define SSTATE_INTERNED_IMMORTAL 2
|
|
|
|
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_DATA(PyTypeObject) PyBaseString_Type;
|
|
|
|
PyAPI_DATA(PyTypeObject) PyString_Type;
|
1990-10-14 20:07:46 +08:00
|
|
|
|
2001-08-30 11:08:07 +08:00
|
|
|
#define PyString_Check(op) PyObject_TypeCheck(op, &PyString_Type)
|
2001-09-11 09:41:59 +08:00
|
|
|
#define PyString_CheckExact(op) ((op)->ob_type == &PyString_Type)
|
1990-10-14 20:07:46 +08:00
|
|
|
|
2002-08-12 15:21:58 +08: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)
|
2002-09-15 22:09:54 +08:00
|
|
|
Py_GCC_ATTRIBUTE((format(printf, 1, 0)));
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)
|
2002-09-15 22:09:54 +08:00
|
|
|
Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(int) PyString_Size(PyObject *);
|
|
|
|
PyAPI_FUNC(char *) PyString_AsString(PyObject *);
|
2002-08-14 15:46:28 +08:00
|
|
|
PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);
|
2002-08-12 15:21:58 +08: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 13:43:11 +08:00
|
|
|
int, char**, int*);
|
2002-08-14 15:46:28 +08:00
|
|
|
extern DL_IMPORT(PyObject *) PyString_DecodeEscape(const char *, int,
|
|
|
|
const char *, int,
|
|
|
|
const char *);
|
1990-10-14 20:07:46 +08:00
|
|
|
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(void) PyString_InternInPlace(PyObject **);
|
2002-08-20 05:43:18 +08:00
|
|
|
PyAPI_FUNC(void) PyString_InternImmortal(PyObject **);
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(PyObject *) PyString_InternFromString(const char *);
|
|
|
|
PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void);
|
1997-01-18 15:53:23 +08:00
|
|
|
|
2002-08-20 05:43:18 +08:00
|
|
|
/* Use only if you know it's a string */
|
|
|
|
#define PyString_CHECK_INTERNED(op) (((PyStringObject *)(op))->ob_sstate)
|
|
|
|
|
1990-10-14 20:07:46 +08:00
|
|
|
/* Macro, trading safety for speed */
|
1997-01-07 06:42:50 +08:00
|
|
|
#define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)
|
|
|
|
#define PyString_GET_SIZE(op) (((PyStringObject *)(op))->ob_size)
|
1993-07-28 17:05:47 +08:00
|
|
|
|
2001-06-16 13:11:17 +08:00
|
|
|
/* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*,
|
|
|
|
x must be an iterable object. */
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);
|
2001-06-16 13:11:17 +08:00
|
|
|
|
2000-07-06 19:25:40 +08:00
|
|
|
/* --- Generic Codecs ----------------------------------------------------- */
|
|
|
|
|
2001-05-15 20:00:02 +08:00
|
|
|
/* Create an object by decoding the encoded string s of the
|
2000-07-06 19:25:40 +08:00
|
|
|
given size. */
|
|
|
|
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(PyObject*) PyString_Decode(
|
2000-07-06 19:25:40 +08: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 20:00:02 +08:00
|
|
|
Python object. */
|
2000-07-06 19:25:40 +08:00
|
|
|
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(PyObject*) PyString_Encode(
|
2000-07-06 19:25:40 +08: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 20:00:02 +08:00
|
|
|
/* Encodes a string object and returns the result as Python
|
2000-07-06 19:25:40 +08:00
|
|
|
object. */
|
|
|
|
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(PyObject*) PyString_AsEncodedObject(
|
2001-05-15 20:00:02 +08: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 15:21:58 +08:00
|
|
|
PyAPI_FUNC(PyObject*) PyString_AsEncodedString(
|
2000-07-06 19:25:40 +08:00
|
|
|
PyObject *str, /* string object */
|
|
|
|
const char *encoding, /* encoding */
|
|
|
|
const char *errors /* error handling */
|
|
|
|
);
|
|
|
|
|
2001-05-15 20:00:02 +08:00
|
|
|
/* Decodes a string object and returns the result as Python
|
|
|
|
object. */
|
|
|
|
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(PyObject*) PyString_AsDecodedObject(
|
2001-05-15 20:00:02 +08: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 15:21:58 +08:00
|
|
|
PyAPI_FUNC(PyObject*) PyString_AsDecodedString(
|
2001-05-15 20:00:02 +08:00
|
|
|
PyObject *str, /* string object */
|
|
|
|
const char *encoding, /* encoding */
|
|
|
|
const char *errors /* error handling */
|
|
|
|
);
|
|
|
|
|
2000-09-20 05:04:18 +08: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 15:21:58 +08:00
|
|
|
PyAPI_FUNC(int) PyString_AsStringAndSize(
|
2000-09-20 05:04:18 +08: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 17:05:47 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* !Py_STRINGOBJECT_H */
|