unicodeobject.h 53.5 KB
Newer Older
1 2 3
#ifndef Py_UNICODEOBJECT_H
#define Py_UNICODEOBJECT_H

4 5
#include <stdarg.h>

6 7 8 9 10 11
/*

Unicode implementation based on original code by Fredrik Lundh,
modified by Marc-Andre Lemburg (mal@lemburg.com) according to the
Unicode Integration Proposal (see file Misc/unicode.txt).

12
Copyright (c) Corporation for National Research Initiatives.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56


 Original header:
 --------------------------------------------------------------------

 * Yet another Unicode string type for Python.  This type supports the
 * 16-bit Basic Multilingual Plane (BMP) only.
 *
 * Written by Fredrik Lundh, January 1999.
 *
 * Copyright (c) 1999 by Secret Labs AB.
 * Copyright (c) 1999 by Fredrik Lundh.
 *
 * fredrik@pythonware.com
 * http://www.pythonware.com
 *
 * --------------------------------------------------------------------
 * This Unicode String Type is
 * 
 * Copyright (c) 1999 by Secret Labs AB
 * Copyright (c) 1999 by Fredrik Lundh
 * 
 * By obtaining, using, and/or copying this software and/or its
 * associated documentation, you agree that you have read, understood,
 * and will comply with the following terms and conditions:
 * 
 * Permission to use, copy, modify, and distribute this software and its
 * associated documentation for any purpose and without fee is hereby
 * granted, provided that the above copyright notice appears in all
 * copies, and that both that copyright notice and this permission notice
 * appear in supporting documentation, and that the name of Secret Labs
 * AB or the author not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior
 * permission.
 * 
 * SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO
 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS.  IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 * -------------------------------------------------------------------- */

57
#include <ctype.h>
58 59 60 61 62

/* === Internal API ======================================================= */

/* --- Internal Unicode Format -------------------------------------------- */

63 64 65
/* Python 3.x requires unicode */
#define Py_USING_UNICODE 

66 67 68 69 70 71 72 73
/* FIXME: MvL's new implementation assumes that Py_UNICODE_SIZE is
   properly set, but the default rules below doesn't set it.  I'll
   sort this out some other day -- fredrik@pythonware.com */

#ifndef Py_UNICODE_SIZE
#error Must define Py_UNICODE_SIZE
#endif

74 75 76 77 78
/* Setting Py_UNICODE_WIDE enables UCS-4 storage.  Otherwise, Unicode
   strings are stored as UCS-2 (with limited support for UTF-16) */

#if Py_UNICODE_SIZE >= 4
#define Py_UNICODE_WIDE
79
#endif
80

81 82 83 84 85 86
/* Set these flags if the platform has "wchar.h", "wctype.h" and the
   wchar_t type is a 16-bit unsigned type */
/* #define HAVE_WCHAR_H */
/* #define HAVE_USABLE_WCHAR_T */

/* Defaults for various platforms */
87
#ifndef PY_UNICODE_TYPE
88

89
/* Windows has a usable wchar_t type (unless we're using UCS-4) */
90
# if defined(MS_WIN32) && Py_UNICODE_SIZE == 2
91
#  define HAVE_USABLE_WCHAR_T
92 93 94
#  define PY_UNICODE_TYPE wchar_t
# endif

95
# if defined(Py_UNICODE_WIDE)
96
#  define PY_UNICODE_TYPE Py_UCS4
97 98 99 100 101 102 103 104 105
# endif

#endif

/* If the compiler provides a wchar_t type we try to support it
   through the interface functions PyUnicode_FromWideChar() and
   PyUnicode_AsWideChar(). */

#ifdef HAVE_USABLE_WCHAR_T
106 107 108
# ifndef HAVE_WCHAR_H
#  define HAVE_WCHAR_H
# endif
109 110 111
#endif

#ifdef HAVE_WCHAR_H
Guido van Rossum's avatar
Guido van Rossum committed
112 113 114 115
/* Work around a cosmetic bug in BSDI 4.x wchar.h; thanks to Thomas Wouters */
# ifdef _HAVE_BSDI
#  include <time.h>
# endif
116
#  include <wchar.h>
117 118
#endif

119 120 121 122 123 124 125 126
/*
 * Use this typedef when you need to represent a UTF-16 surrogate pair
 * as single unsigned integer.
 */
#if SIZEOF_INT >= 4 
typedef unsigned int Py_UCS4; 
#elif SIZEOF_LONG >= 4
typedef unsigned long Py_UCS4; 
127 128
#endif

129
typedef PY_UNICODE_TYPE Py_UNICODE;
130

131 132 133 134 135 136 137 138 139 140 141
/* --- UCS-2/UCS-4 Name Mangling ------------------------------------------ */

/* Unicode API names are mangled to assure that UCS-2 and UCS-4 builds
   produce different external names and thus cause import errors in
   case Python interpreters and extensions with mixed compiled in
   Unicode width assumptions are combined. */

#ifndef Py_UNICODE_WIDE

