Skip to content

Commit 3d1a1d7

Browse files
committed
Added prototypes for the new codec APIs for strings. These APIs
match the ones in the Unicode implementation, but were extended to be able to reuse the existing Unicode codecs for string purposes too. Conversion from string to Unicode and back are done using the default encoding.
1 parent 0a3f797 commit 3d1a1d7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Include/stringobject.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,37 @@ extern DL_IMPORT(PyObject *) PyString_InternFromString Py_PROTO((const char *));
8181
#define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)
8282
#define PyString_GET_SIZE(op) (((PyStringObject *)(op))->ob_size)
8383

84+
/* --- Generic Codecs ----------------------------------------------------- */
85+
86+
/* Create a string object by decoding the encoded string s of the
87+
given size. */
88+
89+
extern DL_IMPORT(PyObject*) PyString_Decode(
90+
const char *s, /* encoded string */
91+
int size, /* size of buffer */
92+
const char *encoding, /* encoding */
93+
const char *errors /* error handling */
94+
);
95+
96+
/* Encodes a char buffer of the given size and returns a
97+
Python string object. */
98+
99+
extern DL_IMPORT(PyObject*) PyString_Encode(
100+
const char *s, /* string char buffer */
101+
int size, /* number of chars to encode */
102+
const char *encoding, /* encoding */
103+
const char *errors /* error handling */
104+
);
105+
106+
/* Encodes a string object and returns the result as Python string
107+
object. */
108+
109+
extern DL_IMPORT(PyObject*) PyString_AsEncodedString(
110+
PyObject *str, /* string object */
111+
const char *encoding, /* encoding */
112+
const char *errors /* error handling */
113+
);
114+
84115
#ifdef __cplusplus
85116
}
86117
#endif

0 commit comments

Comments
 (0)