-\r
-/* String (str/bytes) object interface */\r
-\r
-#ifndef Py_STRINGOBJECT_H\r
-#define Py_STRINGOBJECT_H\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-#include <stdarg.h>\r
-\r
-/*\r
-Type PyStringObject represents a character string. An extra zero byte is\r
-reserved at the end to ensure it is zero-terminated, but a size is\r
-present so strings with null bytes in them can be represented. This\r
-is an immutable object type.\r
-\r
-There are functions to create new string objects, to test\r
-an object for string-ness, and to get the\r
-string value. The latter function returns a null pointer\r
-if the object is not of the proper type.\r
-There is a variant that takes an explicit size as well as a\r
-variant that assumes a zero-terminated string. Note that none of the\r
-functions should be applied to nil objects.\r
-*/\r
-\r
-/* Caching the hash (ob_shash) saves recalculation of a string's hash value.\r
- Interning strings (ob_sstate) tries to ensure that only one string\r
- object with a given value exists, so equality tests can be one pointer\r
- comparison. This is generally restricted to strings that "look like"\r
- Python identifiers, although the intern() builtin can be used to force\r
- interning of any string.\r
- Together, these sped the interpreter by up to 20%. */\r
-\r
-typedef struct {\r
- PyObject_VAR_HEAD\r
- long ob_shash;\r
- int ob_sstate;\r
- char ob_sval[1];\r
-\r
- /* Invariants:\r
- * ob_sval contains space for 'ob_size+1' elements.\r
- * ob_sval[ob_size] == 0.\r
- * ob_shash is the hash of the string or -1 if not computed yet.\r
- * ob_sstate != 0 iff the string object is in stringobject.c's\r
- * 'interned' dictionary; in this case the two references\r
- * from 'interned' to this object are *not counted* in ob_refcnt.\r
- */\r
-} PyStringObject;\r
-\r
-#define SSTATE_NOT_INTERNED 0\r
-#define SSTATE_INTERNED_MORTAL 1\r
-#define SSTATE_INTERNED_IMMORTAL 2\r
-\r
-PyAPI_DATA(PyTypeObject) PyBaseString_Type;\r
-PyAPI_DATA(PyTypeObject) PyString_Type;\r
-\r
-#define PyString_Check(op) \\r
- PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS)\r
-#define PyString_CheckExact(op) (Py_TYPE(op) == &PyString_Type)\r
-\r
-PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);\r
-PyAPI_FUNC(PyObject *) PyString_FromString(const char *);\r
-PyAPI_FUNC(PyObject *) PyString_FromFormatV(const char*, va_list)\r
- Py_GCC_ATTRIBUTE((format(printf, 1, 0)));\r
-PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)\r
- Py_GCC_ATTRIBUTE((format(printf, 1, 2)));\r
-PyAPI_FUNC(Py_ssize_t) PyString_Size(PyObject *);\r
-PyAPI_FUNC(char *) PyString_AsString(PyObject *);\r
-PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);\r
-PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);\r
-PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);\r
-PyAPI_FUNC(int) _PyString_Resize(PyObject **, Py_ssize_t);\r
-PyAPI_FUNC(int) _PyString_Eq(PyObject *, PyObject*);\r
-PyAPI_FUNC(PyObject *) PyString_Format(PyObject *, PyObject *);\r
-PyAPI_FUNC(PyObject *) _PyString_FormatLong(PyObject*, int, int,\r
- int, char**, int*);\r
-PyAPI_FUNC(PyObject *) PyString_DecodeEscape(const char *, Py_ssize_t, \r
- const char *, Py_ssize_t,\r
- const char *);\r
-\r
-PyAPI_FUNC(void) PyString_InternInPlace(PyObject **);\r
-PyAPI_FUNC(void) PyString_InternImmortal(PyObject **);\r
-PyAPI_FUNC(PyObject *) PyString_InternFromString(const char *);\r
-PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void);\r
-\r
-/* Use only if you know it's a string */\r
-#define PyString_CHECK_INTERNED(op) (((PyStringObject *)(op))->ob_sstate)\r
-\r
-/* Macro, trading safety for speed */\r
-#define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)\r
-#define PyString_GET_SIZE(op) Py_SIZE(op)\r
-\r
-/* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*,\r
- x must be an iterable object. */\r
-PyAPI_FUNC(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);\r
-\r
-/* --- Generic Codecs ----------------------------------------------------- */\r
-\r
-/* Create an object by decoding the encoded string s of the\r
- given size. */\r
-\r
-PyAPI_FUNC(PyObject*) PyString_Decode(\r
- const char *s, /* encoded string */\r
- Py_ssize_t size, /* size of buffer */\r
- const char *encoding, /* encoding */\r
- const char *errors /* error handling */\r
- );\r
-\r
-/* Encodes a char buffer of the given size and returns a \r
- Python object. */\r
-\r
-PyAPI_FUNC(PyObject*) PyString_Encode(\r
- const char *s, /* string char buffer */\r
- Py_ssize_t size, /* number of chars to encode */\r
- const char *encoding, /* encoding */\r
- const char *errors /* error handling */\r
- );\r
-\r
-/* Encodes a string object and returns the result as Python \r
- object. */\r
-\r
-PyAPI_FUNC(PyObject*) PyString_AsEncodedObject(\r
- PyObject *str, /* string object */\r
- const char *encoding, /* encoding */\r
- const char *errors /* error handling */\r
- );\r
-\r
-/* Encodes a string object and returns the result as Python string\r
- object. \r
- \r
- If the codec returns an Unicode object, the object is converted\r
- back to a string using the default encoding.\r
-\r
- DEPRECATED - use PyString_AsEncodedObject() instead. */\r
-\r
-PyAPI_FUNC(PyObject*) PyString_AsEncodedString(\r
- PyObject *str, /* string object */\r
- const char *encoding, /* encoding */\r
- const char *errors /* error handling */\r
- );\r
-\r
-/* Decodes a string object and returns the result as Python \r
- object. */\r
-\r
-PyAPI_FUNC(PyObject*) PyString_AsDecodedObject(\r
- PyObject *str, /* string object */\r
- const char *encoding, /* encoding */\r
- const char *errors /* error handling */\r
- );\r
-\r
-/* Decodes a string object and returns the result as Python string\r
- object. \r
- \r
- If the codec returns an Unicode object, the object is converted\r
- back to a string using the default encoding.\r
-\r
- DEPRECATED - use PyString_AsDecodedObject() instead. */\r
-\r
-PyAPI_FUNC(PyObject*) PyString_AsDecodedString(\r
- PyObject *str, /* string object */\r
- const char *encoding, /* encoding */\r
- const char *errors /* error handling */\r
- );\r
-\r
-/* Provides access to the internal data buffer and size of a string\r
- object or the default encoded version of an Unicode object. Passing\r
- NULL as *len parameter will force the string buffer to be\r
- 0-terminated (passing a string with embedded NULL characters will\r
- cause an exception). */\r
-\r
-PyAPI_FUNC(int) PyString_AsStringAndSize(\r
- register PyObject *obj, /* string or Unicode object */\r
- register char **s, /* pointer to buffer variable */\r
- register Py_ssize_t *len /* pointer to length variable or NULL\r
- (only possible for 0-terminated\r
- strings) */\r
- );\r
-\r
-\r
-/* Using the current locale, insert the thousands grouping\r
- into the string pointed to by buffer. For the argument descriptions,\r
- see Objects/stringlib/localeutil.h */\r
-PyAPI_FUNC(Py_ssize_t) _PyString_InsertThousandsGroupingLocale(char *buffer,\r
- Py_ssize_t n_buffer,\r
- char *digits,\r
- Py_ssize_t n_digits,\r
- Py_ssize_t min_width);\r
-\r
-/* Using explicit passed-in values, insert the thousands grouping\r
- into the string pointed to by buffer. For the argument descriptions,\r
- see Objects/stringlib/localeutil.h */\r
-PyAPI_FUNC(Py_ssize_t) _PyString_InsertThousandsGrouping(char *buffer,\r
- Py_ssize_t n_buffer,\r
- char *digits,\r
- Py_ssize_t n_digits,\r
- Py_ssize_t min_width,\r
- const char *grouping,\r
- const char *thousands_sep);\r
-\r
-/* Format the object based on the format_spec, as defined in PEP 3101\r
- (Advanced String Formatting). */\r
-PyAPI_FUNC(PyObject *) _PyBytes_FormatAdvanced(PyObject *obj,\r
- char *format_spec,\r
- Py_ssize_t format_spec_len);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-#endif /* !Py_STRINGOBJECT_H */\r