# define PyUnicode_AsASCIIString PyUnicodeUCS2_AsASCIIString
# define PyUnicode_AsCharmapString PyUnicodeUCS2_AsCharmapString
142
# define PyUnicode_AsEncodedObject PyUnicodeUCS2_AsEncodedObject
143 144 145
# define PyUnicode_AsEncodedString PyUnicodeUCS2_AsEncodedString
# define PyUnicode_AsLatin1String PyUnicodeUCS2_AsLatin1String
# define PyUnicode_AsRawUnicodeEscapeString PyUnicodeUCS2_AsRawUnicodeEscapeString
146
# define PyUnicode_AsUTF32String PyUnicodeUCS2_AsUTF32String
147 148 149 150 151 152 153
# define PyUnicode_AsUTF16String PyUnicodeUCS2_AsUTF16String
# define PyUnicode_AsUTF8String PyUnicodeUCS2_AsUTF8String
# define PyUnicode_AsUnicode PyUnicodeUCS2_AsUnicode
# define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS2_AsUnicodeEscapeString
# define PyUnicode_AsWideChar PyUnicodeUCS2_AsWideChar
# define PyUnicode_Compare PyUnicodeUCS2_Compare
# define PyUnicode_Concat PyUnicodeUCS2_Concat
154 155
# define PyUnicode_Append PyUnicodeUCS2_Append
# define PyUnicode_AppendAndDel PyUnicodeUCS2_AppendAndDel
156 157 158 159 160 161
# define PyUnicode_Contains PyUnicodeUCS2_Contains
# define PyUnicode_Count PyUnicodeUCS2_Count
# define PyUnicode_Decode PyUnicodeUCS2_Decode
# define PyUnicode_DecodeASCII PyUnicodeUCS2_DecodeASCII
# define PyUnicode_DecodeCharmap PyUnicodeUCS2_DecodeCharmap
# define PyUnicode_DecodeLatin1 PyUnicodeUCS2_DecodeLatin1
162
# define PyUnicode_DecodeFSDefault PyUnicodeUCS2_DecodeFSDefault
163
# define PyUnicode_DecodeFSDefaultAndSize PyUnicodeUCS2_DecodeFSDefaultAndSize
164
# define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS2_DecodeRawUnicodeEscape
165 166
# define PyUnicode_DecodeUTF32 PyUnicodeUCS2_DecodeUTF32
# define PyUnicode_DecodeUTF32Stateful PyUnicodeUCS2_DecodeUTF32Stateful
167
# define PyUnicode_DecodeUTF16 PyUnicodeUCS2_DecodeUTF16
168
# define PyUnicode_DecodeUTF16Stateful PyUnicodeUCS2_DecodeUTF16Stateful
169
# define PyUnicode_DecodeUTF8 PyUnicodeUCS2_DecodeUTF8
170
# define PyUnicode_DecodeUTF8Stateful PyUnicodeUCS2_DecodeUTF8Stateful
171 172 173 174 175 176 177
# define PyUnicode_DecodeUnicodeEscape PyUnicodeUCS2_DecodeUnicodeEscape
# define PyUnicode_Encode PyUnicodeUCS2_Encode
# define PyUnicode_EncodeASCII PyUnicodeUCS2_EncodeASCII
# define PyUnicode_EncodeCharmap PyUnicodeUCS2_EncodeCharmap
# define PyUnicode_EncodeDecimal PyUnicodeUCS2_EncodeDecimal
# define PyUnicode_EncodeLatin1 PyUnicodeUCS2_EncodeLatin1
# define PyUnicode_EncodeRawUnicodeEscape PyUnicodeUCS2_EncodeRawUnicodeEscape
178
# define PyUnicode_EncodeUTF32 PyUnicodeUCS2_EncodeUTF32
179 180 181 182 183 184 185
# define PyUnicode_EncodeUTF16 PyUnicodeUCS2_EncodeUTF16
# define PyUnicode_EncodeUTF8 PyUnicodeUCS2_EncodeUTF8
# define PyUnicode_EncodeUnicodeEscape PyUnicodeUCS2_EncodeUnicodeEscape
# define PyUnicode_Find PyUnicodeUCS2_Find
# define PyUnicode_Format PyUnicodeUCS2_Format
# define PyUnicode_FromEncodedObject PyUnicodeUCS2_FromEncodedObject
# define PyUnicode_FromObject PyUnicodeUCS2_FromObject
186
# define PyUnicode_FromOrdinal PyUnicodeUCS2_FromOrdinal
187
# define PyUnicode_FromUnicode PyUnicodeUCS2_FromUnicode
188
# define PyUnicode_FromString PyUnicodeUCS2_FromString
189 190 191
# define PyUnicode_FromStringAndSize PyUnicodeUCS2_FromStringAndSize
# define PyUnicode_FromFormatV PyUnicodeUCS2_FromFormatV
# define PyUnicode_FromFormat PyUnicodeUCS2_FromFormat
Walter Dörwald's avatar
Walter Dörwald committed
192
# define PyUnicode_FromWideChar PyUnicodeUCS2_FromWideChar
193 194 195
# define PyUnicode_GetDefaultEncoding PyUnicodeUCS2_GetDefaultEncoding
# define PyUnicode_GetMax PyUnicodeUCS2_GetMax
# define PyUnicode_GetSize PyUnicodeUCS2_GetSize
196
# define PyUnicode_IsIdentifier PyUnicodeUCS2_IsIdentifier
197
# define PyUnicode_Join PyUnicodeUCS2_Join
198 199 200
# define PyUnicode_Partition PyUnicodeUCS2_Partition
# define PyUnicode_RPartition PyUnicodeUCS2_RPartition
# define PyUnicode_RSplit PyUnicodeUCS2_RSplit
201 202
# define PyUnicode_Replace PyUnicodeUCS2_Replace
# define PyUnicode_Resize PyUnicodeUCS2_Resize
203
# define PyUnicode_RichCompare PyUnicodeUCS2_RichCompare
204 205 206 207 208 209 210 211 212
# define PyUnicode_SetDefaultEncoding PyUnicodeUCS2_SetDefaultEncoding
# define PyUnicode_Split PyUnicodeUCS2_Split
# define PyUnicode_Splitlines PyUnicodeUCS2_Splitlines
# define PyUnicode_Tailmatch PyUnicodeUCS2_Tailmatch
# define PyUnicode_Translate PyUnicodeUCS2_Translate
# define PyUnicode_TranslateCharmap PyUnicodeUCS2_TranslateCharmap
# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS2_AsDefaultEncodedString
# define _PyUnicode_Fini _PyUnicodeUCS2_Fini
# define _PyUnicode_Init _PyUnicodeUCS2_Init
Christian Heimes's avatar
Christian Heimes committed
213
# define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist
214 215 216 217 218 219
# define _PyUnicode_IsAlpha _PyUnicodeUCS2_IsAlpha
# define _PyUnicode_IsDecimalDigit _PyUnicodeUCS2_IsDecimalDigit
# define _PyUnicode_IsDigit _PyUnicodeUCS2_IsDigit
# define _PyUnicode_IsLinebreak _PyUnicodeUCS2_IsLinebreak
# define _PyUnicode_IsLowercase _PyUnicodeUCS2_IsLowercase
# define _PyUnicode_IsNumeric _PyUnicodeUCS2_IsNumeric
220
# define _PyUnicode_IsPrintable _PyUnicodeUCS2_IsPrintable
221
# define _PyUnicode_IsTitlecase _PyUnicodeUCS2_IsTitlecase
222 223
# define _PyUnicode_IsXidStart _PyUnicodeUCS2_IsXidStart
# define _PyUnicode_IsXidContinue _PyUnicodeUCS2_IsXidContinue
224 225 226 227 228 229 230 231 232 233 234 235 236
# define _PyUnicode_IsUppercase _PyUnicodeUCS2_IsUppercase
# define _PyUnicode_IsWhitespace _PyUnicodeUCS2_IsWhitespace
# define _PyUnicode_ToDecimalDigit _PyUnicodeUCS2_ToDecimalDigit
# define _PyUnicode_ToDigit _PyUnicodeUCS2_ToDigit
# define _PyUnicode_ToLowercase _PyUnicodeUCS2_ToLowercase
# define _PyUnicode_ToNumeric _PyUnicodeUCS2_ToNumeric
# define _PyUnicode_ToTitlecase _PyUnicodeUCS2_ToTitlecase
# define _PyUnicode_ToUppercase _PyUnicodeUCS2_ToUppercase

#else

