Debian Codegraph @

pypy/module/cpyext/include/unicodeobject.h

raw symbols SCIP
1 #ifndef Py_UNICODEOBJECT_H
2 #define Py_UNICODEOBJECT_H
3
4 /* start sync with cpython unicodeobject.h line 65 */
5 #ifndef SIZEOF_WCHAR_T
6 #error Must define SIZEOF_WCHAR_T
7 #endif
8
9 #define Py_UNICODE_SIZE SIZEOF_WCHAR_T
10
11 /* If wchar_t can be used for UCS-4 storage, set Py_UNICODE_WIDE.
12 Otherwise, Unicode strings are stored as UCS-2 (with limited support
13 for UTF-16) */
14
15 #if Py_UNICODE_SIZE >= 4
16 #define Py_UNICODE_WIDE
17 #endif
18
19 /* Set these flags if the platform has "wchar.h" and the
20 wchar_t type is a 16-bit unsigned type */
21 /* #define HAVE_WCHAR_H */
22 /* #define HAVE_USABLE_WCHAR_T */
23
24 /* If the compiler provides a wchar_t type we try to support it
25 through the interface functions PyUnicode_FromWideChar(),
26 PyUnicode_AsWideChar() and PyUnicode_AsWideCharString(). */
27
28 #ifdef HAVE_USABLE_WCHAR_T
29 # ifndef HAVE_WCHAR_H
30 # define HAVE_WCHAR_H
31 # endif
32 #endif
33
34 #ifdef HAVE_WCHAR_H
35 # include <wchar.h>
36 #endif
37
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 #include "cpyext_unicodeobject.h"
44
45 #define PyUnicode_Check(op) \
46 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
47 #define PyUnicode_CheckExact(op) Py_IS_TYPE(op, &PyUnicode_Type)
48
49 /* --- Constants ---------------------------------------------------------- */
50
51 /* This Unicode character will be used as replacement character during
52 decoding if the errors argument is set to "replace". Note: the
53 Unicode character U+FFFD is the official REPLACEMENT CHARACTER in
54 Unicode 3.0. */
55
56 #define Py_UNICODE_REPLACEMENT_CHARACTER ((Py_UCS4) 0xFFFD)
57
58 /* taken from cpython/Include/cpython/unicodeobject.h */
59
60 /* Py_UNICODE was the native Unicode storage format (code unit) used by
61 Python and represents a single Unicode element in the Unicode type.
62 With PEP 393, Py_UNICODE is deprecated and replaced with a
63 typedef to wchar_t. */
64 #define PY_UNICODE_TYPE wchar_t
65 /* Py_DEPRECATED(3.3) */ typedef wchar_t Py_UNICODE;
66
67 /* --- Internal Unicode Operations ---------------------------------------- */
68
69 PyAPI_DATA(const unsigned char) _Py_ascii_whitespace[];
70
71 #ifndef USE_UNICODE_WCHAR_CACHE
72 # define USE_UNICODE_WCHAR_CACHE 1
73 #endif /* USE_UNICODE_WCHAR_CACHE */
74
75 /* Since splitting on whitespace is an important use case, and
76 whitespace in most situations is solely ASCII whitespace, we
77 optimize for the common case by using a quick look-up table
78 _Py_ascii_whitespace (see below) with an inlined check.
79
80 */
81 #define Py_UNICODE_ISSPACE(ch) \
82 ((Py_UCS4)(ch) < 128U ? _Py_ascii_whitespace[(ch)] : _PyUnicode_IsWhitespace(ch))
83
84 #define Py_UNICODE_ISLOWER(ch) _PyUnicode_IsLowercase(ch)
85 #define Py_UNICODE_ISUPPER(ch) _PyUnicode_IsUppercase(ch)
86 #define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch)
87 #define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch)
88
89 #define Py_UNICODE_TOLOWER(ch) _PyUnicode_ToLowercase(ch)
90 #define Py_UNICODE_TOUPPER(ch) _PyUnicode_ToUppercase(ch)
91 #define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch)
92
93 #define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)
94 #define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)
95 #define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)
96 #define Py_UNICODE_ISPRINTABLE(ch) _PyUnicode_IsPrintable(ch)
97
98 #define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)
99 #define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)
100 #define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch)
101
102 #define Py_UNICODE_ISALPHA(ch) _PyUnicode_IsAlpha(ch)
103
104 #define Py_UNICODE_ISALNUM(ch) \
105 (Py_UNICODE_ISALPHA(ch) || \
106 Py_UNICODE_ISDECIMAL(ch) || \
107 Py_UNICODE_ISDIGIT(ch) || \
108 Py_UNICODE_ISNUMERIC(ch))
109
110 /* macros to work with surrogates */
111 #define Py_UNICODE_IS_SURROGATE(ch) (0xD800 <= (ch) && (ch) <= 0xDFFF)
112 #define Py_UNICODE_IS_HIGH_SURROGATE(ch) (0xD800 <= (ch) && (ch) <= 0xDBFF)
113 #define Py_UNICODE_IS_LOW_SURROGATE(ch) (0xDC00 <= (ch) && (ch) <= 0xDFFF)
114 /* Join two surrogate characters and return a single Py_UCS4 value. */
115 #define Py_UNICODE_JOIN_SURROGATES(high, low) \
116 (((((Py_UCS4)(high) & 0x03FF) << 10) | \
117 ((Py_UCS4)(low) & 0x03FF)) + 0x10000)
118 /* high surrogate = top 10 bits added to D800 */
119 #define Py_UNICODE_HIGH_SURROGATE(ch) (0xD800 - (0x10000 >> 10) + ((ch) >> 10))
120 /* low surrogate = bottom 10 bits added to DC00 */
121 #define Py_UNICODE_LOW_SURROGATE(ch) (0xDC00 + ((ch) & 0x3FF))
122
123
124 #define _PyASCIIObject_CAST(op) \
125 (assert(PyUnicode_Check(op)), \
126 _Py_CAST(PyASCIIObject*, (op)))
127 #define _PyCompactUnicodeObject_CAST(op) \
128 (assert(PyUnicode_Check(op)), \
129 _Py_CAST(PyCompactUnicodeObject*, (op)))
130 #define _PyUnicodeObject_CAST(op) \
131 (assert(PyUnicode_Check(op)), \
132 _Py_CAST(PyUnicodeObject*, (op)))
133
134 /* --- Flexible String Representation Helper Macros (PEP 393) -------------- */
135
136 /* Values for PyASCIIObject.state: */
137
138 /* Interning state. */
139 #define SSTATE_NOT_INTERNED 0
140 #define SSTATE_INTERNED_MORTAL 1
141 #define SSTATE_INTERNED_IMMORTAL 2
142
143 /* Use only if you know it's a string */
144 static inline unsigned int PyUnicode_CHECK_INTERNED(PyObject *op) {
145 return _PyASCIIObject_CAST(op)->state.interned;
146 }
147 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
148 # define PyUnicode_CHECK_INTERNED(op) PyUnicode_CHECK_INTERNED(_PyObject_CAST(op))
149 #endif
150
151 /* Fast check to determine whether an object is ready. Equivalent to:
152 PyUnicode_IS_COMPACT(op) || _PyUnicodeObject_CAST(op)->data.any */
153 static inline unsigned int PyUnicode_IS_READY(PyObject *op) {
154 return _PyASCIIObject_CAST(op)->state.ready;
155 }
156 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
157 # define PyUnicode_IS_READY(op) PyUnicode_IS_READY(_PyObject_CAST(op))
158 #endif
159
160 /* Return true if the string contains only ASCII characters, or 0 if not. The
161 string may be compact (PyUnicode_IS_COMPACT_ASCII) or not, but must be
162 ready. */
163 static inline unsigned int PyUnicode_IS_ASCII(PyObject *op) {
164 assert(PyUnicode_IS_READY(op));
165 return _PyASCIIObject_CAST(op)->state.ascii;
166 }
167 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
168 # define PyUnicode_IS_ASCII(op) PyUnicode_IS_ASCII(_PyObject_CAST(op))
169 #endif
170
171 /* Return true if the string is compact or 0 if not.
172 No type checks or Ready calls are performed. */
173 static inline unsigned int PyUnicode_IS_COMPACT(PyObject *op) {
174 return _PyASCIIObject_CAST(op)->state.compact;
175 }
176 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
177 # define PyUnicode_IS_COMPACT(op) PyUnicode_IS_COMPACT(_PyObject_CAST(op))
178 #endif
179
180 /* Return true if the string is a compact ASCII string (use PyASCIIObject
181 structure), or 0 if not. No type checks or Ready calls are performed. */
182 static inline int PyUnicode_IS_COMPACT_ASCII(PyObject *op) {
183 return (_PyASCIIObject_CAST(op)->state.ascii && PyUnicode_IS_COMPACT(op));
184 }
185 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
186 # define PyUnicode_IS_COMPACT_ASCII(op) PyUnicode_IS_COMPACT_ASCII(_PyObject_CAST(op))
187 #endif
188
189 enum PyUnicode_Kind {
190 /* String contains only wstr byte characters. This is only possible
191 when the string was created with a legacy API and _PyUnicode_Ready()
192 has not been called yet. */
193 PyUnicode_WCHAR_KIND = 0,
194 /* Return values of the PyUnicode_KIND() function: */
195 PyUnicode_1BYTE_KIND = 1,
196 PyUnicode_2BYTE_KIND = 2,
197 PyUnicode_4BYTE_KIND = 4
198 };
199
200 /* Return one of the PyUnicode_*_KIND values defined above. */
201 #define PyUnicode_KIND(op) \
202 (assert(PyUnicode_IS_READY(op)), \
203 _PyASCIIObject_CAST(op)->state.kind)
204
205 /* Return a void pointer to the raw unicode buffer. */
206 static inline void* _PyUnicode_COMPACT_DATA(PyObject *op) {
207 if (PyUnicode_IS_ASCII(op)) {
208 return _Py_STATIC_CAST(void*, (_PyASCIIObject_CAST(op) + 1));
209 }
210 return _Py_STATIC_CAST(void*, (_PyCompactUnicodeObject_CAST(op) + 1));
211 }
212
213 static inline void* _PyUnicode_NONCOMPACT_DATA(PyObject *op) {
214 void *data;
215 assert(!PyUnicode_IS_COMPACT(op));
216 /* data = _PyUnicodeObject_CAST(op)->data.any; */
217 data = _PyUnicodeObject_CAST(op)->data;
218 assert(data != NULL);
219 return data;
220 }
221
222 static inline void* PyUnicode_DATA(PyObject *op) {
223 if (PyUnicode_IS_COMPACT(op)) {
224 return _PyUnicode_COMPACT_DATA(op);
225 }
226 return _PyUnicode_NONCOMPACT_DATA(op);
227 }
228 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
229 # define PyUnicode_DATA(op) PyUnicode_DATA(_PyObject_CAST(op))
230 #endif
231
232 /* Return pointers to the canonical representation cast to unsigned char,
233 Py_UCS2, or Py_UCS4 for direct character access.
234 No checks are performed, use PyUnicode_KIND() before to ensure
235 these will work correctly. */
236
237 #define PyUnicode_1BYTE_DATA(op) _Py_STATIC_CAST(Py_UCS1*, PyUnicode_DATA(op))
238 #define PyUnicode_2BYTE_DATA(op) _Py_STATIC_CAST(Py_UCS2*, PyUnicode_DATA(op))
239 #define PyUnicode_4BYTE_DATA(op) _Py_STATIC_CAST(Py_UCS4*, PyUnicode_DATA(op))
240
241 /* Returns the length of the unicode string. The caller has to make sure that
242 the string has it's canonical representation set before calling
243 this function. Call PyUnicode_(FAST_)Ready to ensure that. */
244 static inline Py_ssize_t PyUnicode_GET_LENGTH(PyObject *op) {
245 assert(PyUnicode_IS_READY(op));
246 return _PyASCIIObject_CAST(op)->length;
247 }
248 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
249 # define PyUnicode_GET_LENGTH(op) PyUnicode_GET_LENGTH(_PyObject_CAST(op))
250 #endif
251
252 /* Write into the canonical representation, this function does not do any sanity
253 checks and is intended for usage in loops. The caller should cache the
254 kind and data pointers obtained from other function calls.
255 index is the index in the string (starts at 0) and value is the new
256 code point value which should be written to that location. */
257 static inline void PyUnicode_WRITE(int kind, void *data,
258 Py_ssize_t index, Py_UCS4 value)
259 {
260 if (kind == PyUnicode_1BYTE_KIND) {
261 assert(value <= 0xffU);
262 _Py_STATIC_CAST(Py_UCS1*, data)[index] = _Py_STATIC_CAST(Py_UCS1, value);
263 }
264 else if (kind == PyUnicode_2BYTE_KIND) {
265 assert(value <= 0xffffU);
266 _Py_STATIC_CAST(Py_UCS2*, data)[index] = _Py_STATIC_CAST(Py_UCS2, value);
267 }
268 else {
269 assert(kind == PyUnicode_4BYTE_KIND);
270 assert(value <= 0x10ffffU);
271 _Py_STATIC_CAST(Py_UCS4*, data)[index] = value;
272 }
273 }
274 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
275 #define PyUnicode_WRITE(kind, data, index, value) \
276 PyUnicode_WRITE(_Py_STATIC_CAST(int, kind), _Py_CAST(void*, data), \
277 (index), _Py_STATIC_CAST(Py_UCS4, value))
278 #endif
279
280 /* Read a code point from the string's canonical representation. No checks
281 or ready calls are performed. */
282 static inline Py_UCS4 PyUnicode_READ(int kind,
283 const void *data, Py_ssize_t index)
284 {
285 if (kind == PyUnicode_1BYTE_KIND) {
286 return _Py_STATIC_CAST(const Py_UCS1*, data)[index];
287 }
288 if (kind == PyUnicode_2BYTE_KIND) {
289 return _Py_STATIC_CAST(const Py_UCS2*, data)[index];
290 }
291 assert(kind == PyUnicode_4BYTE_KIND);
292 return _Py_STATIC_CAST(const Py_UCS4*, data)[index];
293 }
294 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
295 #define PyUnicode_READ(kind, data, index) \
296 PyUnicode_READ(_Py_STATIC_CAST(int, kind), \
297 _Py_STATIC_CAST(const void*, data), \
298 (index))
299 #endif
300
301 /* PyUnicode_READ_CHAR() is less efficient than PyUnicode_READ() because it
302 calls PyUnicode_KIND() and might call it twice. For single reads, use
303 PyUnicode_READ_CHAR, for multiple consecutive reads callers should
304 cache kind and use PyUnicode_READ instead. */
305 static inline Py_UCS4 PyUnicode_READ_CHAR(PyObject *unicode, Py_ssize_t index)
306 {
307 int kind;
308 assert(PyUnicode_IS_READY(unicode));
309 kind = PyUnicode_KIND(unicode);
310 if (kind == PyUnicode_1BYTE_KIND) {
311 return PyUnicode_1BYTE_DATA(unicode)[index];
312 }
313 if (kind == PyUnicode_2BYTE_KIND) {
314 return PyUnicode_2BYTE_DATA(unicode)[index];
315 }
316 assert(kind == PyUnicode_4BYTE_KIND);
317 return PyUnicode_4BYTE_DATA(unicode)[index];
318 }
319 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
320 # define PyUnicode_READ_CHAR(unicode, index) \
321 PyUnicode_READ_CHAR(_PyObject_CAST(unicode), (index))
322 #endif
323
324 /* Return a maximum character value which is suitable for creating another
325 string based on op. This is always an approximation but more efficient
326 than iterating over the string. */
327 static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *op)
328 {
329 int kind;
330
331 assert(PyUnicode_IS_READY(op));
332 if (PyUnicode_IS_ASCII(op)) {
333 return 0x7fU;
334 }
335
336 kind = PyUnicode_KIND(op);
337 if (kind == PyUnicode_1BYTE_KIND) {
338 return 0xffU;
339 }
340 if (kind == PyUnicode_2BYTE_KIND) {
341 return 0xffffU;
342 }
343 assert(kind == PyUnicode_4BYTE_KIND);
344 return 0x10ffffU;
345 }
346 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
347 # define PyUnicode_MAX_CHAR_VALUE(op) \
348 PyUnicode_MAX_CHAR_VALUE(_PyObject_CAST(op))
349 #endif
350
351 /* === Public API ========================================================= */
352
353 /* PyUnicode_READY() does less work than _PyUnicode_Ready() in the best
354 case. If the canonical representation is not yet set, it will still call
355 _PyUnicode_Ready().
356 Returns 0 on success and -1 on errors. */
357
358 /* In CPython this is a static inlined function. On PyPy, because we generate
359 * and mangle the _PyUnicode_Ready function, and the generated declaration
360 * appears in pypy_decls.h which is 'include'ed after this file, we cannot use
361 * the static inline method and must make it a macro
362 */
363 #define PyUnicode_READY(op) \
364 (assert(PyUnicode_Check(op)), \
365 (PyUnicode_IS_READY(op) ? \
366 0 : _PyUnicode_Ready((PyObject *)(op))))
367
368 /*
369 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
370 # define PyUnicode_READY(op) PyUnicode_READY(_PyObject_CAST(op))
371 #endif
372 */
373
374 /* --- Legacy deprecated API ---------------------------------------------- */
375
376 /* Return a read-only pointer to the Unicode object's internal
377 Py_UNICODE buffer.
378 If the wchar_t/Py_UNICODE representation is not yet available, this
379 function will calculate it. */
380 Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(
381 PyObject *unicode /* Unicode object */
382 );
383
384
385 /* Fast access macros */
386
387 Py_DEPRECATED(3.3)
388 static inline Py_ssize_t PyUnicode_WSTR_LENGTH(PyObject *op)
389 {
390 if (PyUnicode_IS_COMPACT_ASCII(op)) {
391 return _PyASCIIObject_CAST(op)->length;
392 }
393 else {
394 return _PyCompactUnicodeObject_CAST(op)->wstr_length;
395 }
396 }
397 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
398 # define PyUnicode_WSTR_LENGTH(op) PyUnicode_WSTR_LENGTH(_PyObject_CAST(op))
399 #endif
400
401 /* Returns the deprecated Py_UNICODE representation's size in code units
402 (this includes surrogate pairs as 2 units).
403 If the Py_UNICODE representation is not available, it will be computed
404 on request. Use PyUnicode_GET_LENGTH() for the length in code points. */
405
406 Py_DEPRECATED(3.3)
407 static inline Py_ssize_t PyUnicode_GET_SIZE(PyObject *op)
408 {
409 _Py_COMP_DIAG_PUSH
410 _Py_COMP_DIAG_IGNORE_DEPR_DECLS
411 if (_PyASCIIObject_CAST(op)->wstr == _Py_NULL) {
412 (void)PyUnicode_AsUnicode(op);
413 assert(_PyASCIIObject_CAST(op)->wstr != _Py_NULL);
414 }
415 return PyUnicode_WSTR_LENGTH(op);
416 _Py_COMP_DIAG_POP
417 }
418 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
419 # define PyUnicode_GET_SIZE(op) PyUnicode_GET_SIZE(_PyObject_CAST(op))
420 #endif
421
422 Py_DEPRECATED(3.3)
423 static inline Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject *op)
424 {
425 _Py_COMP_DIAG_PUSH
426 _Py_COMP_DIAG_IGNORE_DEPR_DECLS
427 return PyUnicode_GET_SIZE(op) * Py_UNICODE_SIZE;
428 _Py_COMP_DIAG_POP
429 }
430 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
431 # define PyUnicode_GET_DATA_SIZE(op) PyUnicode_GET_DATA_SIZE(_PyObject_CAST(op))
432 #endif
433
434 /* Alias for PyUnicode_AsUnicode(). This will create a wchar_t/Py_UNICODE
435 representation on demand. Using this macro is very inefficient now,
436 try to port your code to use the new PyUnicode_*BYTE_DATA() macros or
437 use PyUnicode_WRITE() and PyUnicode_READ(). */
438
439 Py_DEPRECATED(3.3)
440 static inline Py_UNICODE* PyUnicode_AS_UNICODE(PyObject *op)
441 {
442 wchar_t *wstr = _PyASCIIObject_CAST(op)->wstr;
443 if (wstr != _Py_NULL) {
444 return wstr;
445 }
446
447 _Py_COMP_DIAG_PUSH
448 _Py_COMP_DIAG_IGNORE_DEPR_DECLS
449 return PyUnicode_AsUnicode(op);
450 _Py_COMP_DIAG_POP
451 }
452 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
453 # define PyUnicode_AS_UNICODE(op) PyUnicode_AS_UNICODE(_PyObject_CAST(op))
454 #endif
455
456 Py_DEPRECATED(3.3)
457 static inline const char* PyUnicode_AS_DATA(PyObject *op)
458 {
459 _Py_COMP_DIAG_PUSH
460 _Py_COMP_DIAG_IGNORE_DEPR_DECLS
461 Py_UNICODE *data = PyUnicode_AS_UNICODE(op);
462 // In C++, casting directly PyUnicode* to const char* is not valid
463 return _Py_STATIC_CAST(const char*, _Py_STATIC_CAST(const void*, data));
464 _Py_COMP_DIAG_POP
465 }
466 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
467 # define PyUnicode_AS_DATA(op) PyUnicode_AS_DATA(_PyObject_CAST(op))
468 #endif
469
470 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
471 /* Get the length of the Unicode object. */
472
473 PyAPI_FUNC(Py_ssize_t) PyUnicode_GetLength(
474 PyObject *unicode
475 );
476 #endif
477
478 /* Returns a pointer to the default encoding (UTF-8) of the
479 Unicode object unicode.
480
481 Like PyUnicode_AsUTF8AndSize(), this also caches the UTF-8 representation
482 in the unicodeobject.
483
484 _PyUnicode_AsString is a #define for PyUnicode_AsUTF8 to
485 support the previous internal function with the same behaviour.
486
487 Use of this API is DEPRECATED since no size information can be
488 extracted from the returned data.
489
490 *** This API is for interpreter INTERNAL USE ONLY and will likely
491 *** be removed or changed for Python 3.1.
492
493 *** If you need to access the Unicode object as UTF-8 bytes string,
494 *** please use PyUnicode_AsUTF8String() instead.
495
496 */
497 #ifndef Py_LIMITED_API
498 #define _PyUnicode_AsString PyUnicode_AsUTF8
499 #endif
500
501 PyAPI_FUNC(double) _PyUnicode_ToNumeric(
502 Py_UCS4 ch /* Unicode character */
503 );
504
505 PyAPI_FUNC(int) _PyUnicode_IsWhitespace(
506 const Py_UCS4 ch /* Unicode character */
507 );
508
509 PyAPI_FUNC(int) _PyUnicode_IsLinebreak(
510 const Py_UCS4 ch /* Unicode character */
511 );
512
513 /* end of cpython/unicodeobject.h, back to ./unicodeobject.h */
514
515 /* Get the number of Py_UNICODE units in the
516 string representation. */
517
518 Py_DEPRECATED(3.3) PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(
519 PyObject *unicode /* Unicode object */
520 );
521
522 PyAPI_FUNC(PyObject *) PyUnicode_FromFormatV(
523 const char *format, /* ASCII-encoded string */
524 va_list vargs
525 );
526 PyAPI_FUNC(PyObject *) PyUnicode_FromFormat(
527 const char *format, /* ASCII-encoded string */
528 ...
529 );
530
531 /* --- wchar_t support for platforms which support it --------------------- */
532
533 #ifdef HAVE_WCHAR_H
534
535 /* Create a Unicode Object from the wchar_t buffer w of the given
536 size.
537
538 The buffer is copied into the new object. */
539
540 PyAPI_FUNC(PyObject*) PyUnicode_FromWideChar(
541 const wchar_t *w, /* wchar_t buffer */
542 Py_ssize_t size /* size of buffer */
543 );
544
545 /* Convert the Unicode object to a wide character string. The output string
546 always ends with a nul character. If size is not NULL, write the number of
547 wide characters (excluding the null character) into *size.
548
549 Returns a buffer allocated by PyMem_Malloc() (use PyMem_Free() to free it)
550 on success. On error, returns NULL, *size is undefined and raises a
551 MemoryError. */
552
553 PyAPI_FUNC(wchar_t*) PyUnicode_AsWideCharString(
554 PyObject *unicode, /* Unicode object */
555 Py_ssize_t *size /* number of characters of the result */
556 );
557
558 #endif
559
560 /* Returns a pointer to the default encoding (UTF-8) of the
561 Unicode object unicode and the size of the encoded representation
562 in bytes stored in *size.
563
564 In case of an error, no *size is set.
565
566 This function caches the UTF-8 encoded string in the unicodeobject
567 and subsequent calls will return the same string. The memory is released
568 when the unicodeobject is deallocated.
569
570 */
571
572 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
573 PyAPI_FUNC(char *) PyUnicode_AsUTF8AndSize(
574 PyObject *unicode,
575 Py_ssize_t *size);
576 #endif
577
578 /* Concat two strings, put the result in *pleft and drop the right object
579 (sets *pleft to NULL on error) */
580
581 PyAPI_FUNC(void) PyUnicode_AppendAndDel(
582 PyObject **pleft, /* Pointer to left string */
583 PyObject *right /* Right string */
584 );
585
586 #ifdef __cplusplus
587 }
588 #endif
589 #endif /* !Py_UNICODEOBJECT_H */