]>
Commit | Line | Data |
---|---|---|
4710c53d | 1 | \r |
2 | /* String (str/bytes) object interface */\r | |
3 | \r | |
4 | #ifndef Py_STRINGOBJECT_H\r | |
5 | #define Py_STRINGOBJECT_H\r | |
6 | #ifdef __cplusplus\r | |
7 | extern "C" {\r | |
8 | #endif\r | |
9 | \r | |
10 | #include <stdarg.h>\r | |
11 | \r | |
12 | /*\r | |
13 | Type PyStringObject represents a character string. An extra zero byte is\r | |
14 | reserved at the end to ensure it is zero-terminated, but a size is\r | |
15 | present so strings with null bytes in them can be represented. This\r | |
16 | is an immutable object type.\r | |
17 | \r | |
18 | There are functions to create new string objects, to test\r | |
19 | an object for string-ness, and to get the\r | |
20 | string value. The latter function returns a null pointer\r | |
21 | if the object is not of the proper type.\r | |
22 | There is a variant that takes an explicit size as well as a\r | |
23 | variant that assumes a zero-terminated string. Note that none of the\r | |
24 | functions should be applied to nil objects.\r | |
25 | */\r | |
26 | \r | |
27 | /* Caching the hash (ob_shash) saves recalculation of a string's hash value.\r | |
28 | Interning strings (ob_sstate) tries to ensure that only one string\r | |
29 | object with a given value exists, so equality tests can be one pointer\r | |
30 | comparison. This is generally restricted to strings that "look like"\r | |
31 | Python identifiers, although the intern() builtin can be used to force\r | |
32 | interning of any string.\r | |
33 | Together, these sped the interpreter by up to 20%. */\r | |
34 | \r | |
35 | typedef struct {\r | |
36 | PyObject_VAR_HEAD\r | |
37 | long ob_shash;\r | |
38 | int ob_sstate;\r | |
39 | char ob_sval[1];\r | |
40 | \r | |
41 | /* Invariants:\r | |
42 | * ob_sval contains space for 'ob_size+1' elements.\r | |
43 | * ob_sval[ob_size] == 0.\r | |
44 | * ob_shash is the hash of the string or -1 if not computed yet.\r | |
45 | * ob_sstate != 0 iff the string object is in stringobject.c's\r | |
46 | * 'interned' dictionary; in this case the two references\r | |
47 | * from 'interned' to this object are *not counted* in ob_refcnt.\r | |
48 | */\r | |
49 | } PyStringObject;\r | |
50 | \r | |
51 | #define SSTATE_NOT_INTERNED 0\r | |
52 | #define SSTATE_INTERNED_MORTAL 1\r | |
53 | #define SSTATE_INTERNED_IMMORTAL 2\r | |
54 | \r | |
55 | PyAPI_DATA(PyTypeObject) PyBaseString_Type;\r | |
56 | PyAPI_DATA(PyTypeObject) PyString_Type;\r | |
57 | \r | |
58 | #define PyString_Check(op) \\r | |
59 | PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS)\r | |
60 | #define PyString_CheckExact(op) (Py_TYPE(op) == &PyString_Type)\r | |
61 | \r | |
62 | PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);\r | |
63 | PyAPI_FUNC(PyObject *) PyString_FromString(const char *);\r | |
64 | PyAPI_FUNC(PyObject *) PyString_FromFormatV(const char*, va_list)\r | |
65 | Py_GCC_ATTRIBUTE((format(printf, 1, 0)));\r | |
66 | PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)\r | |
67 | Py_GCC_ATTRIBUTE((format(printf, 1, 2)));\r | |
68 | PyAPI_FUNC(Py_ssize_t) PyString_Size(PyObject *);\r | |
69 | PyAPI_FUNC(char *) PyString_AsString(PyObject *);\r | |
70 | PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);\r | |
71 | PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);\r | |
72 | PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);\r | |
73 | PyAPI_FUNC(int) _PyString_Resize(PyObject **, Py_ssize_t);\r | |
74 | PyAPI_FUNC(int) _PyString_Eq(PyObject *, PyObject*);\r | |
75 | PyAPI_FUNC(PyObject *) PyString_Format(PyObject *, PyObject *);\r | |
76 | PyAPI_FUNC(PyObject *) _PyString_FormatLong(PyObject*, int, int,\r | |
77 | int, char**, int*);\r | |
78 | PyAPI_FUNC(PyObject *) PyString_DecodeEscape(const char *, Py_ssize_t, \r | |
79 | const char *, Py_ssize_t,\r | |
80 | const char *);\r | |
81 | \r | |
82 | PyAPI_FUNC(void) PyString_InternInPlace(PyObject **);\r | |
83 | PyAPI_FUNC(void) PyString_InternImmortal(PyObject **);\r | |
84 | PyAPI_FUNC(PyObject *) PyString_InternFromString(const char *);\r | |
85 | PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void);\r | |
86 | \r | |
87 | /* Use only if you know it's a string */\r | |
88 | #define PyString_CHECK_INTERNED(op) (((PyStringObject *)(op))->ob_sstate)\r | |
89 | \r | |
90 | /* Macro, trading safety for speed */\r | |
91 | #define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)\r | |
92 | #define PyString_GET_SIZE(op) Py_SIZE(op)\r | |
93 | \r | |
94 | /* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*,\r | |
95 | x must be an iterable object. */\r | |
96 | PyAPI_FUNC(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);\r | |
97 | \r | |
98 | /* --- Generic Codecs ----------------------------------------------------- */\r | |
99 | \r | |
100 | /* Create an object by decoding the encoded string s of the\r | |
101 | given size. */\r | |
102 | \r | |
103 | PyAPI_FUNC(PyObject*) PyString_Decode(\r | |
104 | const char *s, /* encoded string */\r | |
105 | Py_ssize_t size, /* size of buffer */\r | |
106 | const char *encoding, /* encoding */\r | |
107 | const char *errors /* error handling */\r | |
108 | );\r | |
109 | \r | |
110 | /* Encodes a char buffer of the given size and returns a \r | |
111 | Python object. */\r | |
112 | \r | |
113 | PyAPI_FUNC(PyObject*) PyString_Encode(\r | |
114 | const char *s, /* string char buffer */\r | |
115 | Py_ssize_t size, /* number of chars to encode */\r | |
116 | const char *encoding, /* encoding */\r | |
117 | const char *errors /* error handling */\r | |
118 | );\r | |
119 | \r | |
120 | /* Encodes a string object and returns the result as Python \r | |
121 | object. */\r | |
122 | \r | |
123 | PyAPI_FUNC(PyObject*) PyString_AsEncodedObject(\r | |
124 | PyObject *str, /* string object */\r | |
125 | const char *encoding, /* encoding */\r | |
126 | const char *errors /* error handling */\r | |
127 | );\r | |
128 | \r | |
129 | /* Encodes a string object and returns the result as Python string\r | |
130 | object. \r | |
131 | \r | |
132 | If the codec returns an Unicode object, the object is converted\r | |
133 | back to a string using the default encoding.\r | |
134 | \r | |
135 | DEPRECATED - use PyString_AsEncodedObject() instead. */\r | |
136 | \r | |
137 | PyAPI_FUNC(PyObject*) PyString_AsEncodedString(\r | |
138 | PyObject *str, /* string object */\r | |
139 | const char *encoding, /* encoding */\r | |
140 | const char *errors /* error handling */\r | |
141 | );\r | |
142 | \r | |
143 | /* Decodes a string object and returns the result as Python \r | |
144 | object. */\r | |
145 | \r | |
146 | PyAPI_FUNC(PyObject*) PyString_AsDecodedObject(\r | |
147 | PyObject *str, /* string object */\r | |
148 | const char *encoding, /* encoding */\r | |
149 | const char *errors /* error handling */\r | |
150 | );\r | |
151 | \r | |
152 | /* Decodes a string object and returns the result as Python string\r | |
153 | object. \r | |
154 | \r | |
155 | If the codec returns an Unicode object, the object is converted\r | |
156 | back to a string using the default encoding.\r | |
157 | \r | |
158 | DEPRECATED - use PyString_AsDecodedObject() instead. */\r | |
159 | \r | |
160 | PyAPI_FUNC(PyObject*) PyString_AsDecodedString(\r | |
161 | PyObject *str, /* string object */\r | |
162 | const char *encoding, /* encoding */\r | |
163 | const char *errors /* error handling */\r | |
164 | );\r | |
165 | \r | |
166 | /* Provides access to the internal data buffer and size of a string\r | |
167 | object or the default encoded version of an Unicode object. Passing\r | |
168 | NULL as *len parameter will force the string buffer to be\r | |
169 | 0-terminated (passing a string with embedded NULL characters will\r | |
170 | cause an exception). */\r | |
171 | \r | |
172 | PyAPI_FUNC(int) PyString_AsStringAndSize(\r | |
173 | register PyObject *obj, /* string or Unicode object */\r | |
174 | register char **s, /* pointer to buffer variable */\r | |
175 | register Py_ssize_t *len /* pointer to length variable or NULL\r | |
176 | (only possible for 0-terminated\r | |
177 | strings) */\r | |
178 | );\r | |
179 | \r | |
180 | \r | |
181 | /* Using the current locale, insert the thousands grouping\r | |
182 | into the string pointed to by buffer. For the argument descriptions,\r | |
183 | see Objects/stringlib/localeutil.h */\r | |
184 | PyAPI_FUNC(Py_ssize_t) _PyString_InsertThousandsGroupingLocale(char *buffer,\r | |
185 | Py_ssize_t n_buffer,\r | |
186 | char *digits,\r | |
187 | Py_ssize_t n_digits,\r | |
188 | Py_ssize_t min_width);\r | |
189 | \r | |
190 | /* Using explicit passed-in values, insert the thousands grouping\r | |
191 | into the string pointed to by buffer. For the argument descriptions,\r | |
192 | see Objects/stringlib/localeutil.h */\r | |
193 | PyAPI_FUNC(Py_ssize_t) _PyString_InsertThousandsGrouping(char *buffer,\r | |
194 | Py_ssize_t n_buffer,\r | |
195 | char *digits,\r | |
196 | Py_ssize_t n_digits,\r | |
197 | Py_ssize_t min_width,\r | |
198 | const char *grouping,\r | |
199 | const char *thousands_sep);\r | |
200 | \r | |
201 | /* Format the object based on the format_spec, as defined in PEP 3101\r | |
202 | (Advanced String Formatting). */\r | |
203 | PyAPI_FUNC(PyObject *) _PyBytes_FormatAdvanced(PyObject *obj,\r | |
204 | char *format_spec,\r | |
205 | Py_ssize_t format_spec_len);\r | |
206 | \r | |
207 | #ifdef __cplusplus\r | |
208 | }\r | |
209 | #endif\r | |
210 | #endif /* !Py_STRINGOBJECT_H */\r |