# define PyUnicode_AsASCIIString PyUnicodeUCS4_AsASCIIString
# define PyUnicode_AsCharmapString PyUnicodeUCS4_AsCharmapString
237
# define PyUnicode_AsEncodedObject PyUnicodeUCS4_AsEncodedObject
238 239 240
# define PyUnicode_AsEncodedString PyUnicodeUCS4_AsEncodedString
# define PyUnicode_AsLatin1String PyUnicodeUCS4_AsLatin1String
# define PyUnicode_AsRawUnicodeEscapeString PyUnicodeUCS4_AsRawUnicodeEscapeString
241
# define PyUnicode_AsUTF32String PyUnicodeUCS4_AsUTF32String
242 243 244 245 246 247 248
# define PyUnicode_AsUTF16String PyUnicodeUCS4_AsUTF16String
# define PyUnicode_AsUTF8String PyUnicodeUCS4_AsUTF8String
# define PyUnicode_AsUnicode PyUnicodeUCS4_AsUnicode
# define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS4_AsUnicodeEscapeString
# define PyUnicode_AsWideChar PyUnicodeUCS4_AsWideChar
# define PyUnicode_Compare PyUnicodeUCS4_Compare
# define PyUnicode_Concat PyUnicodeUCS4_Concat
249 250
# define PyUnicode_Append PyUnicodeUCS4_Append
# define PyUnicode_AppendAndDel PyUnicodeUCS4_AppendAndDel
251 252 253 254 255 256
# define PyUnicode_Contains PyUnicodeUCS4_Contains
# define PyUnicode_Count PyUnicodeUCS4_Count
# define PyUnicode_Decode PyUnicodeUCS4_Decode
# define PyUnicode_DecodeASCII PyUnicodeUCS4_DecodeASCII
# define PyUnicode_DecodeCharmap PyUnicodeUCS4_DecodeCharmap
# define PyUnicode_DecodeLatin1 PyUnicodeUCS4_DecodeLatin1
257
# define PyUnicode_DecodeFSDefault PyUnicodeUCS4_DecodeFSDefault
258
# define PyUnicode_DecodeFSDefaultAndSize PyUnicodeUCS4_DecodeFSDefaultAndSize
259
# define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS4_DecodeRawUnicodeEscape
260 261
# define PyUnicode_DecodeUTF32 PyUnicodeUCS4_DecodeUTF32
# define PyUnicode_DecodeUTF32Stateful PyUnicodeUCS4_DecodeUTF32Stateful
262
# define PyUnicode_DecodeUTF16 PyUnicodeUCS4_DecodeUTF16
263
# define PyUnicode_DecodeUTF16Stateful PyUnicodeUCS4_DecodeUTF16Stateful
264
# define PyUnicode_DecodeUTF8 PyUnicodeUCS4_DecodeUTF8
265
# define PyUnicode_DecodeUTF8Stateful PyUnicodeUCS4_DecodeUTF8Stateful
266 267 268 269 270 271 272
# define PyUnicode_DecodeUnicodeEscape PyUnicodeUCS4_DecodeUnicodeEscape
# define PyUnicode_Encode PyUnicodeUCS4_Encode
# define PyUnicode_EncodeASCII PyUnicodeUCS4_EncodeASCII
# define PyUnicode_EncodeCharmap PyUnicodeUCS4_EncodeCharmap
# define PyUnicode_EncodeDecimal PyUnicodeUCS4_EncodeDecimal
# define PyUnicode_EncodeLatin1 PyUnicodeUCS4_EncodeLatin1
# define PyUnicode_EncodeRawUnicodeEscape PyUnicodeUCS4_EncodeRawUnicodeEscape
273
# define PyUnicode_EncodeUTF32 PyUnicodeUCS4_EncodeUTF32
274 275 276 277 278 279 280
# define PyUnicode_EncodeUTF16 PyUnicodeUCS4_EncodeUTF16
# define PyUnicode_EncodeUTF8 PyUnicodeUCS4_EncodeUTF8
# define PyUnicode_EncodeUnicodeEscape PyUnicodeUCS4_EncodeUnicodeEscape
# define PyUnicode_Find PyUnicodeUCS4_Find
# define PyUnicode_Format PyUnicodeUCS4_Format
# define PyUnicode_FromEncodedObject PyUnicodeUCS4_FromEncodedObject
# define PyUnicode_FromObject PyUnicodeUCS4_FromObject
281
# define PyUnicode_FromOrdinal PyUnicodeUCS4_FromOrdinal
282
# define PyUnicode_FromUnicode PyUnicodeUCS4_FromUnicode
283
# define PyUnicode_FromString PyUnicodeUCS4_FromString
284 285 286
# define PyUnicode_FromStringAndSize PyUnicodeUCS4_FromStringAndSize
# define PyUnicode_FromFormatV PyUnicodeUCS4_FromFormatV
# define PyUnicode_FromFormat PyUnicodeUCS4_FromFormat
287 288 289 290
# define PyUnicode_FromWideChar PyUnicodeUCS4_FromWideChar
# define PyUnicode_GetDefaultEncoding PyUnicodeUCS4_GetDefaultEncoding
# define PyUnicode_GetMax PyUnicodeUCS4_GetMax
# define PyUnicode_GetSize PyUnicodeUCS4_GetSize
291
# define PyUnicode_IsIdentifier PyUnicodeUCS4_IsIdentifier
292
# define PyUnicode_Join PyUnicodeUCS4_Join
293 294 295
# define PyUnicode_Partition PyUnicodeUCS4_Partition
# define PyUnicode_RPartition PyUnicodeUCS4_RPartition
# define PyUnicode_RSplit PyUnicodeUCS4_RSplit
296 297
# define PyUnicode_Replace PyUnicodeUCS4_Replace
# define PyUnicode_Resize PyUnicodeUCS4_Resize
298
# define PyUnicode_RichCompare PyUnicodeUCS4_RichCompare
299 300 301 302 303 304 305 306 307
# define PyUnicode_SetDefaultEncoding PyUnicodeUCS4_SetDefaultEncoding
# define PyUnicode_Split PyUnicodeUCS4_Split
# define PyUnicode_Splitlines PyUnicodeUCS4_Splitlines
# define PyUnicode_Tailmatch PyUnicodeUCS4_Tailmatch
# define PyUnicode_Translate PyUnicodeUCS4_Translate
# define PyUnicode_TranslateCharmap PyUnicodeUCS4_TranslateCharmap
# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS4_AsDefaultEncodedString
# define _PyUnicode_Fini _PyUnicodeUCS4_Fini
# define _PyUnicode_Init _PyUnicodeUCS4_Init
Christian Heimes's avatar
Christian Heimes committed
308
# define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist
309 310 311 312 313 314
# define _PyUnicode_IsAlpha _PyUnicodeUCS4_IsAlpha
# define _PyUnicode_IsDecimalDigit _PyUnicodeUCS4_IsDecimalDigit
# define _PyUnicode_IsDigit _PyUnicodeUCS4_IsDigit
# define _PyUnicode_IsLinebreak _PyUnicodeUCS4_IsLinebreak
# define _PyUnicode_IsLowercase _PyUnicodeUCS4_IsLowercase
# define _PyUnicode_IsNumeric _PyUnicodeUCS4_IsNumeric
315
# define _PyUnicode_IsPrintable _PyUnicodeUCS4_IsPrintable
316
# define _PyUnicode_IsTitlecase _PyUnicodeUCS4_IsTitlecase
317 318
# define _PyUnicode_IsXidStart _PyUnicodeUCS4_IsXidStart
# define _PyUnicode_IsXidContinue _PyUnicodeUCS4_IsXidContinue
319 320 321 322 323 324 325 326 327 328 329 330
# define _PyUnicode_IsUppercase _PyUnicodeUCS4_IsUppercase
# define _PyUnicode_IsWhitespace _PyUnicodeUCS4_IsWhitespace
# define _PyUnicode_ToDecimalDigit _PyUnicodeUCS4_ToDecimalDigit
# define _PyUnicode_ToDigit _PyUnicodeUCS4_ToDigit
# define _PyUnicode_ToLowercase _PyUnicodeUCS4_ToLowercase
# define _PyUnicode_ToNumeric _PyUnicodeUCS4_ToNumeric
# define _PyUnicode_ToTitlecase _PyUnicodeUCS4_ToTitlecase
# define _PyUnicode_ToUppercase _PyUnicodeUCS4_ToUppercase


#endif

331 332 333
/* --- Internal Unicode Operations ---------------------------------------- */

/* If you want Python to use the compiler's wctype.h functions instead
334
   of the ones supplied with Python, define WANT_WCTYPE_FUNCTIONS or
335
   configure Python using --with-wctype-functions.  This reduces the
336
   interpreter's code size. */
337 338 339

#if defined(HAVE_USABLE_WCHAR_T) && defined(WANT_WCTYPE_FUNCTIONS)

340
#include <wctype.h>
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355

#define Py_UNICODE_ISSPACE(ch) iswspace(ch)

#define Py_UNICODE_ISLOWER(ch) iswlower(ch)
#define Py_UNICODE_ISUPPER(ch) iswupper(ch)
#define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch)
#define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch)

#define Py_UNICODE_TOLOWER(ch) towlower(ch)
#define Py_UNICODE_TOUPPER(ch) towupper(ch)
#define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch)

#define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)
#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)
#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)
356
#define Py_UNICODE_ISPRINTABLE(ch) _PyUnicode_IsPrintable(ch)
357 358 359 360 361

#define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)
#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)
#define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch)

362 363
#define Py_UNICODE_ISALPHA(ch) iswalpha(ch)

364 365
#else

366 367 368 369 370 371 372 373
/* Since splitting on whitespace is an important use case, and whitespace
   in most situations is solely ASCII whitespace, we optimize for the common
   case by using a quick look-up table with an inlined check.
 */
extern const unsigned char _Py_ascii_whitespace[];

#define Py_UNICODE_ISSPACE(ch) \
	((ch) < 128U ? _Py_ascii_whitespace[(ch)] : _PyUnicode_IsWhitespace(ch))
374 375 376 377 378 379 380 381 382 383 384 385 386

#define Py_UNICODE_ISLOWER(ch) _PyUnicode_IsLowercase(ch)
#define Py_UNICODE_ISUPPER(ch) _PyUnicode_IsUppercase(ch)
#define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch)
#define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch)

#define Py_UNICODE_TOLOWER(ch) _PyUnicode_ToLowercase(ch)
#define Py_UNICODE_TOUPPER(ch) _PyUnicode_ToUppercase(ch)
#define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch)

#define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)
#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)
#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)
387
#define Py_UNICODE_ISPRINTABLE(ch) _PyUnicode_IsPrintable(ch)
388 389 390 391 392

#define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)
#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)
#define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch)

393
#define Py_UNICODE_ISALPHA(ch) _PyUnicode_IsAlpha(ch)
394

395
#endif
396 397 398 399 400 401 402

#define Py_UNICODE_ISALNUM(ch) \
       (Py_UNICODE_ISALPHA(ch) || \
        Py_UNICODE_ISDECIMAL(ch) || \
        Py_UNICODE_ISDIGIT(ch) || \
        Py_UNICODE_ISNUMERIC(ch))

403 404
#define Py_UNICODE_COPY(target, source, length)				\
	Py_MEMCPY((target), (source), (length)*sizeof(Py_UNICODE))
405 406

#define Py_UNICODE_FILL(target, value, length) do\
407 408 409
    {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\
        for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\
    } while (0)
410

411 412 413 414 415 416
/* check if substring matches at given offset.  the offset must be
   valid, and the substring must not be empty */
#define Py_UNICODE_MATCH(string, offset, substring) \
    ((*((string)->str + (offset)) == *((substring)->str)) && \
    ((*((string)->str + (offset) + (substring)->length-1) == *((substring)->str + (substring)->length-1))) && \
     !memcmp((string)->str + (offset), (substring)->str, (substring)->length*sizeof(Py_UNICODE)))
417

