Index: Include/unicodeobject.h =================================================================== --- Include/unicodeobject.h (révision 70384) +++ Include/unicodeobject.h (copie de travail) @@ -1574,6 +1574,13 @@ Py_UNICODE ch /* Unicode character */ ); +/* Number of bytes needed to encode the unicode character + as UTF-8 */ + +PyAPI_FUNC(int) _PyUnicode_UTF8Size( + Py_UNICODE ch /* Unicode character */ + ); + PyAPI_FUNC(size_t) Py_UNICODE_strlen(const Py_UNICODE *u); PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcpy( Index: Objects/unicodectype.c =================================================================== --- Objects/unicodectype.c (révision 70384) +++ Objects/unicodectype.c (copie de travail) @@ -838,3 +838,18 @@ } #endif + +int _PyUnicode_UTF8Size(Py_UNICODE code) +{ + if (code < 0x80) + return 1; + if (code < 0x0800) + return 2; +#ifdef Py_UNICODE_WIDE + if (code < 0x10000) + return 3; + return 4; +#else + return 3; +#endif +}