418 419 420 421
#ifdef __cplusplus
extern "C" {
#endif

Christian Heimes's avatar
Christian Heimes committed
422 423
PyAPI_FUNC(int) PyUnicode_ClearFreeList(void);

424 425 426 427
/* --- Unicode Type ------------------------------------------------------- */

typedef struct {
    PyObject_HEAD
Martin v. Löwis's avatar
Martin v. Löwis committed
428
    Py_ssize_t length;		/* Length of raw Unicode data in buffer */
429 430
    Py_UNICODE *str;		/* Raw Unicode buffer */
    long hash;			/* Hash value; -1 if not set */
431 432 433
    int state;			/* != 0 if interned. In this case the two
    				 * references from the dictionary to this object
    				 * are *not* counted in ob_refcnt. */
434 435 436
    PyObject *defenc;		/* (Default) Encoded version as Python
				   string, or NULL; this is used for
				   implementing the buffer protocol */
437 438
} PyUnicodeObject;

439
PyAPI_DATA(PyTypeObject) PyUnicode_Type;
440
PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type;
441

442 443 444 445
#define SSTATE_NOT_INTERNED 0
#define SSTATE_INTERNED_MORTAL 1
#define SSTATE_INTERNED_IMMORTAL 2

446
#define PyUnicode_Check(op) \
447 448
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
#define PyUnicode_CheckExact(op) (Py_TYPE(op) == &PyUnicode_Type)
449 450 451

/* Fast access macros */
#define PyUnicode_GET_SIZE(op) \
452
        (assert(PyUnicode_Check(op)),(((PyUnicodeObject *)(op))->length))
453
#define PyUnicode_GET_DATA_SIZE(op) \
454
        (assert(PyUnicode_Check(op)),(((PyUnicodeObject *)(op))->length * sizeof(Py_UNICODE)))
455
#define PyUnicode_AS_UNICODE(op) \
456
        (assert(PyUnicode_Check(op)),(((PyUnicodeObject *)(op))->str))
457
#define PyUnicode_AS_DATA(op) \
458
        (assert(PyUnicode_Check(op)),((const char *)((PyUnicodeObject *)(op))->str))
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473

/* --- Constants ---------------------------------------------------------- */

/* This Unicode character will be used as replacement character during
   decoding if the errors argument is set to "replace". Note: the
   Unicode character U+FFFD is the official REPLACEMENT CHARACTER in
   Unicode 3.0. */

#define Py_UNICODE_REPLACEMENT_CHARACTER ((Py_UNICODE) 0xFFFD)

/* === Public API ========================================================= */

/* --- Plain Py_UNICODE --------------------------------------------------- */

/* Create a Unicode Object from the Py_UNICODE buffer u of the given
474 475 476 477 478 479
   size. 

   u may be NULL which causes the contents to be undefined. It is the
   user's responsibility to fill in the needed data afterwards. Note
   that modifying the Unicode object contents after construction is
   only allowed if u was set to NULL.
480 481 482

   The buffer is copied into the new object. */

483
PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(
484
    const Py_UNICODE *u,        /* Unicode buffer */
Martin v. Löwis's avatar
Martin v. Löwis committed
485
    Py_ssize_t size             /* size of buffer */
486 487
    );

488 489 490 491 492 493
/* Similar to PyUnicode_FromUnicode(), but u points to Latin-1 encoded bytes */
PyAPI_FUNC(PyObject*) PyUnicode_FromStringAndSize(
    const char *u,        /* char buffer */
    Py_ssize_t size       /* size of buffer */
    );

494 495 496 497 498 499
/* Similar to PyUnicode_FromUnicode(), but u points to null-terminated
   Latin-1 encoded bytes */
PyAPI_FUNC(PyObject*) PyUnicode_FromString(
    const char *u        /* string */
    );

500 501 502
/* Return a read-only pointer to the Unicode object's internal
   Py_UNICODE buffer. */

503
PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(
504 505 506 507 508
    PyObject *unicode	 	/* Unicode object */
    );

/* Get the length of the Unicode object. */

Martin v. Löwis's avatar
Martin v. Löwis committed
509
PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(
510 511 512
    PyObject *unicode	 	/* Unicode object */
    );

513
/* Get the maximum ordinal for a Unicode character. */
514
PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void);
515

516 517 518 519 520 521 522 523 524 525 526 527 528 529
/* Resize an already allocated Unicode object to the new size length.

   *unicode is modified to point to the new (resized) object and 0
   returned on success.

   This API may only be called by the function which also called the
   Unicode constructor. The refcount on the object must be 1. Otherwise,
   an error is returned.

   Error handling is implemented as follows: an exception is set, -1
   is returned and *unicode left untouched.

*/

530
PyAPI_FUNC(int) PyUnicode_Resize(
531
    PyObject **unicode,		/* Pointer to the Unicode object */
Martin v. Löwis's avatar
Martin v. Löwis committed
532
    Py_ssize_t length		/* New length */
533 534
    );

535 536 537 538 539
/* Coerce obj to an Unicode object and return a reference with
   *incremented* refcount.

   Coercion is done in the following way:

540
   1. String and other char buffer compatible objects are decoded
541 542
      under the assumptions that they contain data using the current
      default encoding. Decoding is done in "strict" mode.
543

544 545
   2. All other objects (including Unicode objects) raise an
      exception.
546 547 548 549 550 551

   The API returns NULL in case of an error. The caller is responsible
   for decref'ing the returned objects.

*/

552
PyAPI_FUNC(PyObject*) PyUnicode_FromEncodedObject(
553 554 555 556 557
    register PyObject *obj, 	/* Object */
    const char *encoding,       /* encoding */
    const char *errors          /* error handling */
    );

558
/* Coerce obj to an Unicode object and return a reference with
559
   *incremented* refcount.
560 561 562 563 564
   
   Unicode objects are passed back as-is (subclasses are converted to
   true Unicode objects), all other objects are delegated to
   PyUnicode_FromEncodedObject(obj, NULL, "strict") which results in
   using the default encoding as basis for decoding the object.
565 566 567 568 569 570

   The API returns NULL in case of an error. The caller is responsible
   for decref'ing the returned objects.

*/

571
PyAPI_FUNC(PyObject*) PyUnicode_FromObject(
572 573 574
    register PyObject *obj 	/* Object */
    );

575 576 577
PyAPI_FUNC(PyObject *) PyUnicode_FromFormatV(const char*, va_list);
PyAPI_FUNC(PyObject *) PyUnicode_FromFormat(const char*, ...);

578 579 580 581 582 583
/* Format the object based on the format_spec, as defined in PEP 3101
   (Advanced String Formatting). */
PyAPI_FUNC(PyObject *) _PyUnicode_FormatAdvanced(PyObject *obj,
                                                 Py_UNICODE *format_spec,
                                                 Py_ssize_t format_spec_len);

584 585 586 587 588 589 590 591
PyAPI_FUNC(void) PyUnicode_InternInPlace(PyObject **);
PyAPI_FUNC(void) PyUnicode_InternImmortal(PyObject **);
PyAPI_FUNC(PyObject *) PyUnicode_InternFromString(const char *);
PyAPI_FUNC(void) _Py_ReleaseInternedUnicodeStrings(void);

/* Use only if you know it's a string */
#define PyUnicode_CHECK_INTERNED(op) (((PyUnicodeObject *)(op))->state)

592 593 594 595 596 597 598 599 600
/* --- wchar_t support for platforms which support it --------------------- */

#ifdef HAVE_WCHAR_H

/* Create a Unicode Object from the whcar_t buffer w of the given
   size.

   The buffer is copied into the new object. */

601
PyAPI_FUNC(PyObject*) PyUnicode_FromWideChar(
602
    register const wchar_t *w,  /* wchar_t buffer */
Martin v. Löwis's avatar
Martin v. Löwis committed
603
    Py_ssize_t size             /* size of buffer */
604 605
    );

606
/* Copies the Unicode Object contents into the wchar_t buffer w.  At
607 608
   most size wchar_t characters are copied.

609 610 611 612 613 614 615
   Note that the resulting wchar_t string may or may not be
   0-terminated.  It is the responsibility of the caller to make sure
   that the wchar_t string is 0-terminated in case this is required by
   the application.

   Returns the number of wchar_t characters copied (excluding a
   possibly trailing 0-termination character) or -1 in case of an
616 617
   error. */

Martin v. Löwis's avatar
Martin v. Löwis committed
618
PyAPI_FUNC(Py_ssize_t) PyUnicode_AsWideChar(
619 620
    PyUnicodeObject *unicode,   /* Unicode object */
    register wchar_t *w,        /* wchar_t buffer */
Martin v. Löwis's avatar
Martin v. Löwis committed
621
    Py_ssize_t size             /* size of buffer */
622 623 624 625
    );

#endif

626 627 628 629 630 631 632 633 634 635
/* --- Unicode ordinals --------------------------------------------------- */

/* Create a Unicode Object from the given Unicode code point ordinal. 
 
   The ordinal must be in range(0x10000) on narrow Python builds
   (UCS2), and range(0x110000) on wide builds (UCS4). A ValueError is
   raised in case it is not.

*/

636
PyAPI_FUNC(PyObject*) PyUnicode_FromOrdinal(int ordinal);
637

638 639 640 641 642 643
/* === Builtin Codecs ===================================================== 

   Many of these APIs take two arguments encoding and errors. These
   parameters encoding and errors have the same semantics as the ones
   of the builtin unicode() API. 

644
   Setting encoding to NULL causes the default encoding to be used.
645 646 647 648 649 650 651 652 653 654 655

   Error handling is set by errors which may also be set to NULL
   meaning to use the default handling defined for the codec. Default
   error handling for all builtin codecs is "strict" (ValueErrors are
   raised).

   The codecs all use a similar interface. Only deviation from the
   generic ones are documented.

*/

656 657
/* --- Manage the default encoding ---------------------------------------- */

658 659 660 661 662 663 664 665 666 667 668 669 670 671
/* Return a Python string holding the default encoded value of the
   Unicode object. 

   The resulting string is cached in the Unicode object for subsequent
   usage by this function. The cached version is needed to implement
   the character buffer interface and will live (at least) as long as
   the Unicode object itself.

   The refcount of the string is *not* incremented.

   *** Exported for internal use by the interpreter only !!! ***

*/

672
PyAPI_FUNC(PyObject *) _PyUnicode_AsDefaultEncodedString(
673 674
    PyObject *unicode,
    const char *errors);
675

676 677 678 679 680 681 682 683 684 685 686 687 688 689
/* Decode a null-terminated string using Py_FileSystemDefaultEncoding.

   If the encoding is supported by one of the built-in codecs (i.e., UTF-8,
   UTF-16, UTF-32, Latin-1 or MBCS), otherwise fallback to UTF-8 and replace
   invalid characters with '?'.

   The function is intended to be used for paths and file names only
   during bootstrapping process where the codecs are not set up.
*/

PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefault(
    const char *s               /* encoded string */
    );

690 691 692 693 694
PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefaultAndSize(
    const char *s,               /* encoded string */
    Py_ssize_t size              /* size */
    );

695 696 697
/* Returns a pointer to the default encoding (normally, UTF-8) of the
   Unicode object unicode and the size of the encoded representation
   in bytes stored in *size.
698

699
   In case of an error, no *size is set.
700

701 702
*/

703 704 705
PyAPI_FUNC(char *) PyUnicode_AsStringAndSize(
    PyObject *unicode, 
    Py_ssize_t *size);
706

707 708
/* Returns a pointer to the default encoding (normally, UTf-8) of the
   Unicode object unicode.
709

710 711 712
   Use of this API is DEPRECATED since no size information can be
   extracted from the returned data. Use PyUnicode_AsStringAndSize()
   instead.
713

714
*/
715

716
PyAPI_FUNC(char *) PyUnicode_AsString(PyObject *unicode);
717

718
/* Returns the currently active default encoding.
719

720 721 722 723 724
   The default encoding is currently implemented as run-time settable
   process global.  This may change in future versions of the
   interpreter to become a parameter which is managed on a per-thread
   basis.
   
725 726
 */

727
PyAPI_FUNC(const char*) PyUnicode_GetDefaultEncoding(void);
728 729 730 731 732 733 734

/* Sets the currently active default encoding.

   Returns 0 on success, -1 in case of an error.
   
 */

735
PyAPI_FUNC(int) PyUnicode_SetDefaultEncoding(
736 737 738
    const char *encoding	/* Encoding name in standard form */
    );

739 740 741 742 743
/* --- Generic Codecs ----------------------------------------------------- */

/* Create a Unicode object by decoding the encoded string s of the
   given size. */

744
PyAPI_FUNC(PyObject*) PyUnicode_Decode(
745
    const char *s,              /* encoded string */
Martin v. Löwis's avatar
Martin v. Löwis committed
746
    Py_ssize_t size,            /* size of buffer */
747 748 749 750 751 752 753
    const char *encoding,       /* encoding */
    const char *errors          /* error handling */
    );

/* Encodes a Py_UNICODE buffer of the given size and returns a 
   Python string object. */

754
PyAPI_FUNC(PyObject*) PyUnicode_Encode(
755
    const Py_UNICODE *s,        /* Unicode char buffer */
Martin v. Löwis's avatar
Martin v. Löwis committed
756
    Py_ssize_t size,            /* number of Py_UNICODE chars to encode */
757 758 759 760
    const char *encoding,       /* encoding */
    const char *errors          /* error handling */
    );

761 762 763 764 765 766 767 768 769
/* Encodes a Unicode object and returns the result as Python
   object. */

PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedObject(
    PyObject *unicode,	 	/* Unicode object */
    const char *encoding,	/* encoding */
    const char *errors		/* error handling */
    );

770 771 772
/* Encodes a Unicode object and returns the result as Python string
   object. */

773
PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedString(
774 775 776 777 778
    PyObject *unicode,	 	/* Unicode object */
    const char *encoding,	/* encoding */
    const char *errors		/* error handling */
    );

779 780 781 782 783
PyAPI_FUNC(PyObject*) PyUnicode_BuildEncodingMap(
    PyObject* string            /* 256 character map */
   );


784 785
/* --- UTF-7 Codecs ------------------------------------------------------- */

786
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7(
787
    const char *string, 	/* UTF-7 encoded string */
Martin v. Löwis's avatar
Martin v. Löwis committed
788
    Py_ssize_t length,	 	/* size of string */
789 790 791
    const char *errors		/* error handling */
    );

792 793 794 795 796 797 798
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7Stateful(
    const char *string, 	/* UTF-7 encoded string */
    Py_ssize_t length,	 	/* size of string */
    const char *errors,		/* error handling */
    Py_ssize_t *consumed	/* bytes consumed */
    );

799
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7(
800
    const Py_UNICODE *data, 	/* Unicode char buffer */
Neal Norwitz's avatar
Neal Norwitz committed
801
    Py_ssize_t length,	 	/* number of Py_UNICODE chars to encode */
802 803 804 805 806 807 808
    int encodeSetO,             /* force the encoder to encode characters in
                                   Set O, as described in RFC2152 */
    int encodeWhiteSpace,       /* force the encoder to encode space, tab,
                                   carriage return and linefeed characters */
    const char *errors		/* error handling */
    );

809 810
/* --- UTF-8 Codecs ------------------------------------------------------- */

811
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8(
812
    const char *string, 	/* UTF-8 encoded string */
Martin v. Löwis's avatar
Martin v. Löwis committed
813
    Py_ssize_t length,	 	/* size of string */
814 815 816
    const char *errors		/* error handling */
    );

817 818
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8Stateful(
    const char *string, 	/* UTF-8 encoded string */
Martin v. Löwis's avatar
Martin v. Löwis committed
819
    Py_ssize_t length,	 	/* size of string */
820
    const char *errors,		/* error handling */
Neal Norwitz's avatar
Neal Norwitz committed
821
    Py_ssize_t *consumed	/* bytes consumed */
822 823
    );

824
PyAPI_FUNC(PyObject*) PyUnicode_AsUTF8String(
825 826 827
    PyObject *unicode	 	/* Unicode object */
    );

828
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF8(
829
    const Py_UNICODE *data, 	/* Unicode char buffer */
Neal Norwitz's avatar
Neal Norwitz committed
830
    Py_ssize_t length,	 	/* number of Py_UNICODE chars to encode */
831 832 833
    const char *errors		/* error handling */
    );

834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
/* --- UTF-32 Codecs ------------------------------------------------------ */

/* Decodes length bytes from a UTF-32 encoded buffer string and returns
   the corresponding Unicode object.

   errors (if non-NULL) defines the error handling. It defaults
   to "strict". 

   If byteorder is non-NULL, the decoder starts decoding using the
   given byte order:

	*byteorder == -1: little endian
	*byteorder == 0:  native order
	*byteorder == 1:  big endian

   In native mode, the first four bytes of the stream are checked for a
   BOM mark. If found, the BOM mark is analysed, the byte order
   adjusted and the BOM skipped.  In the other modes, no BOM mark
   interpretation is done. After completion, *byteorder is set to the
   current byte order at the end of input data.

   If byteorder is NULL, the codec starts in native order mode.

*/

PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF32(
    const char *string, 	/* UTF-32 encoded string */
    Py_ssize_t length,	 	/* size of string */
    const char *errors,		/* error handling */
    int *byteorder		/* pointer to byteorder to use
				   0=native;-1=LE,1=BE; updated on
				   exit */
    );

PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF32Stateful(
    const char *string, 	/* UTF-32 encoded string */
    Py_ssize_t length,	 	/* size of string */
    const char *errors,		/* error handling */
    int *byteorder,		/* pointer to byteorder to use
				   0=native;-1=LE,1=BE; updated on
				   exit */
    Py_ssize_t *consumed	/* bytes consumed */
    );

/* Returns a Python string using the UTF-32 encoding in native byte
   order. The string always starts with a BOM mark.  */

PyAPI_FUNC(PyObject*) PyUnicode_AsUTF32String(
    PyObject *unicode	 	/* Unicode object */
    );

/* Returns a Python string object holding the UTF-32 encoded value of
   the Unicode data.

   If byteorder is not 0, output is written according to the following
   byte order:

   byteorder == -1: little endian
   byteorder == 0:  native byte order (writes a BOM mark)
   byteorder == 1:  big endian

   If byteorder is 0, the output string will always start with the
   Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is
   prepended.

*/

PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF32(
    const Py_UNICODE *data, 	/* Unicode char buffer */
    Py_ssize_t length,	 	/* number of Py_UNICODE chars to encode */
    const char *errors,		/* error handling */
    int byteorder		/* byteorder to use 0=BOM+native;-1=LE,1=BE */
    );

908 909
/* --- UTF-16 Codecs ------------------------------------------------------ */

910
/* Decodes length bytes from a UTF-16 encoded buffer string and returns
911 912 913 914 915 916 917 918 919 920 921 922
   the corresponding Unicode object.

   errors (if non-NULL) defines the error handling. It defaults
   to "strict". 

   If byteorder is non-NULL, the decoder starts decoding using the
   given byte order:

	*byteorder == -1: little endian
	*byteorder == 0:  native order
	*byteorder == 1:  big endian

923 924 925 926 927
   In native mode, the first two bytes of the stream are checked for a
   BOM mark. If found, the BOM mark is analysed, the byte order
   adjusted and the BOM skipped.  In the other modes, no BOM mark
   interpretation is done. After completion, *byteorder is set to the
   current byte order at the end of input data.
928 929 930 931 932

   If byteorder is NULL, the codec starts in native order mode.

*/

933
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16(
934
    const char *string, 	/* UTF-16 encoded string */
Martin v. Löwis's avatar
Martin v. Löwis committed
935
    Py_ssize_t length,	 	/* size of string */
936 937 938 939 940 941
    const char *errors,		/* error handling */
    int *byteorder		/* pointer to byteorder to use
				   0=native;-1=LE,1=BE; updated on
				   exit */
    );

942 943
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16Stateful(
    const char *string, 	/* UTF-16 encoded string */
Martin v. Löwis's avatar
Martin v. Löwis committed
944
    Py_ssize_t length,	 	/* size of string */
945 946 947 948
    const char *errors,		/* error handling */
    int *byteorder,		/* pointer to byteorder to use
				   0=native;-1=LE,1=BE; updated on
				   exit */
Neal Norwitz's avatar
Neal Norwitz committed
949
    Py_ssize_t *consumed	/* bytes consumed */
950 951
    );

952 953 954
/* Returns a Python string using the UTF-16 encoding in native byte
   order. The string always starts with a BOM mark.  */

955
PyAPI_FUNC(PyObject*) PyUnicode_AsUTF16String(
956 957 958 959
    PyObject *unicode	 	/* Unicode object */
    );

/* Returns a Python string object holding the UTF-16 encoded value of
960
   the Unicode data.
961 962 963 964 965 966 967 968 969 970 971 972 973 974

   If byteorder is not 0, output is written according to the following
   byte order:

   byteorder == -1: little endian
   byteorder == 0:  native byte order (writes a BOM mark)
   byteorder == 1:  big endian

   If byteorder is 0, the output string will always start with the
   Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is
   prepended.

   Note that Py_UNICODE data is being interpreted as UTF-16 reduced to
   UCS-2. This trick makes it possible to add full UTF-16 capabilities
975
   at a later point without compromising the APIs.
976 977 978

*/

979
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF16(
980
    const Py_UNICODE *data, 	/* Unicode char buffer */
Neal Norwitz's avatar
Neal Norwitz committed
981
    Py_ssize_t length,	 	/* number of Py_UNICODE chars to encode */
982 983 984 985 986 987
    const char *errors,		/* error handling */
    int byteorder		/* byteorder to use 0=BOM+native;-1=LE,1=BE */
    );

/* --- Unicode-Escape Codecs ---------------------------------------------- */

988
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUnicodeEscape(
989
    const char *string, 	/* Unicode-Escape encoded string */
Martin v. Löwis's avatar
Martin v. Löwis committed
990
    Py_ssize_t length,	 	/* size of string */
991 992 993
    const char *errors		/* error handling */
    );

994
PyAPI_FUNC(PyObject*) PyUnicode_AsUnicodeEscapeString(
995 996 997
    PyObject *unicode	 	/* Unicode object */
    );

998
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUnicodeEscape(
999
    const Py_UNICODE *data, 	/* Unicode char buffer */
Neal Norwitz's avatar
Neal Norwitz committed
1000
    Py_ssize_t length	 	/* Number of Py_UNICODE chars to encode */
1001 1002 1003 1004
    );

/* --- Raw-Unicode-Escape Codecs ------------------------------------------ */

1005
PyAPI_FUNC(PyObject*) PyUnicode_DecodeRawUnicodeEscape(
1006
    const char *string, 	/* Raw-Unicode-Escape encoded string */
Martin v. Löwis's avatar
Martin v. Löwis committed
1007
    Py_ssize_t length,	 	/* size of string */
1008 1009 1010
    const char *errors		/* error handling */
    );

1011
PyAPI_FUNC(PyObject*) PyUnicode_AsRawUnicodeEscapeString(
1012 1013 1014
    PyObject *unicode	 	/* Unicode object */
    );

1015
PyAPI_FUNC(PyObject*) PyUnicode_EncodeRawUnicodeEscape(
1016
    const Py_UNICODE *data, 	/* Unicode char buffer */
Neal Norwitz's avatar
Neal Norwitz committed
1017
    Py_ssize_t length	 	/* Number of Py_UNICODE chars to encode */
1018 1019
    );

1020 1021 1022 1023 1024 1025
/* --- Unicode Internal Codec ---------------------------------------------

    Only for internal use in _codecsmodule.c */

PyObject *_PyUnicode_DecodeUnicodeInternal(
    const char *string,
Martin v. Löwis's avatar
Martin v. Löwis committed
1026
    Py_ssize_t length,
1027 1028 1029
    const char *errors
    );

1030 1031 1032 1033 1034 1035
/* --- Latin-1 Codecs ----------------------------------------------------- 

   Note: Latin-1 corresponds to the first 256 Unicode ordinals.

*/

1036
PyAPI_FUNC(PyObject*) PyUnicode_DecodeLatin1(
1037
    const char *string, 	/* Latin-1 encoded string */
Martin v. Löwis's avatar
Martin v. Löwis committed
1038
    Py_ssize_t length,	 	/* size of string */
1039 1040 1041
    const char *errors		/* error handling */
    );

1042
PyAPI_FUNC(PyObject*) PyUnicode_AsLatin1String(
1043 1044 1045
    PyObject *unicode	 	/* Unicode object */
    );

1046
PyAPI_FUNC(PyObject*) PyUnicode_EncodeLatin1(
1047
    const Py_UNICODE *data, 	/* Unicode char buffer */
Neal Norwitz's avatar
Neal Norwitz committed
1048
    Py_ssize_t length,	 	/* Number of Py_UNICODE chars to encode */
1049 1050 1051 1052 1053 1054 1055 1056 1057
    const char *errors		/* error handling */
    );

/* --- ASCII Codecs ------------------------------------------------------- 

   Only 7-bit ASCII data is excepted. All other codes generate errors.

*/

1058
PyAPI_FUNC(PyObject*) PyUnicode_DecodeASCII(
1059
    const char *string, 	/* ASCII encoded string */
Martin v. Löwis's avatar
Martin v. Löwis committed
1060
    Py_ssize_t length,	 	/* size of string */
1061 1062 1063
    const char *errors		/* error handling */
    );

1064
PyAPI_FUNC(PyObject*) PyUnicode_AsASCIIString(
1065 1066 1067
    PyObject *unicode	 	/* Unicode object */
    );

1068
PyAPI_FUNC(PyObject*) PyUnicode_EncodeASCII(
1069
    const Py_UNICODE *data, 	/* Unicode char buffer */
Neal Norwitz's avatar
Neal Norwitz committed
1070
    Py_ssize_t length,	 	/* Number of Py_UNICODE chars to encode */
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
    const char *errors		/* error handling */
    );

/* --- Character Map Codecs ----------------------------------------------- 

   This codec uses mappings to encode and decode characters. 

   Decoding mappings must map single string characters to single
   Unicode characters, integers (which are then interpreted as Unicode
   ordinals) or None (meaning "undefined mapping" and causing an
   error).

   Encoding mappings must map single Unicode characters to single
   string characters, integers (which are then interpreted as Latin-1
   ordinals) or None (meaning "undefined mapping" and causing an
   error).

   If a character lookup fails with a LookupError, the character is
   copied as-is meaning that its ordinal value will be interpreted as
   Unicode or Latin-1 ordinal resp. Because of this mappings only need
   to contain those mappings which map characters to different code
   points.

*/

1096
PyAPI_FUNC(PyObject*) PyUnicode_DecodeCharmap(
1097
    const char *string, 	/* Encoded string */
Martin v. Löwis's avatar
Martin v. Löwis committed
1098
    Py_ssize_t length,	 	/* size of string */
1099 1100 1101 1102 1103
    PyObject *mapping,		/* character mapping 
				   (char ordinal -> unicode ordinal) */
    const char *errors		/* error handling */
    );

1104
PyAPI_FUNC(PyObject*) PyUnicode_AsCharmapString(
1105 1106 1107 1108 1109
    PyObject *unicode,	 	/* Unicode object */
    PyObject *mapping		/* character mapping 
				   (unicode ordinal -> char ordinal) */
    );

1110
PyAPI_FUNC(PyObject*) PyUnicode_EncodeCharmap(
1111
    const Py_UNICODE *data, 	/* Unicode char buffer */
Martin v. Löwis's avatar
Martin v. Löwis committed
1112
    Py_ssize_t length,	 	/* Number of Py_UNICODE chars to encode */
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
    PyObject *mapping,		/* character mapping 
				   (unicode ordinal -> char ordinal) */
    const char *errors		/* error handling */
    );

/* Translate a Py_UNICODE buffer of the given length by applying a
   character mapping table to it and return the resulting Unicode
   object.

   The mapping table must map Unicode ordinal integers to Unicode
   ordinal integers or None (causing deletion of the character). 

   Mapping tables may be dictionaries or sequences. Unmapped character
   ordinals (ones which cause a LookupError) are left untouched and
   are copied as-is.

*/

1131
PyAPI_FUNC(PyObject *) PyUnicode_TranslateCharmap(
1132
    const Py_UNICODE *data, 	/* Unicode char buffer */
Neal Norwitz's avatar
Neal Norwitz committed
1133
    Py_ssize_t length,	 	/* Number of Py_UNICODE chars to encode */
1134 1135 1136 1137
    PyObject *table,		/* Translate table */
    const char *errors		/* error handling */
    );

1138
#ifdef MS_WIN32
Guido van Rossum's avatar
Guido van Rossum committed
1139

1140
/* --- MBCS codecs for Windows -------------------------------------------- */
Guido van Rossum's avatar
Guido van Rossum committed
1141

1142
PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCS(
1143
    const char *string,         /* MBCS encoded string */
Martin v. Löwis's avatar
Martin v. Löwis committed
1144
    Py_ssize_t length,              /* size of string */
1145 1146 1147
    const char *errors          /* error handling */
    );

1148 1149 1150 1151 1152 1153 1154
PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCSStateful(
    const char *string,         /* MBCS encoded string */
    Py_ssize_t length,          /* size of string */
    const char *errors,         /* error handling */
    Py_ssize_t *consumed        /* bytes consumed */
    );

1155
PyAPI_FUNC(PyObject*) PyUnicode_AsMBCSString(
1156 1157 1158
    PyObject *unicode           /* Unicode object */
    );

1159
PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS(
1160
    const Py_UNICODE *data,     /* Unicode char buffer */
Neal Norwitz's avatar
Neal Norwitz committed
1161
    Py_ssize_t length,          /* Number of Py_UNICODE chars to encode */
1162 1163 1164 1165
    const char *errors          /* error handling */
    );

#endif /* MS_WIN32 */
Guido van Rossum's avatar
Guido van Rossum committed
1166

1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
/* --- Decimal Encoder ---------------------------------------------------- */

/* Takes a Unicode string holding a decimal value and writes it into
   an output buffer using standard ASCII digit codes.

   The output buffer has to provide at least length+1 bytes of storage
   area. The output string is 0-terminated.

   The encoder converts whitespace to ' ', decimal characters to their
   corresponding ASCII digit and all other Latin-1 characters except
   \0 as-is. Characters outside this range (Unicode ordinals 1-256)
   are treated as errors. This includes embedded NULL bytes.

   Error handling is defined by the errors argument:

      NULL or "strict": raise a ValueError
      "ignore": ignore the wrong characters (these are not copied to the
		output buffer)
      "replace": replaces illegal characters with '?'

   Returns 0 on success, -1 on failure.

*/

1191
PyAPI_FUNC(int) PyUnicode_EncodeDecimal(
1192
    Py_UNICODE *s,		/* Unicode buffer */
Neal Norwitz's avatar
Neal Norwitz committed
1193
    Py_ssize_t length,		/* Number of Py_UNICODE chars to encode */
1194 1195 1196 1197
    char *output,		/* Output buffer; must have size >= length */
    const char *errors		/* error handling */
    );

1198 1199 1200 1201 1202 1203 1204 1205
/* --- Methods & Slots ----------------------------------------------------

   These are capable of handling Unicode objects and strings on input
   (we refer to them as strings in the descriptions) and return
   Unicode objects or integers as apporpriate. */

/* Concat two strings giving a new Unicode string. */

1206
PyAPI_FUNC(PyObject*) PyUnicode_Concat(
1207 1208 1209 1210
    PyObject *left,	 	/* Left string */
    PyObject *right	 	/* Right string */
    );

1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226
/* Concat two strings and put the result in *pleft
   (sets *pleft to NULL on error) */

PyAPI_FUNC(void) PyUnicode_Append(
    PyObject **pleft,	 	/* Pointer to left string */
    PyObject *right	 	/* Right string */
    );

/* Concat two strings, put the result in *pleft and drop the right object
   (sets *pleft to NULL on error) */

PyAPI_FUNC(void) PyUnicode_AppendAndDel(
    PyObject **pleft,	 	/* Pointer to left string */
    PyObject *right	 	/* Right string */
    );

1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
/* Split a string giving a list of Unicode strings.

   If sep is NULL, splitting will be done at all whitespace
   substrings. Otherwise, splits occur at the given separator.

   At most maxsplit splits will be done. If negative, no limit is set.

   Separators are not included in the resulting list.

*/

1238
PyAPI_FUNC(PyObject*) PyUnicode_Split(
1239 1240
    PyObject *s,		/* String to split */
    PyObject *sep,		/* String separator */
Martin v. Löwis's avatar
Martin v. Löwis committed
1241
    Py_ssize_t maxsplit		/* Maxsplit count */
1242 1243 1244 1245 1246 1247 1248
    );		

/* Dito, but split at line breaks.

   CRLF is considered to be one line break. Line breaks are not
   included in the resulting list. */
    
1249
PyAPI_FUNC(PyObject*) PyUnicode_Splitlines(
1250
    PyObject *s,		/* String to split */
Guido van Rossum's avatar
Guido van Rossum committed
1251
    int keepends		/* If true, line end markers are included */
1252 1253
    );		

1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
/* Partition a string using a given separator. */

PyAPI_FUNC(PyObject*) PyUnicode_Partition(
    PyObject *s,		/* String to partition */
    PyObject *sep		/* String separator */
    );		

/* Partition a string using a given separator, searching from the end of the
   string. */

PyAPI_FUNC(PyObject*) PyUnicode_RPartition(
    PyObject *s,		/* String to partition */
    PyObject *sep		/* String separator */
    );		

1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284
/* Split a string giving a list of Unicode strings.

   If sep is NULL, splitting will be done at all whitespace
   substrings. Otherwise, splits occur at the given separator.

   At most maxsplit splits will be done. But unlike PyUnicode_Split
   PyUnicode_RSplit splits from the end of the string. If negative,
   no limit is set.

   Separators are not included in the resulting list.

*/

PyAPI_FUNC(PyObject*) PyUnicode_RSplit(
    PyObject *s,		/* String to split */
    PyObject *sep,		/* String separator */
Martin v. Löwis's avatar
Martin v. Löwis committed
1285
    Py_ssize_t maxsplit		/* Maxsplit count */
1286 1287
    );		

1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
/* Translate a string by applying a character mapping table to it and
   return the resulting Unicode object.

   The mapping table must map Unicode ordinal integers to Unicode
   ordinal integers or None (causing deletion of the character). 

   Mapping tables may be dictionaries or sequences. Unmapped character
   ordinals (ones which cause a LookupError) are left untouched and
   are copied as-is.

*/

1300
PyAPI_FUNC(PyObject *) PyUnicode_Translate(
1301 1302 1303 1304 1305 1306 1307 1308
    PyObject *str,		/* String */ 
    PyObject *table,		/* Translate table */
    const char *errors		/* error handling */
    );

/* Join a sequence of strings using the given separator and return
   the resulting Unicode string. */
    
1309
PyAPI_FUNC(PyObject*) PyUnicode_Join(
1310 1311 1312 1313 1314 1315 1316
    PyObject *separator, 	/* Separator string */
    PyObject *seq	 	/* Sequence object */
    );

/* Return 1 if substr matches str[start:end] at the given tail end, 0
   otherwise. */

Martin v. Löwis's avatar
Martin v. Löwis committed
1317
PyAPI_FUNC(Py_ssize_t) PyUnicode_Tailmatch(
1318 1319
    PyObject *str,		/* String */ 
    PyObject *substr,		/* Prefix or Suffix string */
Martin v. Löwis's avatar
Martin v. Löwis committed
1320 1321
    Py_ssize_t start,		/* Start index */
    Py_ssize_t end,		/* Stop index */
1322 1323 1324 1325
    int direction		/* Tail end: -1 prefix, +1 suffix */
    );

/* Return the first position of substr in str[start:end] using the
1326 1327
   given search direction or -1 if not found. -2 is returned in case
   an error occurred and an exception is set. */
1328

Martin v. Löwis's avatar
Martin v. Löwis committed
1329
PyAPI_FUNC(Py_ssize_t) PyUnicode_Find(
1330 1331
    PyObject *str,		/* String */ 
    PyObject *substr,		/* Substring to find */
Martin v. Löwis's avatar
Martin v. Löwis committed
1332 1333
    Py_ssize_t start,		/* Start index */
    Py_ssize_t end,		/* Stop index */
1334 1335 1336
    int direction		/* Find direction: +1 forward, -1 backward */
    );

1337
/* Count the number of occurrences of substr in str[start:end]. */
1338

Martin v. Löwis's avatar
Martin v. Löwis committed
1339
PyAPI_FUNC(Py_ssize_t) PyUnicode_Count(
1340 1341
    PyObject *str,		/* String */ 
    PyObject *substr,		/* Substring to count */
Martin v. Löwis's avatar
Martin v. Löwis committed
1342 1343
    Py_ssize_t start,		/* Start index */
    Py_ssize_t end		/* Stop index */
1344 1345
    );

1346
/* Replace at most maxcount occurrences of substr in str with replstr
1347 1348
   and return the resulting Unicode object. */

1349
PyAPI_FUNC(PyObject *) PyUnicode_Replace(
1350 1351 1352
    PyObject *str,		/* String */ 
    PyObject *substr,		/* Substring to find */
    PyObject *replstr,		/* Substring to replace */
Martin v. Löwis's avatar
Martin v. Löwis committed
1353
    Py_ssize_t maxcount		/* Max. number of replacements to apply;
1354 1355 1356 1357 1358 1359
				   -1 = all */
    );

/* Compare two strings and return -1, 0, 1 for less than, equal,
   greater than resp. */

1360
PyAPI_FUNC(int) PyUnicode_Compare(
1361 1362 1363 1364
    PyObject *left,		/* Left string */ 
    PyObject *right		/* Right string */
    );

1365 1366 1367 1368 1369
PyAPI_FUNC(int) PyUnicode_CompareWithASCIIString(
    PyObject *left,
    const char *right
    );

1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
/* Rich compare two strings and return one of the following:

   - NULL in case an exception was raised
   - Py_True or Py_False for successfuly comparisons
   - Py_NotImplemented in case the type combination is unknown

   Note that Py_EQ and Py_NE comparisons can cause a UnicodeWarning in
   case the conversion of the arguments to Unicode fails with a
   UnicodeDecodeError.

   Possible values for op:

     Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE

*/

PyAPI_FUNC(PyObject *) PyUnicode_RichCompare(
    PyObject *left,		/* Left string */ 
    PyObject *right,		/* Right string */
    int op			/* Operation: Py_EQ, Py_NE, Py_GT, etc. */
    );

1392
/* Apply a argument tuple or dictionary to a format string and return
1393 1394
   the resulting Unicode string. */

1395
PyAPI_FUNC(PyObject *) PyUnicode_Format(
1396 1397 1398 1399
    PyObject *format,		/* Format string */ 
    PyObject *args		/* Argument tuple or dictionary */
    );

1400 1401 1402 1403 1404 1405
/* Checks whether element is contained in container and return 1/0
   accordingly.

   element has to coerce to an one element Unicode string. -1 is
   returned in case of an error. */

1406
PyAPI_FUNC(int) PyUnicode_Contains(
1407 1408 1409 1410
    PyObject *container,	/* Container string */ 
    PyObject *element		/* Element string */
    );

1411 1412 1413 1414
/* Checks whether argument is a valid identifier. */

PyAPI_FUNC(int) PyUnicode_IsIdentifier(PyObject *s);

1415
/* Externally visible for str.strip(unicode) */
1416
PyAPI_FUNC(PyObject *) _PyUnicode_XStrip(
1417 1418 1419 1420 1421
    PyUnicodeObject *self,
    int striptype,
    PyObject *sepobj
    );

1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432
/* Using the current locale, insert the thousands grouping
   into the string pointed to by buffer.  For the argument descriptions,
   see Objects/stringlib/localeutil.h */

PyAPI_FUNC(int) _PyUnicode_InsertThousandsGrouping(Py_UNICODE *buffer,
						  Py_ssize_t len,
						  Py_UNICODE *plast,
						  Py_ssize_t buf_size,
						  Py_ssize_t *count,
						  int append_zero_char);

1433 1434 1435 1436 1437 1438 1439 1440 1441
/* === Characters Type APIs =============================================== */

/* These should not be used directly. Use the Py_UNICODE_IS* and
   Py_UNICODE_TO* macros instead. 

   These APIs are implemented in Objects/unicodectype.c.

*/

1442
PyAPI_FUNC(int) _PyUnicode_IsLowercase(
1443
    Py_UNICODE ch 	/* Unicode character */
1444 1445
    );

1446
PyAPI_FUNC(int) _PyUnicode_IsUppercase(
1447
    Py_UNICODE ch 	/* Unicode character */
1448 1449
    );

1450
PyAPI_FUNC(int) _PyUnicode_IsTitlecase(
1451
    Py_UNICODE ch 	/* Unicode character */
1452 1453
    );

1454 1455 1456 1457 1458 1459 1460 1461
PyAPI_FUNC(int) _PyUnicode_IsXidStart(
    Py_UNICODE ch 	/* Unicode character */
    );

PyAPI_FUNC(int) _PyUnicode_IsXidContinue(
    Py_UNICODE ch 	/* Unicode character */
    );

1462
PyAPI_FUNC(int) _PyUnicode_IsWhitespace(
Tim Peters's avatar
Tim Peters committed
1463
    const Py_UNICODE ch 	/* Unicode character */
1464 1465
    );

1466
PyAPI_FUNC(int) _PyUnicode_IsLinebreak(
Tim Peters's avatar
Tim Peters committed
1467
    const Py_UNICODE ch 	/* Unicode character */
1468 1469
    );

1470
PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToLowercase(
1471
    Py_UNICODE ch 	/* Unicode character */
1472 1473
    );

1474
PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToUppercase(
1475
    Py_UNICODE ch 	/* Unicode character */
1476 1477
    );

1478
PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToTitlecase(
1479
    Py_UNICODE ch 	/* Unicode character */
1480 1481
    );

1482
PyAPI_FUNC(int) _PyUnicode_ToDecimalDigit(
1483
    Py_UNICODE ch 	/* Unicode character */
1484 1485
    );

1486
PyAPI_FUNC(int) _PyUnicode_ToDigit(
1487
    Py_UNICODE ch 	/* Unicode character */
1488 1489
    );

1490
PyAPI_FUNC(double) _PyUnicode_ToNumeric(
1491
    Py_UNICODE ch 	/* Unicode character */
1492 1493
    );

1494
PyAPI_FUNC(int) _PyUnicode_IsDecimalDigit(
1495
    Py_UNICODE ch 	/* Unicode character */
1496 1497
    );

1498
PyAPI_FUNC(int) _PyUnicode_IsDigit(
1499
    Py_UNICODE ch 	/* Unicode character */
1500 1501
    );

1502
PyAPI_FUNC(int) _PyUnicode_IsNumeric(
1503
    Py_UNICODE ch 	/* Unicode character */
1504 1505
    );

1506 1507 1508 1509
PyAPI_FUNC(int) _PyUnicode_IsPrintable(
    Py_UNICODE ch 	/* Unicode character */
    );

1510
PyAPI_FUNC(int) _PyUnicode_IsAlpha(
1511
    Py_UNICODE ch 	/* Unicode character */
1512 1513
    );

1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528
PyAPI_FUNC(size_t) Py_UNICODE_strlen(const Py_UNICODE *u);

PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcpy(
    Py_UNICODE *s1, const Py_UNICODE *s2);

PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strncpy(
    Py_UNICODE *s1, const Py_UNICODE *s2, size_t n);

PyAPI_FUNC(int) Py_UNICODE_strcmp(
    const Py_UNICODE *s1, const Py_UNICODE *s2);

PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr(
    const Py_UNICODE *s, Py_UNICODE c
    );

1529 1530 1531 1532
#ifdef __cplusplus
}
#endif
#endif /* !Py_UNICODEOBJECT_H */