Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1 | #ifndef Py_UNICODEOBJECT_H |
| 2 | #define Py_UNICODEOBJECT_H |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 3 | |
Christian Heimes | af98da1 | 2008-01-27 15:18:18 +0000 | [diff] [blame] | 4 | #include <stdarg.h> |
| 5 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 6 | /* |
| 7 | |
| 8 | Unicode implementation based on original code by Fredrik Lundh, |
| 9 | modified by Marc-Andre Lemburg (mal@lemburg.com) according to the |
| 10 | Unicode Integration Proposal (see file Misc/unicode.txt). |
| 11 | |
Guido van Rossum | 16b1ad9 | 2000-08-03 16:24:25 +0000 | [diff] [blame] | 12 | Copyright (c) Corporation for National Research Initiatives. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 13 | |
| 14 | |
| 15 | Original header: |
| 16 | -------------------------------------------------------------------- |
| 17 | |
| 18 | * Yet another Unicode string type for Python. This type supports the |
| 19 | * 16-bit Basic Multilingual Plane (BMP) only. |
| 20 | * |
| 21 | * Written by Fredrik Lundh, January 1999. |
| 22 | * |
| 23 | * Copyright (c) 1999 by Secret Labs AB. |
| 24 | * Copyright (c) 1999 by Fredrik Lundh. |
| 25 | * |
| 26 | * fredrik@pythonware.com |
| 27 | * http://www.pythonware.com |
| 28 | * |
| 29 | * -------------------------------------------------------------------- |
| 30 | * This Unicode String Type is |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 31 | * |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 32 | * Copyright (c) 1999 by Secret Labs AB |
| 33 | * Copyright (c) 1999 by Fredrik Lundh |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 34 | * |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 35 | * By obtaining, using, and/or copying this software and/or its |
| 36 | * associated documentation, you agree that you have read, understood, |
| 37 | * and will comply with the following terms and conditions: |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 38 | * |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 39 | * Permission to use, copy, modify, and distribute this software and its |
| 40 | * associated documentation for any purpose and without fee is hereby |
| 41 | * granted, provided that the above copyright notice appears in all |
| 42 | * copies, and that both that copyright notice and this permission notice |
| 43 | * appear in supporting documentation, and that the name of Secret Labs |
| 44 | * AB or the author not be used in advertising or publicity pertaining to |
| 45 | * distribution of the software without specific, written prior |
| 46 | * permission. |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 47 | * |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 48 | * SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 49 | * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 50 | * FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR |
| 51 | * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 52 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 53 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 54 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 55 | * -------------------------------------------------------------------- */ |
| 56 | |
Marc-André Lemburg | 5e6007c | 2001-09-19 11:21:03 +0000 | [diff] [blame] | 57 | #include <ctype.h> |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 58 | |
| 59 | /* === Internal API ======================================================= */ |
| 60 | |
| 61 | /* --- Internal Unicode Format -------------------------------------------- */ |
| 62 | |
Christian Heimes | 0625e89 | 2008-01-07 21:04:21 +0000 | [diff] [blame] | 63 | /* Python 3.x requires unicode */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 64 | #define Py_USING_UNICODE |
Christian Heimes | 0625e89 | 2008-01-07 21:04:21 +0000 | [diff] [blame] | 65 | |
Fredrik Lundh | 9b14ab3 | 2001-06-26 22:59:49 +0000 | [diff] [blame] | 66 | /* FIXME: MvL's new implementation assumes that Py_UNICODE_SIZE is |
| 67 | properly set, but the default rules below doesn't set it. I'll |
| 68 | sort this out some other day -- fredrik@pythonware.com */ |
| 69 | |
| 70 | #ifndef Py_UNICODE_SIZE |
| 71 | #error Must define Py_UNICODE_SIZE |
| 72 | #endif |
| 73 | |
Fredrik Lundh | 8f45585 | 2001-06-27 18:59:43 +0000 | [diff] [blame] | 74 | /* Setting Py_UNICODE_WIDE enables UCS-4 storage. Otherwise, Unicode |
| 75 | strings are stored as UCS-2 (with limited support for UTF-16) */ |
| 76 | |
| 77 | #if Py_UNICODE_SIZE >= 4 |
| 78 | #define Py_UNICODE_WIDE |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 79 | #endif |
Fredrik Lundh | 1294ad0 | 2001-06-26 17:17:07 +0000 | [diff] [blame] | 80 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 81 | /* Set these flags if the platform has "wchar.h", "wctype.h" and the |
| 82 | wchar_t type is a 16-bit unsigned type */ |
| 83 | /* #define HAVE_WCHAR_H */ |
| 84 | /* #define HAVE_USABLE_WCHAR_T */ |
| 85 | |
| 86 | /* Defaults for various platforms */ |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 87 | #ifndef PY_UNICODE_TYPE |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 88 | |
Fredrik Lundh | 1294ad0 | 2001-06-26 17:17:07 +0000 | [diff] [blame] | 89 | /* Windows has a usable wchar_t type (unless we're using UCS-4) */ |
Fredrik Lundh | 8f45585 | 2001-06-27 18:59:43 +0000 | [diff] [blame] | 90 | # if defined(MS_WIN32) && Py_UNICODE_SIZE == 2 |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 91 | # define HAVE_USABLE_WCHAR_T |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 92 | # define PY_UNICODE_TYPE wchar_t |
| 93 | # endif |
| 94 | |
Fredrik Lundh | 8f45585 | 2001-06-27 18:59:43 +0000 | [diff] [blame] | 95 | # if defined(Py_UNICODE_WIDE) |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 96 | # define PY_UNICODE_TYPE Py_UCS4 |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 97 | # endif |
| 98 | |
| 99 | #endif |
| 100 | |
| 101 | /* If the compiler provides a wchar_t type we try to support it |
| 102 | through the interface functions PyUnicode_FromWideChar() and |
| 103 | PyUnicode_AsWideChar(). */ |
| 104 | |
| 105 | #ifdef HAVE_USABLE_WCHAR_T |
Marc-André Lemburg | 1a731c6 | 2000-08-11 11:43:10 +0000 | [diff] [blame] | 106 | # ifndef HAVE_WCHAR_H |
| 107 | # define HAVE_WCHAR_H |
| 108 | # endif |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 109 | #endif |
| 110 | |
| 111 | #ifdef HAVE_WCHAR_H |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 112 | /* Work around a cosmetic bug in BSDI 4.x wchar.h; thanks to Thomas Wouters */ |
| 113 | # ifdef _HAVE_BSDI |
| 114 | # include <time.h> |
| 115 | # endif |
Marc-André Lemburg | 5e6007c | 2001-09-19 11:21:03 +0000 | [diff] [blame] | 116 | # include <wchar.h> |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 117 | #endif |
| 118 | |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 119 | /* |
| 120 | * Use this typedef when you need to represent a UTF-16 surrogate pair |
| 121 | * as single unsigned integer. |
| 122 | */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 123 | #if SIZEOF_INT >= 4 |
| 124 | typedef unsigned int Py_UCS4; |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 125 | #elif SIZEOF_LONG >= 4 |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 126 | typedef unsigned long Py_UCS4; |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 127 | #endif |
| 128 | |
Benjamin Peterson | 960cf0f | 2009-01-09 04:11:44 +0000 | [diff] [blame] | 129 | /* Py_UNICODE is the native Unicode storage format (code unit) used by |
| 130 | Python and represents a single Unicode element in the Unicode |
| 131 | type. */ |
| 132 | |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 133 | typedef PY_UNICODE_TYPE Py_UNICODE; |
Marc-André Lemburg | 4327910 | 2000-07-07 09:01:41 +0000 | [diff] [blame] | 134 | |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 135 | /* --- UCS-2/UCS-4 Name Mangling ------------------------------------------ */ |
| 136 | |
| 137 | /* Unicode API names are mangled to assure that UCS-2 and UCS-4 builds |
| 138 | produce different external names and thus cause import errors in |
| 139 | case Python interpreters and extensions with mixed compiled in |
| 140 | Unicode width assumptions are combined. */ |
| 141 | |
| 142 | #ifndef Py_UNICODE_WIDE |
| 143 | |
| 144 | # define PyUnicode_AsASCIIString PyUnicodeUCS2_AsASCIIString |
| 145 | # define PyUnicode_AsCharmapString PyUnicodeUCS2_AsCharmapString |
Marc-André Lemburg | b2750b5 | 2008-06-06 12:18:17 +0000 | [diff] [blame] | 146 | # define PyUnicode_AsDecodedObject PyUnicodeUCS2_AsDecodedObject |
| 147 | # define PyUnicode_AsDecodedUnicode PyUnicodeUCS2_AsDecodedUnicode |
Marc-André Lemburg | d2d4598 | 2004-07-08 17:57:32 +0000 | [diff] [blame] | 148 | # define PyUnicode_AsEncodedObject PyUnicodeUCS2_AsEncodedObject |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 149 | # define PyUnicode_AsEncodedString PyUnicodeUCS2_AsEncodedString |
Marc-André Lemburg | b2750b5 | 2008-06-06 12:18:17 +0000 | [diff] [blame] | 150 | # define PyUnicode_AsEncodedUnicode PyUnicodeUCS2_AsEncodedUnicode |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 151 | # define PyUnicode_AsLatin1String PyUnicodeUCS2_AsLatin1String |
| 152 | # define PyUnicode_AsRawUnicodeEscapeString PyUnicodeUCS2_AsRawUnicodeEscapeString |
Walter Dörwald | 41980ca | 2007-08-16 21:55:45 +0000 | [diff] [blame] | 153 | # define PyUnicode_AsUTF32String PyUnicodeUCS2_AsUTF32String |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 154 | # define PyUnicode_AsUTF16String PyUnicodeUCS2_AsUTF16String |
| 155 | # define PyUnicode_AsUTF8String PyUnicodeUCS2_AsUTF8String |
| 156 | # define PyUnicode_AsUnicode PyUnicodeUCS2_AsUnicode |
| 157 | # define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS2_AsUnicodeEscapeString |
| 158 | # define PyUnicode_AsWideChar PyUnicodeUCS2_AsWideChar |
Alexandre Vassalotti | 15fafbe | 2008-12-28 02:13:22 +0000 | [diff] [blame] | 159 | # define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 160 | # define PyUnicode_Compare PyUnicodeUCS2_Compare |
Benjamin Peterson | ad465f9 | 2010-05-07 20:21:26 +0000 | [diff] [blame] | 161 | # define PyUnicode_CompareWithASCII PyUnicodeUCS2_CompareASCII |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 162 | # define PyUnicode_Concat PyUnicodeUCS2_Concat |
Walter Dörwald | 1ab8330 | 2007-05-18 17:15:44 +0000 | [diff] [blame] | 163 | # define PyUnicode_Append PyUnicodeUCS2_Append |
| 164 | # define PyUnicode_AppendAndDel PyUnicodeUCS2_AppendAndDel |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 165 | # define PyUnicode_Contains PyUnicodeUCS2_Contains |
| 166 | # define PyUnicode_Count PyUnicodeUCS2_Count |
| 167 | # define PyUnicode_Decode PyUnicodeUCS2_Decode |
| 168 | # define PyUnicode_DecodeASCII PyUnicodeUCS2_DecodeASCII |
| 169 | # define PyUnicode_DecodeCharmap PyUnicodeUCS2_DecodeCharmap |
| 170 | # define PyUnicode_DecodeLatin1 PyUnicodeUCS2_DecodeLatin1 |
Guido van Rossum | 00bc0e0 | 2007-10-15 02:52:41 +0000 | [diff] [blame] | 171 | # define PyUnicode_DecodeFSDefault PyUnicodeUCS2_DecodeFSDefault |
Christian Heimes | 5894ba7 | 2007-11-04 11:43:14 +0000 | [diff] [blame] | 172 | # define PyUnicode_DecodeFSDefaultAndSize PyUnicodeUCS2_DecodeFSDefaultAndSize |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 173 | # define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS2_DecodeRawUnicodeEscape |
Walter Dörwald | 41980ca | 2007-08-16 21:55:45 +0000 | [diff] [blame] | 174 | # define PyUnicode_DecodeUTF32 PyUnicodeUCS2_DecodeUTF32 |
| 175 | # define PyUnicode_DecodeUTF32Stateful PyUnicodeUCS2_DecodeUTF32Stateful |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 176 | # define PyUnicode_DecodeUTF16 PyUnicodeUCS2_DecodeUTF16 |
Walter Dörwald | 6965203 | 2004-09-07 20:24:22 +0000 | [diff] [blame] | 177 | # define PyUnicode_DecodeUTF16Stateful PyUnicodeUCS2_DecodeUTF16Stateful |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 178 | # define PyUnicode_DecodeUTF8 PyUnicodeUCS2_DecodeUTF8 |
Walter Dörwald | 6965203 | 2004-09-07 20:24:22 +0000 | [diff] [blame] | 179 | # define PyUnicode_DecodeUTF8Stateful PyUnicodeUCS2_DecodeUTF8Stateful |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 180 | # define PyUnicode_DecodeUnicodeEscape PyUnicodeUCS2_DecodeUnicodeEscape |
| 181 | # define PyUnicode_Encode PyUnicodeUCS2_Encode |
| 182 | # define PyUnicode_EncodeASCII PyUnicodeUCS2_EncodeASCII |
| 183 | # define PyUnicode_EncodeCharmap PyUnicodeUCS2_EncodeCharmap |
| 184 | # define PyUnicode_EncodeDecimal PyUnicodeUCS2_EncodeDecimal |
| 185 | # define PyUnicode_EncodeLatin1 PyUnicodeUCS2_EncodeLatin1 |
| 186 | # define PyUnicode_EncodeRawUnicodeEscape PyUnicodeUCS2_EncodeRawUnicodeEscape |
Walter Dörwald | 41980ca | 2007-08-16 21:55:45 +0000 | [diff] [blame] | 187 | # define PyUnicode_EncodeUTF32 PyUnicodeUCS2_EncodeUTF32 |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 188 | # define PyUnicode_EncodeUTF16 PyUnicodeUCS2_EncodeUTF16 |
| 189 | # define PyUnicode_EncodeUTF8 PyUnicodeUCS2_EncodeUTF8 |
| 190 | # define PyUnicode_EncodeUnicodeEscape PyUnicodeUCS2_EncodeUnicodeEscape |
| 191 | # define PyUnicode_Find PyUnicodeUCS2_Find |
| 192 | # define PyUnicode_Format PyUnicodeUCS2_Format |
| 193 | # define PyUnicode_FromEncodedObject PyUnicodeUCS2_FromEncodedObject |
Alexandre Vassalotti | 15fafbe | 2008-12-28 02:13:22 +0000 | [diff] [blame] | 194 | # define PyUnicode_FromFormat PyUnicodeUCS2_FromFormat |
| 195 | # define PyUnicode_FromFormatV PyUnicodeUCS2_FromFormatV |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 196 | # define PyUnicode_FromObject PyUnicodeUCS2_FromObject |
Marc-André Lemburg | 9c329de | 2002-08-12 08:19:10 +0000 | [diff] [blame] | 197 | # define PyUnicode_FromOrdinal PyUnicodeUCS2_FromOrdinal |
Walter Dörwald | acaa5a1 | 2007-05-05 12:00:46 +0000 | [diff] [blame] | 198 | # define PyUnicode_FromString PyUnicodeUCS2_FromString |
Walter Dörwald | d203431 | 2007-05-18 16:29:38 +0000 | [diff] [blame] | 199 | # define PyUnicode_FromStringAndSize PyUnicodeUCS2_FromStringAndSize |
Alexandre Vassalotti | 15fafbe | 2008-12-28 02:13:22 +0000 | [diff] [blame] | 200 | # define PyUnicode_FromUnicode PyUnicodeUCS2_FromUnicode |
Walter Dörwald | 14176a5 | 2007-05-18 17:04:42 +0000 | [diff] [blame] | 201 | # define PyUnicode_FromWideChar PyUnicodeUCS2_FromWideChar |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 202 | # define PyUnicode_FSConverter PyUnicodeUCS2_FSConverter |
Victor Stinner | 47fcb5b | 2010-08-13 23:59:58 +0000 | [diff] [blame] | 203 | # define PyUnicode_FSDecoder PyUnicodeUCS2_FSDecoder |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 204 | # define PyUnicode_GetDefaultEncoding PyUnicodeUCS2_GetDefaultEncoding |
| 205 | # define PyUnicode_GetMax PyUnicodeUCS2_GetMax |
| 206 | # define PyUnicode_GetSize PyUnicodeUCS2_GetSize |
Martin v. Löwis | 4738340 | 2007-08-15 07:32:56 +0000 | [diff] [blame] | 207 | # define PyUnicode_IsIdentifier PyUnicodeUCS2_IsIdentifier |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 208 | # define PyUnicode_Join PyUnicodeUCS2_Join |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 209 | # define PyUnicode_Partition PyUnicodeUCS2_Partition |
| 210 | # define PyUnicode_RPartition PyUnicodeUCS2_RPartition |
| 211 | # define PyUnicode_RSplit PyUnicodeUCS2_RSplit |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 212 | # define PyUnicode_Replace PyUnicodeUCS2_Replace |
| 213 | # define PyUnicode_Resize PyUnicodeUCS2_Resize |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 214 | # define PyUnicode_RichCompare PyUnicodeUCS2_RichCompare |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 215 | # define PyUnicode_SetDefaultEncoding PyUnicodeUCS2_SetDefaultEncoding |
| 216 | # define PyUnicode_Split PyUnicodeUCS2_Split |
| 217 | # define PyUnicode_Splitlines PyUnicodeUCS2_Splitlines |
| 218 | # define PyUnicode_Tailmatch PyUnicodeUCS2_Tailmatch |
| 219 | # define PyUnicode_Translate PyUnicodeUCS2_Translate |
| 220 | # define PyUnicode_TranslateCharmap PyUnicodeUCS2_TranslateCharmap |
| 221 | # define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS2_AsDefaultEncodedString |
| 222 | # define _PyUnicode_Fini _PyUnicodeUCS2_Fini |
| 223 | # define _PyUnicode_Init _PyUnicodeUCS2_Init |
| 224 | # define _PyUnicode_IsAlpha _PyUnicodeUCS2_IsAlpha |
| 225 | # define _PyUnicode_IsDecimalDigit _PyUnicodeUCS2_IsDecimalDigit |
| 226 | # define _PyUnicode_IsDigit _PyUnicodeUCS2_IsDigit |
| 227 | # define _PyUnicode_IsLinebreak _PyUnicodeUCS2_IsLinebreak |
| 228 | # define _PyUnicode_IsLowercase _PyUnicodeUCS2_IsLowercase |
| 229 | # define _PyUnicode_IsNumeric _PyUnicodeUCS2_IsNumeric |
Georg Brandl | 559e5d7 | 2008-06-11 18:37:52 +0000 | [diff] [blame] | 230 | # define _PyUnicode_IsPrintable _PyUnicodeUCS2_IsPrintable |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 231 | # define _PyUnicode_IsTitlecase _PyUnicodeUCS2_IsTitlecase |
Martin v. Löwis | 13c3e38 | 2007-08-14 22:37:03 +0000 | [diff] [blame] | 232 | # define _PyUnicode_IsXidStart _PyUnicodeUCS2_IsXidStart |
| 233 | # define _PyUnicode_IsXidContinue _PyUnicodeUCS2_IsXidContinue |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 234 | # define _PyUnicode_IsUppercase _PyUnicodeUCS2_IsUppercase |
| 235 | # define _PyUnicode_IsWhitespace _PyUnicodeUCS2_IsWhitespace |
| 236 | # define _PyUnicode_ToDecimalDigit _PyUnicodeUCS2_ToDecimalDigit |
| 237 | # define _PyUnicode_ToDigit _PyUnicodeUCS2_ToDigit |
| 238 | # define _PyUnicode_ToLowercase _PyUnicodeUCS2_ToLowercase |
| 239 | # define _PyUnicode_ToNumeric _PyUnicodeUCS2_ToNumeric |
| 240 | # define _PyUnicode_ToTitlecase _PyUnicodeUCS2_ToTitlecase |
| 241 | # define _PyUnicode_ToUppercase _PyUnicodeUCS2_ToUppercase |
| 242 | |
| 243 | #else |
| 244 | |
| 245 | # define PyUnicode_AsASCIIString PyUnicodeUCS4_AsASCIIString |
| 246 | # define PyUnicode_AsCharmapString PyUnicodeUCS4_AsCharmapString |
Marc-André Lemburg | b2750b5 | 2008-06-06 12:18:17 +0000 | [diff] [blame] | 247 | # define PyUnicode_AsDecodedObject PyUnicodeUCS4_AsDecodedObject |
| 248 | # define PyUnicode_AsDecodedUnicode PyUnicodeUCS4_AsDecodedUnicode |
Marc-André Lemburg | d2d4598 | 2004-07-08 17:57:32 +0000 | [diff] [blame] | 249 | # define PyUnicode_AsEncodedObject PyUnicodeUCS4_AsEncodedObject |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 250 | # define PyUnicode_AsEncodedString PyUnicodeUCS4_AsEncodedString |
Marc-André Lemburg | b2750b5 | 2008-06-06 12:18:17 +0000 | [diff] [blame] | 251 | # define PyUnicode_AsEncodedUnicode PyUnicodeUCS4_AsEncodedUnicode |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 252 | # define PyUnicode_AsLatin1String PyUnicodeUCS4_AsLatin1String |
| 253 | # define PyUnicode_AsRawUnicodeEscapeString PyUnicodeUCS4_AsRawUnicodeEscapeString |
Walter Dörwald | 41980ca | 2007-08-16 21:55:45 +0000 | [diff] [blame] | 254 | # define PyUnicode_AsUTF32String PyUnicodeUCS4_AsUTF32String |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 255 | # define PyUnicode_AsUTF16String PyUnicodeUCS4_AsUTF16String |
| 256 | # define PyUnicode_AsUTF8String PyUnicodeUCS4_AsUTF8String |
| 257 | # define PyUnicode_AsUnicode PyUnicodeUCS4_AsUnicode |
| 258 | # define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS4_AsUnicodeEscapeString |
| 259 | # define PyUnicode_AsWideChar PyUnicodeUCS4_AsWideChar |
Alexandre Vassalotti | 15fafbe | 2008-12-28 02:13:22 +0000 | [diff] [blame] | 260 | # define PyUnicode_ClearFreeList PyUnicodeUCS4_ClearFreelist |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 261 | # define PyUnicode_Compare PyUnicodeUCS4_Compare |
Benjamin Peterson | ad465f9 | 2010-05-07 20:21:26 +0000 | [diff] [blame] | 262 | # define PyUnicode_CompareWithASCII PyUnicodeUCS4_CompareWithASCII |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 263 | # define PyUnicode_Concat PyUnicodeUCS4_Concat |
Walter Dörwald | 1ab8330 | 2007-05-18 17:15:44 +0000 | [diff] [blame] | 264 | # define PyUnicode_Append PyUnicodeUCS4_Append |
| 265 | # define PyUnicode_AppendAndDel PyUnicodeUCS4_AppendAndDel |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 266 | # define PyUnicode_Contains PyUnicodeUCS4_Contains |
| 267 | # define PyUnicode_Count PyUnicodeUCS4_Count |
| 268 | # define PyUnicode_Decode PyUnicodeUCS4_Decode |
| 269 | # define PyUnicode_DecodeASCII PyUnicodeUCS4_DecodeASCII |
| 270 | # define PyUnicode_DecodeCharmap PyUnicodeUCS4_DecodeCharmap |
| 271 | # define PyUnicode_DecodeLatin1 PyUnicodeUCS4_DecodeLatin1 |
Guido van Rossum | 00bc0e0 | 2007-10-15 02:52:41 +0000 | [diff] [blame] | 272 | # define PyUnicode_DecodeFSDefault PyUnicodeUCS4_DecodeFSDefault |
Christian Heimes | 5894ba7 | 2007-11-04 11:43:14 +0000 | [diff] [blame] | 273 | # define PyUnicode_DecodeFSDefaultAndSize PyUnicodeUCS4_DecodeFSDefaultAndSize |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 274 | # define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS4_DecodeRawUnicodeEscape |
Walter Dörwald | 41980ca | 2007-08-16 21:55:45 +0000 | [diff] [blame] | 275 | # define PyUnicode_DecodeUTF32 PyUnicodeUCS4_DecodeUTF32 |
| 276 | # define PyUnicode_DecodeUTF32Stateful PyUnicodeUCS4_DecodeUTF32Stateful |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 277 | # define PyUnicode_DecodeUTF16 PyUnicodeUCS4_DecodeUTF16 |
Walter Dörwald | 6965203 | 2004-09-07 20:24:22 +0000 | [diff] [blame] | 278 | # define PyUnicode_DecodeUTF16Stateful PyUnicodeUCS4_DecodeUTF16Stateful |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 279 | # define PyUnicode_DecodeUTF8 PyUnicodeUCS4_DecodeUTF8 |
Walter Dörwald | 6965203 | 2004-09-07 20:24:22 +0000 | [diff] [blame] | 280 | # define PyUnicode_DecodeUTF8Stateful PyUnicodeUCS4_DecodeUTF8Stateful |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 281 | # define PyUnicode_DecodeUnicodeEscape PyUnicodeUCS4_DecodeUnicodeEscape |
| 282 | # define PyUnicode_Encode PyUnicodeUCS4_Encode |
| 283 | # define PyUnicode_EncodeASCII PyUnicodeUCS4_EncodeASCII |
| 284 | # define PyUnicode_EncodeCharmap PyUnicodeUCS4_EncodeCharmap |
| 285 | # define PyUnicode_EncodeDecimal PyUnicodeUCS4_EncodeDecimal |
| 286 | # define PyUnicode_EncodeLatin1 PyUnicodeUCS4_EncodeLatin1 |
| 287 | # define PyUnicode_EncodeRawUnicodeEscape PyUnicodeUCS4_EncodeRawUnicodeEscape |
Walter Dörwald | 41980ca | 2007-08-16 21:55:45 +0000 | [diff] [blame] | 288 | # define PyUnicode_EncodeUTF32 PyUnicodeUCS4_EncodeUTF32 |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 289 | # define PyUnicode_EncodeUTF16 PyUnicodeUCS4_EncodeUTF16 |
| 290 | # define PyUnicode_EncodeUTF8 PyUnicodeUCS4_EncodeUTF8 |
| 291 | # define PyUnicode_EncodeUnicodeEscape PyUnicodeUCS4_EncodeUnicodeEscape |
| 292 | # define PyUnicode_Find PyUnicodeUCS4_Find |
| 293 | # define PyUnicode_Format PyUnicodeUCS4_Format |
| 294 | # define PyUnicode_FromEncodedObject PyUnicodeUCS4_FromEncodedObject |
Alexandre Vassalotti | 15fafbe | 2008-12-28 02:13:22 +0000 | [diff] [blame] | 295 | # define PyUnicode_FromFormat PyUnicodeUCS4_FromFormat |
| 296 | # define PyUnicode_FromFormatV PyUnicodeUCS4_FromFormatV |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 297 | # define PyUnicode_FromObject PyUnicodeUCS4_FromObject |
Marc-André Lemburg | 9c329de | 2002-08-12 08:19:10 +0000 | [diff] [blame] | 298 | # define PyUnicode_FromOrdinal PyUnicodeUCS4_FromOrdinal |
Walter Dörwald | acaa5a1 | 2007-05-05 12:00:46 +0000 | [diff] [blame] | 299 | # define PyUnicode_FromString PyUnicodeUCS4_FromString |
Walter Dörwald | d203431 | 2007-05-18 16:29:38 +0000 | [diff] [blame] | 300 | # define PyUnicode_FromStringAndSize PyUnicodeUCS4_FromStringAndSize |
Alexandre Vassalotti | 15fafbe | 2008-12-28 02:13:22 +0000 | [diff] [blame] | 301 | # define PyUnicode_FromUnicode PyUnicodeUCS4_FromUnicode |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 302 | # define PyUnicode_FromWideChar PyUnicodeUCS4_FromWideChar |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 303 | # define PyUnicode_FSConverter PyUnicodeUCS4_FSConverter |
Victor Stinner | 47fcb5b | 2010-08-13 23:59:58 +0000 | [diff] [blame] | 304 | # define PyUnicode_FSDecoder PyUnicodeUCS4_FSDecoder |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 305 | # define PyUnicode_GetDefaultEncoding PyUnicodeUCS4_GetDefaultEncoding |
| 306 | # define PyUnicode_GetMax PyUnicodeUCS4_GetMax |
| 307 | # define PyUnicode_GetSize PyUnicodeUCS4_GetSize |
Martin v. Löwis | 4738340 | 2007-08-15 07:32:56 +0000 | [diff] [blame] | 308 | # define PyUnicode_IsIdentifier PyUnicodeUCS4_IsIdentifier |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 309 | # define PyUnicode_Join PyUnicodeUCS4_Join |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 310 | # define PyUnicode_Partition PyUnicodeUCS4_Partition |
| 311 | # define PyUnicode_RPartition PyUnicodeUCS4_RPartition |
| 312 | # define PyUnicode_RSplit PyUnicodeUCS4_RSplit |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 313 | # define PyUnicode_Replace PyUnicodeUCS4_Replace |
| 314 | # define PyUnicode_Resize PyUnicodeUCS4_Resize |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 315 | # define PyUnicode_RichCompare PyUnicodeUCS4_RichCompare |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 316 | # define PyUnicode_SetDefaultEncoding PyUnicodeUCS4_SetDefaultEncoding |
| 317 | # define PyUnicode_Split PyUnicodeUCS4_Split |
| 318 | # define PyUnicode_Splitlines PyUnicodeUCS4_Splitlines |
| 319 | # define PyUnicode_Tailmatch PyUnicodeUCS4_Tailmatch |
| 320 | # define PyUnicode_Translate PyUnicodeUCS4_Translate |
| 321 | # define PyUnicode_TranslateCharmap PyUnicodeUCS4_TranslateCharmap |
| 322 | # define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS4_AsDefaultEncodedString |
| 323 | # define _PyUnicode_Fini _PyUnicodeUCS4_Fini |
| 324 | # define _PyUnicode_Init _PyUnicodeUCS4_Init |
| 325 | # define _PyUnicode_IsAlpha _PyUnicodeUCS4_IsAlpha |
| 326 | # define _PyUnicode_IsDecimalDigit _PyUnicodeUCS4_IsDecimalDigit |
| 327 | # define _PyUnicode_IsDigit _PyUnicodeUCS4_IsDigit |
| 328 | # define _PyUnicode_IsLinebreak _PyUnicodeUCS4_IsLinebreak |
| 329 | # define _PyUnicode_IsLowercase _PyUnicodeUCS4_IsLowercase |
| 330 | # define _PyUnicode_IsNumeric _PyUnicodeUCS4_IsNumeric |
Georg Brandl | 559e5d7 | 2008-06-11 18:37:52 +0000 | [diff] [blame] | 331 | # define _PyUnicode_IsPrintable _PyUnicodeUCS4_IsPrintable |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 332 | # define _PyUnicode_IsTitlecase _PyUnicodeUCS4_IsTitlecase |
Martin v. Löwis | 13c3e38 | 2007-08-14 22:37:03 +0000 | [diff] [blame] | 333 | # define _PyUnicode_IsXidStart _PyUnicodeUCS4_IsXidStart |
| 334 | # define _PyUnicode_IsXidContinue _PyUnicodeUCS4_IsXidContinue |
Marc-André Lemburg | b5ac6f6 | 2001-07-31 14:30:16 +0000 | [diff] [blame] | 335 | # define _PyUnicode_IsUppercase _PyUnicodeUCS4_IsUppercase |
| 336 | # define _PyUnicode_IsWhitespace _PyUnicodeUCS4_IsWhitespace |
| 337 | # define _PyUnicode_ToDecimalDigit _PyUnicodeUCS4_ToDecimalDigit |
| 338 | # define _PyUnicode_ToDigit _PyUnicodeUCS4_ToDigit |
| 339 | # define _PyUnicode_ToLowercase _PyUnicodeUCS4_ToLowercase |
| 340 | # define _PyUnicode_ToNumeric _PyUnicodeUCS4_ToNumeric |
| 341 | # define _PyUnicode_ToTitlecase _PyUnicodeUCS4_ToTitlecase |
| 342 | # define _PyUnicode_ToUppercase _PyUnicodeUCS4_ToUppercase |
| 343 | |
| 344 | |
| 345 | #endif |
| 346 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 347 | /* --- Internal Unicode Operations ---------------------------------------- */ |
| 348 | |
| 349 | /* If you want Python to use the compiler's wctype.h functions instead |
Barry Warsaw | 51ac580 | 2000-03-20 16:36:48 +0000 | [diff] [blame] | 350 | of the ones supplied with Python, define WANT_WCTYPE_FUNCTIONS or |
Raymond Hettinger | 57341c3 | 2004-10-31 05:46:59 +0000 | [diff] [blame] | 351 | configure Python using --with-wctype-functions. This reduces the |
Barry Warsaw | 51ac580 | 2000-03-20 16:36:48 +0000 | [diff] [blame] | 352 | interpreter's code size. */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 353 | |
| 354 | #if defined(HAVE_USABLE_WCHAR_T) && defined(WANT_WCTYPE_FUNCTIONS) |
| 355 | |
Marc-André Lemburg | 5e6007c | 2001-09-19 11:21:03 +0000 | [diff] [blame] | 356 | #include <wctype.h> |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 357 | |
| 358 | #define Py_UNICODE_ISSPACE(ch) iswspace(ch) |
| 359 | |
| 360 | #define Py_UNICODE_ISLOWER(ch) iswlower(ch) |
| 361 | #define Py_UNICODE_ISUPPER(ch) iswupper(ch) |
| 362 | #define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch) |
| 363 | #define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch) |
| 364 | |
| 365 | #define Py_UNICODE_TOLOWER(ch) towlower(ch) |
| 366 | #define Py_UNICODE_TOUPPER(ch) towupper(ch) |
| 367 | #define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch) |
| 368 | |
| 369 | #define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch) |
| 370 | #define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch) |
| 371 | #define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch) |
Georg Brandl | 559e5d7 | 2008-06-11 18:37:52 +0000 | [diff] [blame] | 372 | #define Py_UNICODE_ISPRINTABLE(ch) _PyUnicode_IsPrintable(ch) |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 373 | |
| 374 | #define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch) |
| 375 | #define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch) |
| 376 | #define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch) |
| 377 | |
Marc-André Lemburg | f03e741 | 2000-07-05 09:45:59 +0000 | [diff] [blame] | 378 | #define Py_UNICODE_ISALPHA(ch) iswalpha(ch) |
| 379 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 380 | #else |
| 381 | |
Benjamin Peterson | 960cf0f | 2009-01-09 04:11:44 +0000 | [diff] [blame] | 382 | /* Since splitting on whitespace is an important use case, and |
| 383 | whitespace in most situations is solely ASCII whitespace, we |
| 384 | optimize for the common case by using a quick look-up table |
| 385 | _Py_ascii_whitespace (see below) with an inlined check. |
Christian Heimes | 190d79e | 2008-01-30 11:58:22 +0000 | [diff] [blame] | 386 | |
Benjamin Peterson | 960cf0f | 2009-01-09 04:11:44 +0000 | [diff] [blame] | 387 | */ |
Christian Heimes | 190d79e | 2008-01-30 11:58:22 +0000 | [diff] [blame] | 388 | #define Py_UNICODE_ISSPACE(ch) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 389 | ((ch) < 128U ? _Py_ascii_whitespace[(ch)] : _PyUnicode_IsWhitespace(ch)) |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 390 | |
| 391 | #define Py_UNICODE_ISLOWER(ch) _PyUnicode_IsLowercase(ch) |
| 392 | #define Py_UNICODE_ISUPPER(ch) _PyUnicode_IsUppercase(ch) |
| 393 | #define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch) |
| 394 | #define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch) |
| 395 | |
| 396 | #define Py_UNICODE_TOLOWER(ch) _PyUnicode_ToLowercase(ch) |
| 397 | #define Py_UNICODE_TOUPPER(ch) _PyUnicode_ToUppercase(ch) |
| 398 | #define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch) |
| 399 | |
| 400 | #define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch) |
| 401 | #define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch) |
| 402 | #define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch) |
Georg Brandl | 559e5d7 | 2008-06-11 18:37:52 +0000 | [diff] [blame] | 403 | #define Py_UNICODE_ISPRINTABLE(ch) _PyUnicode_IsPrintable(ch) |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 404 | |
| 405 | #define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch) |
| 406 | #define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch) |
| 407 | #define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch) |
| 408 | |
Marc-André Lemburg | f03e741 | 2000-07-05 09:45:59 +0000 | [diff] [blame] | 409 | #define Py_UNICODE_ISALPHA(ch) _PyUnicode_IsAlpha(ch) |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 410 | |
Marc-André Lemburg | f03e741 | 2000-07-05 09:45:59 +0000 | [diff] [blame] | 411 | #endif |
Marc-André Lemburg | a9c103b | 2000-07-03 10:52:13 +0000 | [diff] [blame] | 412 | |
| 413 | #define Py_UNICODE_ISALNUM(ch) \ |
| 414 | (Py_UNICODE_ISALPHA(ch) || \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 415 | Py_UNICODE_ISDECIMAL(ch) || \ |
| 416 | Py_UNICODE_ISDIGIT(ch) || \ |
| 417 | Py_UNICODE_ISNUMERIC(ch)) |
Marc-André Lemburg | a9c103b | 2000-07-03 10:52:13 +0000 | [diff] [blame] | 418 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 419 | #define Py_UNICODE_COPY(target, source, length) \ |
| 420 | Py_MEMCPY((target), (source), (length)*sizeof(Py_UNICODE)) |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 421 | |
Benjamin Peterson | 960cf0f | 2009-01-09 04:11:44 +0000 | [diff] [blame] | 422 | #define Py_UNICODE_FILL(target, value, length) \ |
| 423 | do {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 424 | for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\ |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 425 | } while (0) |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 426 | |
Benjamin Peterson | 960cf0f | 2009-01-09 04:11:44 +0000 | [diff] [blame] | 427 | /* Check if substring matches at given offset. the offset must be |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 428 | valid, and the substring must not be empty */ |
Benjamin Peterson | 960cf0f | 2009-01-09 04:11:44 +0000 | [diff] [blame] | 429 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 430 | #define Py_UNICODE_MATCH(string, offset, substring) \ |
| 431 | ((*((string)->str + (offset)) == *((substring)->str)) && \ |
| 432 | ((*((string)->str + (offset) + (substring)->length-1) == *((substring)->str + (substring)->length-1))) && \ |
| 433 | !memcmp((string)->str + (offset), (substring)->str, (substring)->length*sizeof(Py_UNICODE))) |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 434 | |
Barry Warsaw | 51ac580 | 2000-03-20 16:36:48 +0000 | [diff] [blame] | 435 | #ifdef __cplusplus |
| 436 | extern "C" { |
| 437 | #endif |
| 438 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 439 | /* --- Unicode Type ------------------------------------------------------- */ |
| 440 | |
| 441 | typedef struct { |
| 442 | PyObject_HEAD |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 443 | Py_ssize_t length; /* Length of raw Unicode data in buffer */ |
| 444 | Py_UNICODE *str; /* Raw Unicode buffer */ |
| 445 | long hash; /* Hash value; -1 if not set */ |
| 446 | int state; /* != 0 if interned. In this case the two |
| 447 | * references from the dictionary to this object |
| 448 | * are *not* counted in ob_refcnt. */ |
| 449 | PyObject *defenc; /* (Default) Encoded version as Python |
| 450 | string, or NULL; this is used for |
| 451 | implementing the buffer protocol */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 452 | } PyUnicodeObject; |
| 453 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 454 | PyAPI_DATA(PyTypeObject) PyUnicode_Type; |
Christian Heimes | a22e8bd | 2007-11-29 22:35:39 +0000 | [diff] [blame] | 455 | PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type; |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 456 | |
Walter Dörwald | 1680713 | 2007-05-25 13:52:07 +0000 | [diff] [blame] | 457 | #define SSTATE_NOT_INTERNED 0 |
| 458 | #define SSTATE_INTERNED_MORTAL 1 |
| 459 | #define SSTATE_INTERNED_IMMORTAL 2 |
| 460 | |
Thomas Wouters | 27d517b | 2007-02-25 20:39:11 +0000 | [diff] [blame] | 461 | #define PyUnicode_Check(op) \ |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 462 | PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) |
| 463 | #define PyUnicode_CheckExact(op) (Py_TYPE(op) == &PyUnicode_Type) |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 464 | |
| 465 | /* Fast access macros */ |
| 466 | #define PyUnicode_GET_SIZE(op) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 467 | (assert(PyUnicode_Check(op)),(((PyUnicodeObject *)(op))->length)) |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 468 | #define PyUnicode_GET_DATA_SIZE(op) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 469 | (assert(PyUnicode_Check(op)),(((PyUnicodeObject *)(op))->length * sizeof(Py_UNICODE))) |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 470 | #define PyUnicode_AS_UNICODE(op) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 471 | (assert(PyUnicode_Check(op)),(((PyUnicodeObject *)(op))->str)) |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 472 | #define PyUnicode_AS_DATA(op) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 473 | (assert(PyUnicode_Check(op)),((const char *)((PyUnicodeObject *)(op))->str)) |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 474 | |
| 475 | /* --- Constants ---------------------------------------------------------- */ |
| 476 | |
| 477 | /* This Unicode character will be used as replacement character during |
| 478 | decoding if the errors argument is set to "replace". Note: the |
| 479 | Unicode character U+FFFD is the official REPLACEMENT CHARACTER in |
| 480 | Unicode 3.0. */ |
| 481 | |
| 482 | #define Py_UNICODE_REPLACEMENT_CHARACTER ((Py_UNICODE) 0xFFFD) |
| 483 | |
| 484 | /* === Public API ========================================================= */ |
| 485 | |
| 486 | /* --- Plain Py_UNICODE --------------------------------------------------- */ |
| 487 | |
| 488 | /* Create a Unicode Object from the Py_UNICODE buffer u of the given |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 489 | size. |
Marc-André Lemburg | 8155e0e | 2001-04-23 14:44:21 +0000 | [diff] [blame] | 490 | |
| 491 | u may be NULL which causes the contents to be undefined. It is the |
| 492 | user's responsibility to fill in the needed data afterwards. Note |
| 493 | that modifying the Unicode object contents after construction is |
| 494 | only allowed if u was set to NULL. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 495 | |
| 496 | The buffer is copied into the new object. */ |
| 497 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 498 | PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode( |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 499 | const Py_UNICODE *u, /* Unicode buffer */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 500 | Py_ssize_t size /* size of buffer */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 501 | ); |
| 502 | |
Georg Brandl | 952867a | 2010-06-27 10:17:12 +0000 | [diff] [blame] | 503 | /* Similar to PyUnicode_FromUnicode(), but u points to UTF-8 encoded bytes */ |
Walter Dörwald | d203431 | 2007-05-18 16:29:38 +0000 | [diff] [blame] | 504 | PyAPI_FUNC(PyObject*) PyUnicode_FromStringAndSize( |
| 505 | const char *u, /* char buffer */ |
| 506 | Py_ssize_t size /* size of buffer */ |
| 507 | ); |
| 508 | |
Walter Dörwald | acaa5a1 | 2007-05-05 12:00:46 +0000 | [diff] [blame] | 509 | /* Similar to PyUnicode_FromUnicode(), but u points to null-terminated |
Georg Brandl | 952867a | 2010-06-27 10:17:12 +0000 | [diff] [blame] | 510 | UTF-8 encoded bytes */ |
Walter Dörwald | acaa5a1 | 2007-05-05 12:00:46 +0000 | [diff] [blame] | 511 | PyAPI_FUNC(PyObject*) PyUnicode_FromString( |
| 512 | const char *u /* string */ |
| 513 | ); |
| 514 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 515 | /* Return a read-only pointer to the Unicode object's internal |
| 516 | Py_UNICODE buffer. */ |
| 517 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 518 | PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 519 | PyObject *unicode /* Unicode object */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 520 | ); |
| 521 | |
| 522 | /* Get the length of the Unicode object. */ |
| 523 | |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 524 | PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 525 | PyObject *unicode /* Unicode object */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 526 | ); |
| 527 | |
Martin v. Löwis | ce9b5a5 | 2001-06-27 06:28:56 +0000 | [diff] [blame] | 528 | /* Get the maximum ordinal for a Unicode character. */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 529 | PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void); |
Martin v. Löwis | ce9b5a5 | 2001-06-27 06:28:56 +0000 | [diff] [blame] | 530 | |
Guido van Rossum | 52c2359 | 2000-04-10 13:41:41 +0000 | [diff] [blame] | 531 | /* Resize an already allocated Unicode object to the new size length. |
| 532 | |
| 533 | *unicode is modified to point to the new (resized) object and 0 |
| 534 | returned on success. |
| 535 | |
| 536 | This API may only be called by the function which also called the |
| 537 | Unicode constructor. The refcount on the object must be 1. Otherwise, |
| 538 | an error is returned. |
| 539 | |
| 540 | Error handling is implemented as follows: an exception is set, -1 |
| 541 | is returned and *unicode left untouched. |
| 542 | |
| 543 | */ |
| 544 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 545 | PyAPI_FUNC(int) PyUnicode_Resize( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 546 | PyObject **unicode, /* Pointer to the Unicode object */ |
| 547 | Py_ssize_t length /* New length */ |
Guido van Rossum | 52c2359 | 2000-04-10 13:41:41 +0000 | [diff] [blame] | 548 | ); |
| 549 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 550 | /* Coerce obj to an Unicode object and return a reference with |
| 551 | *incremented* refcount. |
| 552 | |
| 553 | Coercion is done in the following way: |
| 554 | |
Georg Brandl | 952867a | 2010-06-27 10:17:12 +0000 | [diff] [blame] | 555 | 1. bytes, bytearray and other char buffer compatible objects are decoded |
Fred Drake | cb093fe | 2000-05-09 19:51:53 +0000 | [diff] [blame] | 556 | under the assumptions that they contain data using the current |
| 557 | default encoding. Decoding is done in "strict" mode. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 558 | |
Guido van Rossum | b8c65bc | 2001-10-19 02:01:31 +0000 | [diff] [blame] | 559 | 2. All other objects (including Unicode objects) raise an |
| 560 | exception. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 561 | |
| 562 | The API returns NULL in case of an error. The caller is responsible |
| 563 | for decref'ing the returned objects. |
| 564 | |
| 565 | */ |
| 566 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 567 | PyAPI_FUNC(PyObject*) PyUnicode_FromEncodedObject( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 568 | register PyObject *obj, /* Object */ |
Marc-André Lemburg | 5a5c81a | 2000-07-07 13:46:42 +0000 | [diff] [blame] | 569 | const char *encoding, /* encoding */ |
| 570 | const char *errors /* error handling */ |
| 571 | ); |
| 572 | |
Guido van Rossum | b8c65bc | 2001-10-19 02:01:31 +0000 | [diff] [blame] | 573 | /* Coerce obj to an Unicode object and return a reference with |
Marc-André Lemburg | 5a5c81a | 2000-07-07 13:46:42 +0000 | [diff] [blame] | 574 | *incremented* refcount. |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 575 | |
Guido van Rossum | b8c65bc | 2001-10-19 02:01:31 +0000 | [diff] [blame] | 576 | Unicode objects are passed back as-is (subclasses are converted to |
| 577 | true Unicode objects), all other objects are delegated to |
| 578 | PyUnicode_FromEncodedObject(obj, NULL, "strict") which results in |
Georg Brandl | 952867a | 2010-06-27 10:17:12 +0000 | [diff] [blame] | 579 | using UTF-8 encoding as basis for decoding the object. |
Marc-André Lemburg | 5a5c81a | 2000-07-07 13:46:42 +0000 | [diff] [blame] | 580 | |
| 581 | The API returns NULL in case of an error. The caller is responsible |
| 582 | for decref'ing the returned objects. |
| 583 | |
| 584 | */ |
| 585 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 586 | PyAPI_FUNC(PyObject*) PyUnicode_FromObject( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 587 | register PyObject *obj /* Object */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 588 | ); |
| 589 | |
Walter Dörwald | d203431 | 2007-05-18 16:29:38 +0000 | [diff] [blame] | 590 | PyAPI_FUNC(PyObject *) PyUnicode_FromFormatV(const char*, va_list); |
| 591 | PyAPI_FUNC(PyObject *) PyUnicode_FromFormat(const char*, ...); |
| 592 | |
Eric Smith | 4a7d76d | 2008-05-30 18:10:19 +0000 | [diff] [blame] | 593 | /* Format the object based on the format_spec, as defined in PEP 3101 |
| 594 | (Advanced String Formatting). */ |
| 595 | PyAPI_FUNC(PyObject *) _PyUnicode_FormatAdvanced(PyObject *obj, |
| 596 | Py_UNICODE *format_spec, |
| 597 | Py_ssize_t format_spec_len); |
| 598 | |
Walter Dörwald | 1680713 | 2007-05-25 13:52:07 +0000 | [diff] [blame] | 599 | PyAPI_FUNC(void) PyUnicode_InternInPlace(PyObject **); |
| 600 | PyAPI_FUNC(void) PyUnicode_InternImmortal(PyObject **); |
| 601 | PyAPI_FUNC(PyObject *) PyUnicode_InternFromString(const char *); |
| 602 | PyAPI_FUNC(void) _Py_ReleaseInternedUnicodeStrings(void); |
| 603 | |
| 604 | /* Use only if you know it's a string */ |
| 605 | #define PyUnicode_CHECK_INTERNED(op) (((PyUnicodeObject *)(op))->state) |
| 606 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 607 | /* --- wchar_t support for platforms which support it --------------------- */ |
| 608 | |
| 609 | #ifdef HAVE_WCHAR_H |
| 610 | |
Georg Brandl | 952867a | 2010-06-27 10:17:12 +0000 | [diff] [blame] | 611 | /* Create a Unicode Object from the wchar_t buffer w of the given |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 612 | size. |
| 613 | |
| 614 | The buffer is copied into the new object. */ |
| 615 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 616 | PyAPI_FUNC(PyObject*) PyUnicode_FromWideChar( |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 617 | register const wchar_t *w, /* wchar_t buffer */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 618 | Py_ssize_t size /* size of buffer */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 619 | ); |
| 620 | |
Marc-André Lemburg | a9cadcd | 2004-11-22 13:02:31 +0000 | [diff] [blame] | 621 | /* Copies the Unicode Object contents into the wchar_t buffer w. At |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 622 | most size wchar_t characters are copied. |
| 623 | |
Marc-André Lemburg | a9cadcd | 2004-11-22 13:02:31 +0000 | [diff] [blame] | 624 | Note that the resulting wchar_t string may or may not be |
| 625 | 0-terminated. It is the responsibility of the caller to make sure |
| 626 | that the wchar_t string is 0-terminated in case this is required by |
| 627 | the application. |
| 628 | |
| 629 | Returns the number of wchar_t characters copied (excluding a |
| 630 | possibly trailing 0-termination character) or -1 in case of an |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 631 | error. */ |
| 632 | |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 633 | PyAPI_FUNC(Py_ssize_t) PyUnicode_AsWideChar( |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 634 | PyUnicodeObject *unicode, /* Unicode object */ |
| 635 | register wchar_t *w, /* wchar_t buffer */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 636 | Py_ssize_t size /* size of buffer */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 637 | ); |
| 638 | |
| 639 | #endif |
| 640 | |
Marc-André Lemburg | cc8764c | 2002-08-11 12:23:04 +0000 | [diff] [blame] | 641 | /* --- Unicode ordinals --------------------------------------------------- */ |
| 642 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 643 | /* Create a Unicode Object from the given Unicode code point ordinal. |
| 644 | |
Marc-André Lemburg | cc8764c | 2002-08-11 12:23:04 +0000 | [diff] [blame] | 645 | The ordinal must be in range(0x10000) on narrow Python builds |
| 646 | (UCS2), and range(0x110000) on wide builds (UCS4). A ValueError is |
| 647 | raised in case it is not. |
| 648 | |
| 649 | */ |
| 650 | |
Marc-André Lemburg | 9c329de | 2002-08-12 08:19:10 +0000 | [diff] [blame] | 651 | PyAPI_FUNC(PyObject*) PyUnicode_FromOrdinal(int ordinal); |
Marc-André Lemburg | cc8764c | 2002-08-11 12:23:04 +0000 | [diff] [blame] | 652 | |
Benjamin Peterson | 960cf0f | 2009-01-09 04:11:44 +0000 | [diff] [blame] | 653 | /* --- Free-list management ----------------------------------------------- */ |
| 654 | |
| 655 | /* Clear the free list used by the Unicode implementation. |
| 656 | |
| 657 | This can be used to release memory used for objects on the free |
| 658 | list back to the Python memory allocator. |
| 659 | |
| 660 | */ |
| 661 | |
| 662 | PyAPI_FUNC(int) PyUnicode_ClearFreeList(void); |
| 663 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 664 | /* === Builtin Codecs ===================================================== |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 665 | |
| 666 | Many of these APIs take two arguments encoding and errors. These |
| 667 | parameters encoding and errors have the same semantics as the ones |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 668 | of the builtin unicode() API. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 669 | |
Georg Brandl | 952867a | 2010-06-27 10:17:12 +0000 | [diff] [blame] | 670 | Setting encoding to NULL causes the default encoding (UTF-8) to be used. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 671 | |
| 672 | Error handling is set by errors which may also be set to NULL |
| 673 | meaning to use the default handling defined for the codec. Default |
| 674 | error handling for all builtin codecs is "strict" (ValueErrors are |
| 675 | raised). |
| 676 | |
| 677 | The codecs all use a similar interface. Only deviation from the |
| 678 | generic ones are documented. |
| 679 | |
| 680 | */ |
| 681 | |
Fred Drake | cb093fe | 2000-05-09 19:51:53 +0000 | [diff] [blame] | 682 | /* --- Manage the default encoding ---------------------------------------- */ |
| 683 | |
Jeremy Hylton | 3ce4538 | 2001-07-30 22:34:24 +0000 | [diff] [blame] | 684 | /* Return a Python string holding the default encoded value of the |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 685 | Unicode object. |
Jeremy Hylton | 3ce4538 | 2001-07-30 22:34:24 +0000 | [diff] [blame] | 686 | |
| 687 | The resulting string is cached in the Unicode object for subsequent |
| 688 | usage by this function. The cached version is needed to implement |
| 689 | the character buffer interface and will live (at least) as long as |
| 690 | the Unicode object itself. |
| 691 | |
| 692 | The refcount of the string is *not* incremented. |
| 693 | |
| 694 | *** Exported for internal use by the interpreter only !!! *** |
| 695 | |
| 696 | */ |
| 697 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 698 | PyAPI_FUNC(PyObject *) _PyUnicode_AsDefaultEncodedString( |
Marc-André Lemburg | 9155aa7 | 2008-04-29 11:14:08 +0000 | [diff] [blame] | 699 | PyObject *unicode, |
| 700 | const char *errors); |
Jeremy Hylton | 3ce4538 | 2001-07-30 22:34:24 +0000 | [diff] [blame] | 701 | |
Marc-André Lemburg | 9155aa7 | 2008-04-29 11:14:08 +0000 | [diff] [blame] | 702 | /* Returns a pointer to the default encoding (normally, UTF-8) of the |
| 703 | Unicode object unicode and the size of the encoded representation |
| 704 | in bytes stored in *size. |
Christian Heimes | 5894ba7 | 2007-11-04 11:43:14 +0000 | [diff] [blame] | 705 | |
Marc-André Lemburg | 9155aa7 | 2008-04-29 11:14:08 +0000 | [diff] [blame] | 706 | In case of an error, no *size is set. |
Guido van Rossum | 7d1df6c | 2007-08-29 13:53:23 +0000 | [diff] [blame] | 707 | |
Marc-André Lemburg | 4cc0f24 | 2008-08-07 18:54:33 +0000 | [diff] [blame] | 708 | *** This API is for interpreter INTERNAL USE ONLY and will likely |
| 709 | *** be removed or changed for Python 3.1. |
| 710 | |
| 711 | *** If you need to access the Unicode object as UTF-8 bytes string, |
| 712 | *** please use PyUnicode_AsUTF8String() instead. |
| 713 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 714 | */ |
| 715 | |
Marc-André Lemburg | 4cc0f24 | 2008-08-07 18:54:33 +0000 | [diff] [blame] | 716 | PyAPI_FUNC(char *) _PyUnicode_AsStringAndSize( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 717 | PyObject *unicode, |
Marc-André Lemburg | 9155aa7 | 2008-04-29 11:14:08 +0000 | [diff] [blame] | 718 | Py_ssize_t *size); |
Guido van Rossum | 7d1df6c | 2007-08-29 13:53:23 +0000 | [diff] [blame] | 719 | |
Marc-André Lemburg | 9155aa7 | 2008-04-29 11:14:08 +0000 | [diff] [blame] | 720 | /* Returns a pointer to the default encoding (normally, UTf-8) of the |
| 721 | Unicode object unicode. |
Guido van Rossum | 7d1df6c | 2007-08-29 13:53:23 +0000 | [diff] [blame] | 722 | |
Marc-André Lemburg | 9155aa7 | 2008-04-29 11:14:08 +0000 | [diff] [blame] | 723 | Use of this API is DEPRECATED since no size information can be |
Marc-André Lemburg | 4cc0f24 | 2008-08-07 18:54:33 +0000 | [diff] [blame] | 724 | extracted from the returned data. |
| 725 | |
| 726 | *** This API is for interpreter INTERNAL USE ONLY and will likely |
| 727 | *** be removed or changed for Python 3.1. |
| 728 | |
| 729 | *** If you need to access the Unicode object as UTF-8 bytes string, |
| 730 | *** please use PyUnicode_AsUTF8String() instead. |
Guido van Rossum | 7d1df6c | 2007-08-29 13:53:23 +0000 | [diff] [blame] | 731 | |
Marc-André Lemburg | 9155aa7 | 2008-04-29 11:14:08 +0000 | [diff] [blame] | 732 | */ |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 733 | |
Marc-André Lemburg | 4cc0f24 | 2008-08-07 18:54:33 +0000 | [diff] [blame] | 734 | PyAPI_FUNC(char *) _PyUnicode_AsString(PyObject *unicode); |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 735 | |
Marc-André Lemburg | 9155aa7 | 2008-04-29 11:14:08 +0000 | [diff] [blame] | 736 | /* Returns the currently active default encoding. |
Fred Drake | cb093fe | 2000-05-09 19:51:53 +0000 | [diff] [blame] | 737 | |
Marc-André Lemburg | 9155aa7 | 2008-04-29 11:14:08 +0000 | [diff] [blame] | 738 | The default encoding is currently implemented as run-time settable |
| 739 | process global. This may change in future versions of the |
| 740 | interpreter to become a parameter which is managed on a per-thread |
| 741 | basis. |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 742 | |
Fred Drake | cb093fe | 2000-05-09 19:51:53 +0000 | [diff] [blame] | 743 | */ |
| 744 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 745 | PyAPI_FUNC(const char*) PyUnicode_GetDefaultEncoding(void); |
Fred Drake | cb093fe | 2000-05-09 19:51:53 +0000 | [diff] [blame] | 746 | |
| 747 | /* Sets the currently active default encoding. |
| 748 | |
| 749 | Returns 0 on success, -1 in case of an error. |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 750 | |
Fred Drake | cb093fe | 2000-05-09 19:51:53 +0000 | [diff] [blame] | 751 | */ |
| 752 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 753 | PyAPI_FUNC(int) PyUnicode_SetDefaultEncoding( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 754 | const char *encoding /* Encoding name in standard form */ |
Fred Drake | cb093fe | 2000-05-09 19:51:53 +0000 | [diff] [blame] | 755 | ); |
| 756 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 757 | /* --- Generic Codecs ----------------------------------------------------- */ |
| 758 | |
| 759 | /* Create a Unicode object by decoding the encoded string s of the |
| 760 | given size. */ |
| 761 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 762 | PyAPI_FUNC(PyObject*) PyUnicode_Decode( |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 763 | const char *s, /* encoded string */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 764 | Py_ssize_t size, /* size of buffer */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 765 | const char *encoding, /* encoding */ |
| 766 | const char *errors /* error handling */ |
| 767 | ); |
| 768 | |
Marc-André Lemburg | b2750b5 | 2008-06-06 12:18:17 +0000 | [diff] [blame] | 769 | /* Decode a Unicode object unicode and return the result as Python |
| 770 | object. */ |
| 771 | |
| 772 | PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedObject( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 773 | PyObject *unicode, /* Unicode object */ |
| 774 | const char *encoding, /* encoding */ |
| 775 | const char *errors /* error handling */ |
Marc-André Lemburg | b2750b5 | 2008-06-06 12:18:17 +0000 | [diff] [blame] | 776 | ); |
| 777 | |
| 778 | /* Decode a Unicode object unicode and return the result as Unicode |
| 779 | object. */ |
| 780 | |
| 781 | PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedUnicode( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 782 | PyObject *unicode, /* Unicode object */ |
| 783 | const char *encoding, /* encoding */ |
| 784 | const char *errors /* error handling */ |
Marc-André Lemburg | b2750b5 | 2008-06-06 12:18:17 +0000 | [diff] [blame] | 785 | ); |
| 786 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 787 | /* Encodes a Py_UNICODE buffer of the given size and returns a |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 788 | Python string object. */ |
| 789 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 790 | PyAPI_FUNC(PyObject*) PyUnicode_Encode( |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 791 | const Py_UNICODE *s, /* Unicode char buffer */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 792 | Py_ssize_t size, /* number of Py_UNICODE chars to encode */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 793 | const char *encoding, /* encoding */ |
| 794 | const char *errors /* error handling */ |
| 795 | ); |
| 796 | |
Marc-André Lemburg | d2d4598 | 2004-07-08 17:57:32 +0000 | [diff] [blame] | 797 | /* Encodes a Unicode object and returns the result as Python |
| 798 | object. */ |
| 799 | |
| 800 | PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedObject( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 801 | PyObject *unicode, /* Unicode object */ |
| 802 | const char *encoding, /* encoding */ |
| 803 | const char *errors /* error handling */ |
Marc-André Lemburg | d2d4598 | 2004-07-08 17:57:32 +0000 | [diff] [blame] | 804 | ); |
| 805 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 806 | /* Encodes a Unicode object and returns the result as Python string |
| 807 | object. */ |
| 808 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 809 | PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedString( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 810 | PyObject *unicode, /* Unicode object */ |
| 811 | const char *encoding, /* encoding */ |
| 812 | const char *errors /* error handling */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 813 | ); |
| 814 | |
Marc-André Lemburg | b2750b5 | 2008-06-06 12:18:17 +0000 | [diff] [blame] | 815 | /* Encodes a Unicode object and returns the result as Unicode |
| 816 | object. */ |
| 817 | |
| 818 | PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedUnicode( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 819 | PyObject *unicode, /* Unicode object */ |
| 820 | const char *encoding, /* encoding */ |
| 821 | const char *errors /* error handling */ |
Marc-André Lemburg | b2750b5 | 2008-06-06 12:18:17 +0000 | [diff] [blame] | 822 | ); |
| 823 | |
| 824 | /* Build an encoding map. */ |
| 825 | |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 826 | PyAPI_FUNC(PyObject*) PyUnicode_BuildEncodingMap( |
| 827 | PyObject* string /* 256 character map */ |
| 828 | ); |
| 829 | |
Marc-André Lemburg | c60e6f7 | 2001-09-20 10:35:46 +0000 | [diff] [blame] | 830 | /* --- UTF-7 Codecs ------------------------------------------------------- */ |
| 831 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 832 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 833 | const char *string, /* UTF-7 encoded string */ |
| 834 | Py_ssize_t length, /* size of string */ |
| 835 | const char *errors /* error handling */ |
Marc-André Lemburg | c60e6f7 | 2001-09-20 10:35:46 +0000 | [diff] [blame] | 836 | ); |
| 837 | |
Christian Heimes | 5d14c2b | 2007-11-20 23:38:09 +0000 | [diff] [blame] | 838 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7Stateful( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 839 | const char *string, /* UTF-7 encoded string */ |
| 840 | Py_ssize_t length, /* size of string */ |
| 841 | const char *errors, /* error handling */ |
| 842 | Py_ssize_t *consumed /* bytes consumed */ |
Christian Heimes | 5d14c2b | 2007-11-20 23:38:09 +0000 | [diff] [blame] | 843 | ); |
| 844 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 845 | PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 846 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 847 | Py_ssize_t length, /* number of Py_UNICODE chars to encode */ |
| 848 | int base64SetO, /* Encode RFC2152 Set O characters in base64 */ |
| 849 | int base64WhiteSpace, /* Encode whitespace (sp, ht, nl, cr) in base64 */ |
| 850 | const char *errors /* error handling */ |
Marc-André Lemburg | c60e6f7 | 2001-09-20 10:35:46 +0000 | [diff] [blame] | 851 | ); |
| 852 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 853 | /* --- UTF-8 Codecs ------------------------------------------------------- */ |
| 854 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 855 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 856 | const char *string, /* UTF-8 encoded string */ |
| 857 | Py_ssize_t length, /* size of string */ |
| 858 | const char *errors /* error handling */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 859 | ); |
| 860 | |
Walter Dörwald | 6965203 | 2004-09-07 20:24:22 +0000 | [diff] [blame] | 861 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8Stateful( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 862 | const char *string, /* UTF-8 encoded string */ |
| 863 | Py_ssize_t length, /* size of string */ |
| 864 | const char *errors, /* error handling */ |
| 865 | Py_ssize_t *consumed /* bytes consumed */ |
Walter Dörwald | 6965203 | 2004-09-07 20:24:22 +0000 | [diff] [blame] | 866 | ); |
| 867 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 868 | PyAPI_FUNC(PyObject*) PyUnicode_AsUTF8String( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 869 | PyObject *unicode /* Unicode object */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 870 | ); |
| 871 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 872 | PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF8( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 873 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 874 | Py_ssize_t length, /* number of Py_UNICODE chars to encode */ |
| 875 | const char *errors /* error handling */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 876 | ); |
| 877 | |
Walter Dörwald | 41980ca | 2007-08-16 21:55:45 +0000 | [diff] [blame] | 878 | /* --- UTF-32 Codecs ------------------------------------------------------ */ |
| 879 | |
| 880 | /* Decodes length bytes from a UTF-32 encoded buffer string and returns |
| 881 | the corresponding Unicode object. |
| 882 | |
| 883 | errors (if non-NULL) defines the error handling. It defaults |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 884 | to "strict". |
Walter Dörwald | 41980ca | 2007-08-16 21:55:45 +0000 | [diff] [blame] | 885 | |
| 886 | If byteorder is non-NULL, the decoder starts decoding using the |
| 887 | given byte order: |
| 888 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 889 | *byteorder == -1: little endian |
| 890 | *byteorder == 0: native order |
| 891 | *byteorder == 1: big endian |
Walter Dörwald | 41980ca | 2007-08-16 21:55:45 +0000 | [diff] [blame] | 892 | |
| 893 | In native mode, the first four bytes of the stream are checked for a |
| 894 | BOM mark. If found, the BOM mark is analysed, the byte order |
| 895 | adjusted and the BOM skipped. In the other modes, no BOM mark |
| 896 | interpretation is done. After completion, *byteorder is set to the |
| 897 | current byte order at the end of input data. |
| 898 | |
| 899 | If byteorder is NULL, the codec starts in native order mode. |
| 900 | |
| 901 | */ |
| 902 | |
| 903 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF32( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 904 | const char *string, /* UTF-32 encoded string */ |
| 905 | Py_ssize_t length, /* size of string */ |
| 906 | const char *errors, /* error handling */ |
| 907 | int *byteorder /* pointer to byteorder to use |
| 908 | 0=native;-1=LE,1=BE; updated on |
| 909 | exit */ |
Walter Dörwald | 41980ca | 2007-08-16 21:55:45 +0000 | [diff] [blame] | 910 | ); |
| 911 | |
| 912 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF32Stateful( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 913 | const char *string, /* UTF-32 encoded string */ |
| 914 | Py_ssize_t length, /* size of string */ |
| 915 | const char *errors, /* error handling */ |
| 916 | int *byteorder, /* pointer to byteorder to use |
| 917 | 0=native;-1=LE,1=BE; updated on |
| 918 | exit */ |
| 919 | Py_ssize_t *consumed /* bytes consumed */ |
Walter Dörwald | 41980ca | 2007-08-16 21:55:45 +0000 | [diff] [blame] | 920 | ); |
| 921 | |
| 922 | /* Returns a Python string using the UTF-32 encoding in native byte |
| 923 | order. The string always starts with a BOM mark. */ |
| 924 | |
| 925 | PyAPI_FUNC(PyObject*) PyUnicode_AsUTF32String( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 926 | PyObject *unicode /* Unicode object */ |
Walter Dörwald | 41980ca | 2007-08-16 21:55:45 +0000 | [diff] [blame] | 927 | ); |
| 928 | |
| 929 | /* Returns a Python string object holding the UTF-32 encoded value of |
| 930 | the Unicode data. |
| 931 | |
| 932 | If byteorder is not 0, output is written according to the following |
| 933 | byte order: |
| 934 | |
| 935 | byteorder == -1: little endian |
| 936 | byteorder == 0: native byte order (writes a BOM mark) |
| 937 | byteorder == 1: big endian |
| 938 | |
| 939 | If byteorder is 0, the output string will always start with the |
| 940 | Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is |
| 941 | prepended. |
| 942 | |
| 943 | */ |
| 944 | |
| 945 | PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF32( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 946 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 947 | Py_ssize_t length, /* number of Py_UNICODE chars to encode */ |
| 948 | const char *errors, /* error handling */ |
| 949 | int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */ |
Walter Dörwald | 41980ca | 2007-08-16 21:55:45 +0000 | [diff] [blame] | 950 | ); |
| 951 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 952 | /* --- UTF-16 Codecs ------------------------------------------------------ */ |
| 953 | |
Guido van Rossum | 9e896b3 | 2000-04-05 20:11:21 +0000 | [diff] [blame] | 954 | /* Decodes length bytes from a UTF-16 encoded buffer string and returns |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 955 | the corresponding Unicode object. |
| 956 | |
| 957 | errors (if non-NULL) defines the error handling. It defaults |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 958 | to "strict". |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 959 | |
| 960 | If byteorder is non-NULL, the decoder starts decoding using the |
| 961 | given byte order: |
| 962 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 963 | *byteorder == -1: little endian |
| 964 | *byteorder == 0: native order |
| 965 | *byteorder == 1: big endian |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 966 | |
Marc-André Lemburg | 489b56e | 2001-05-21 20:30:15 +0000 | [diff] [blame] | 967 | In native mode, the first two bytes of the stream are checked for a |
| 968 | BOM mark. If found, the BOM mark is analysed, the byte order |
| 969 | adjusted and the BOM skipped. In the other modes, no BOM mark |
| 970 | interpretation is done. After completion, *byteorder is set to the |
| 971 | current byte order at the end of input data. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 972 | |
| 973 | If byteorder is NULL, the codec starts in native order mode. |
| 974 | |
| 975 | */ |
| 976 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 977 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 978 | const char *string, /* UTF-16 encoded string */ |
| 979 | Py_ssize_t length, /* size of string */ |
| 980 | const char *errors, /* error handling */ |
| 981 | int *byteorder /* pointer to byteorder to use |
| 982 | 0=native;-1=LE,1=BE; updated on |
| 983 | exit */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 984 | ); |
| 985 | |
Walter Dörwald | 6965203 | 2004-09-07 20:24:22 +0000 | [diff] [blame] | 986 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16Stateful( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 987 | const char *string, /* UTF-16 encoded string */ |
| 988 | Py_ssize_t length, /* size of string */ |
| 989 | const char *errors, /* error handling */ |
| 990 | int *byteorder, /* pointer to byteorder to use |
| 991 | 0=native;-1=LE,1=BE; updated on |
| 992 | exit */ |
| 993 | Py_ssize_t *consumed /* bytes consumed */ |
Walter Dörwald | 6965203 | 2004-09-07 20:24:22 +0000 | [diff] [blame] | 994 | ); |
| 995 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 996 | /* Returns a Python string using the UTF-16 encoding in native byte |
| 997 | order. The string always starts with a BOM mark. */ |
| 998 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 999 | PyAPI_FUNC(PyObject*) PyUnicode_AsUTF16String( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1000 | PyObject *unicode /* Unicode object */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1001 | ); |
| 1002 | |
| 1003 | /* Returns a Python string object holding the UTF-16 encoded value of |
Guido van Rossum | 9e896b3 | 2000-04-05 20:11:21 +0000 | [diff] [blame] | 1004 | the Unicode data. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1005 | |
| 1006 | If byteorder is not 0, output is written according to the following |
| 1007 | byte order: |
| 1008 | |
| 1009 | byteorder == -1: little endian |
| 1010 | byteorder == 0: native byte order (writes a BOM mark) |
| 1011 | byteorder == 1: big endian |
| 1012 | |
| 1013 | If byteorder is 0, the output string will always start with the |
| 1014 | Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is |
| 1015 | prepended. |
| 1016 | |
| 1017 | Note that Py_UNICODE data is being interpreted as UTF-16 reduced to |
| 1018 | UCS-2. This trick makes it possible to add full UTF-16 capabilities |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 1019 | at a later point without compromising the APIs. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1020 | |
| 1021 | */ |
| 1022 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1023 | PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF16( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1024 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 1025 | Py_ssize_t length, /* number of Py_UNICODE chars to encode */ |
| 1026 | const char *errors, /* error handling */ |
| 1027 | int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1028 | ); |
| 1029 | |
| 1030 | /* --- Unicode-Escape Codecs ---------------------------------------------- */ |
| 1031 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1032 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeUnicodeEscape( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1033 | const char *string, /* Unicode-Escape encoded string */ |
| 1034 | Py_ssize_t length, /* size of string */ |
| 1035 | const char *errors /* error handling */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1036 | ); |
| 1037 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1038 | PyAPI_FUNC(PyObject*) PyUnicode_AsUnicodeEscapeString( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1039 | PyObject *unicode /* Unicode object */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1040 | ); |
| 1041 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1042 | PyAPI_FUNC(PyObject*) PyUnicode_EncodeUnicodeEscape( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1043 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 1044 | Py_ssize_t length /* Number of Py_UNICODE chars to encode */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1045 | ); |
| 1046 | |
| 1047 | /* --- Raw-Unicode-Escape Codecs ------------------------------------------ */ |
| 1048 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1049 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeRawUnicodeEscape( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1050 | const char *string, /* Raw-Unicode-Escape encoded string */ |
| 1051 | Py_ssize_t length, /* size of string */ |
| 1052 | const char *errors /* error handling */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1053 | ); |
| 1054 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1055 | PyAPI_FUNC(PyObject*) PyUnicode_AsRawUnicodeEscapeString( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1056 | PyObject *unicode /* Unicode object */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1057 | ); |
| 1058 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1059 | PyAPI_FUNC(PyObject*) PyUnicode_EncodeRawUnicodeEscape( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1060 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 1061 | Py_ssize_t length /* Number of Py_UNICODE chars to encode */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1062 | ); |
| 1063 | |
Walter Dörwald | a47d1c0 | 2005-08-30 10:23:14 +0000 | [diff] [blame] | 1064 | /* --- Unicode Internal Codec --------------------------------------------- |
| 1065 | |
| 1066 | Only for internal use in _codecsmodule.c */ |
| 1067 | |
| 1068 | PyObject *_PyUnicode_DecodeUnicodeInternal( |
| 1069 | const char *string, |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 1070 | Py_ssize_t length, |
Walter Dörwald | a47d1c0 | 2005-08-30 10:23:14 +0000 | [diff] [blame] | 1071 | const char *errors |
| 1072 | ); |
| 1073 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1074 | /* --- Latin-1 Codecs ----------------------------------------------------- |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1075 | |
| 1076 | Note: Latin-1 corresponds to the first 256 Unicode ordinals. |
| 1077 | |
| 1078 | */ |
| 1079 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1080 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeLatin1( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1081 | const char *string, /* Latin-1 encoded string */ |
| 1082 | Py_ssize_t length, /* size of string */ |
| 1083 | const char *errors /* error handling */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1084 | ); |
| 1085 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1086 | PyAPI_FUNC(PyObject*) PyUnicode_AsLatin1String( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1087 | PyObject *unicode /* Unicode object */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1088 | ); |
| 1089 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1090 | PyAPI_FUNC(PyObject*) PyUnicode_EncodeLatin1( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1091 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 1092 | Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ |
| 1093 | const char *errors /* error handling */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1094 | ); |
| 1095 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1096 | /* --- ASCII Codecs ------------------------------------------------------- |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1097 | |
| 1098 | Only 7-bit ASCII data is excepted. All other codes generate errors. |
| 1099 | |
| 1100 | */ |
| 1101 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1102 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeASCII( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1103 | const char *string, /* ASCII encoded string */ |
| 1104 | Py_ssize_t length, /* size of string */ |
| 1105 | const char *errors /* error handling */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1106 | ); |
| 1107 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1108 | PyAPI_FUNC(PyObject*) PyUnicode_AsASCIIString( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1109 | PyObject *unicode /* Unicode object */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1110 | ); |
| 1111 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1112 | PyAPI_FUNC(PyObject*) PyUnicode_EncodeASCII( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1113 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 1114 | Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ |
| 1115 | const char *errors /* error handling */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1116 | ); |
| 1117 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1118 | /* --- Character Map Codecs ----------------------------------------------- |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1119 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1120 | This codec uses mappings to encode and decode characters. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1121 | |
| 1122 | Decoding mappings must map single string characters to single |
| 1123 | Unicode characters, integers (which are then interpreted as Unicode |
| 1124 | ordinals) or None (meaning "undefined mapping" and causing an |
| 1125 | error). |
| 1126 | |
| 1127 | Encoding mappings must map single Unicode characters to single |
| 1128 | string characters, integers (which are then interpreted as Latin-1 |
| 1129 | ordinals) or None (meaning "undefined mapping" and causing an |
| 1130 | error). |
| 1131 | |
| 1132 | If a character lookup fails with a LookupError, the character is |
| 1133 | copied as-is meaning that its ordinal value will be interpreted as |
| 1134 | Unicode or Latin-1 ordinal resp. Because of this mappings only need |
| 1135 | to contain those mappings which map characters to different code |
| 1136 | points. |
| 1137 | |
| 1138 | */ |
| 1139 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1140 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeCharmap( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1141 | const char *string, /* Encoded string */ |
| 1142 | Py_ssize_t length, /* size of string */ |
| 1143 | PyObject *mapping, /* character mapping |
| 1144 | (char ordinal -> unicode ordinal) */ |
| 1145 | const char *errors /* error handling */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1146 | ); |
| 1147 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1148 | PyAPI_FUNC(PyObject*) PyUnicode_AsCharmapString( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1149 | PyObject *unicode, /* Unicode object */ |
| 1150 | PyObject *mapping /* character mapping |
| 1151 | (unicode ordinal -> char ordinal) */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1152 | ); |
| 1153 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1154 | PyAPI_FUNC(PyObject*) PyUnicode_EncodeCharmap( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1155 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 1156 | Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ |
| 1157 | PyObject *mapping, /* character mapping |
| 1158 | (unicode ordinal -> char ordinal) */ |
| 1159 | const char *errors /* error handling */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1160 | ); |
| 1161 | |
| 1162 | /* Translate a Py_UNICODE buffer of the given length by applying a |
| 1163 | character mapping table to it and return the resulting Unicode |
| 1164 | object. |
| 1165 | |
| 1166 | The mapping table must map Unicode ordinal integers to Unicode |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1167 | ordinal integers or None (causing deletion of the character). |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1168 | |
| 1169 | Mapping tables may be dictionaries or sequences. Unmapped character |
| 1170 | ordinals (ones which cause a LookupError) are left untouched and |
| 1171 | are copied as-is. |
| 1172 | |
| 1173 | */ |
| 1174 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1175 | PyAPI_FUNC(PyObject *) PyUnicode_TranslateCharmap( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1176 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 1177 | Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ |
| 1178 | PyObject *table, /* Translate table */ |
| 1179 | const char *errors /* error handling */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1180 | ); |
| 1181 | |
Guido van Rossum | efec115 | 2000-03-28 02:01:15 +0000 | [diff] [blame] | 1182 | #ifdef MS_WIN32 |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 1183 | |
Guido van Rossum | efec115 | 2000-03-28 02:01:15 +0000 | [diff] [blame] | 1184 | /* --- MBCS codecs for Windows -------------------------------------------- */ |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 1185 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1186 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCS( |
Guido van Rossum | efec115 | 2000-03-28 02:01:15 +0000 | [diff] [blame] | 1187 | const char *string, /* MBCS encoded string */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 1188 | Py_ssize_t length, /* size of string */ |
Guido van Rossum | efec115 | 2000-03-28 02:01:15 +0000 | [diff] [blame] | 1189 | const char *errors /* error handling */ |
| 1190 | ); |
| 1191 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1192 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCSStateful( |
| 1193 | const char *string, /* MBCS encoded string */ |
| 1194 | Py_ssize_t length, /* size of string */ |
| 1195 | const char *errors, /* error handling */ |
| 1196 | Py_ssize_t *consumed /* bytes consumed */ |
| 1197 | ); |
| 1198 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1199 | PyAPI_FUNC(PyObject*) PyUnicode_AsMBCSString( |
Guido van Rossum | efec115 | 2000-03-28 02:01:15 +0000 | [diff] [blame] | 1200 | PyObject *unicode /* Unicode object */ |
| 1201 | ); |
| 1202 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1203 | PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS( |
Guido van Rossum | efec115 | 2000-03-28 02:01:15 +0000 | [diff] [blame] | 1204 | const Py_UNICODE *data, /* Unicode char buffer */ |
Neal Norwitz | d78f6cf | 2007-08-08 04:49:37 +0000 | [diff] [blame] | 1205 | Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ |
Guido van Rossum | efec115 | 2000-03-28 02:01:15 +0000 | [diff] [blame] | 1206 | const char *errors /* error handling */ |
| 1207 | ); |
| 1208 | |
Guido van Rossum | efec115 | 2000-03-28 02:01:15 +0000 | [diff] [blame] | 1209 | #endif /* MS_WIN32 */ |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 1210 | |
Guido van Rossum | 9e896b3 | 2000-04-05 20:11:21 +0000 | [diff] [blame] | 1211 | /* --- Decimal Encoder ---------------------------------------------------- */ |
| 1212 | |
| 1213 | /* Takes a Unicode string holding a decimal value and writes it into |
| 1214 | an output buffer using standard ASCII digit codes. |
| 1215 | |
| 1216 | The output buffer has to provide at least length+1 bytes of storage |
| 1217 | area. The output string is 0-terminated. |
| 1218 | |
| 1219 | The encoder converts whitespace to ' ', decimal characters to their |
| 1220 | corresponding ASCII digit and all other Latin-1 characters except |
| 1221 | \0 as-is. Characters outside this range (Unicode ordinals 1-256) |
| 1222 | are treated as errors. This includes embedded NULL bytes. |
| 1223 | |
| 1224 | Error handling is defined by the errors argument: |
| 1225 | |
| 1226 | NULL or "strict": raise a ValueError |
| 1227 | "ignore": ignore the wrong characters (these are not copied to the |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1228 | output buffer) |
Guido van Rossum | 9e896b3 | 2000-04-05 20:11:21 +0000 | [diff] [blame] | 1229 | "replace": replaces illegal characters with '?' |
| 1230 | |
| 1231 | Returns 0 on success, -1 on failure. |
| 1232 | |
| 1233 | */ |
| 1234 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1235 | PyAPI_FUNC(int) PyUnicode_EncodeDecimal( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1236 | Py_UNICODE *s, /* Unicode buffer */ |
| 1237 | Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ |
| 1238 | char *output, /* Output buffer; must have size >= length */ |
| 1239 | const char *errors /* error handling */ |
Guido van Rossum | 9e896b3 | 2000-04-05 20:11:21 +0000 | [diff] [blame] | 1240 | ); |
| 1241 | |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 1242 | /* --- File system encoding ---------------------------------------------- */ |
| 1243 | |
Victor Stinner | 47fcb5b | 2010-08-13 23:59:58 +0000 | [diff] [blame] | 1244 | /* ParseTuple converter: encode str objects to bytes using |
| 1245 | PyUnicode_EncodeFSDefault(); bytes objects are output as-is. */ |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 1246 | |
| 1247 | PyAPI_FUNC(int) PyUnicode_FSConverter(PyObject*, void*); |
| 1248 | |
Victor Stinner | 47fcb5b | 2010-08-13 23:59:58 +0000 | [diff] [blame] | 1249 | /* ParseTuple converter: decode bytes objects to unicode using |
| 1250 | PyUnicode_DecodeFSDefaultAndSize(); str objects are output as-is. */ |
| 1251 | |
| 1252 | PyAPI_FUNC(int) PyUnicode_FSDecoder(PyObject*, void*); |
| 1253 | |
Victor Stinner | 77c3862 | 2010-05-14 15:58:55 +0000 | [diff] [blame] | 1254 | /* Decode a null-terminated string using Py_FileSystemDefaultEncoding |
| 1255 | and the "surrogateescape" error handler. |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 1256 | |
Victor Stinner | 77c3862 | 2010-05-14 15:58:55 +0000 | [diff] [blame] | 1257 | If Py_FileSystemDefaultEncoding is not set, fall back to UTF-8. |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 1258 | |
Benjamin Peterson | ccbd694 | 2010-05-15 17:43:18 +0000 | [diff] [blame] | 1259 | Use PyUnicode_DecodeFSDefaultAndSize() if the string length is known. |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 1260 | */ |
| 1261 | |
| 1262 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefault( |
| 1263 | const char *s /* encoded string */ |
| 1264 | ); |
| 1265 | |
Victor Stinner | 77c3862 | 2010-05-14 15:58:55 +0000 | [diff] [blame] | 1266 | /* Decode a string using Py_FileSystemDefaultEncoding |
| 1267 | and the "surrogateescape" error handler. |
| 1268 | |
| 1269 | If Py_FileSystemDefaultEncoding is not set, fall back to UTF-8. |
| 1270 | */ |
| 1271 | |
Martin v. Löwis | 011e842 | 2009-05-05 04:43:17 +0000 | [diff] [blame] | 1272 | PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefaultAndSize( |
| 1273 | const char *s, /* encoded string */ |
| 1274 | Py_ssize_t size /* size */ |
| 1275 | ); |
| 1276 | |
Victor Stinner | ae6265f | 2010-05-15 16:27:27 +0000 | [diff] [blame] | 1277 | /* Encode a Unicode object to Py_FileSystemDefaultEncoding with the |
Benjamin Peterson | ccbd694 | 2010-05-15 17:43:18 +0000 | [diff] [blame] | 1278 | "surrogateescape" error handler, and return bytes. |
Victor Stinner | ae6265f | 2010-05-15 16:27:27 +0000 | [diff] [blame] | 1279 | |
| 1280 | If Py_FileSystemDefaultEncoding is not set, fall back to UTF-8. |
| 1281 | */ |
| 1282 | |
| 1283 | PyAPI_FUNC(PyObject*) PyUnicode_EncodeFSDefault( |
| 1284 | PyObject *unicode |
| 1285 | ); |
| 1286 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1287 | /* --- Methods & Slots ---------------------------------------------------- |
| 1288 | |
| 1289 | These are capable of handling Unicode objects and strings on input |
| 1290 | (we refer to them as strings in the descriptions) and return |
| 1291 | Unicode objects or integers as apporpriate. */ |
| 1292 | |
| 1293 | /* Concat two strings giving a new Unicode string. */ |
| 1294 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1295 | PyAPI_FUNC(PyObject*) PyUnicode_Concat( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1296 | PyObject *left, /* Left string */ |
| 1297 | PyObject *right /* Right string */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1298 | ); |
| 1299 | |
Walter Dörwald | 1ab8330 | 2007-05-18 17:15:44 +0000 | [diff] [blame] | 1300 | /* Concat two strings and put the result in *pleft |
| 1301 | (sets *pleft to NULL on error) */ |
| 1302 | |
| 1303 | PyAPI_FUNC(void) PyUnicode_Append( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1304 | PyObject **pleft, /* Pointer to left string */ |
| 1305 | PyObject *right /* Right string */ |
Walter Dörwald | 1ab8330 | 2007-05-18 17:15:44 +0000 | [diff] [blame] | 1306 | ); |
| 1307 | |
| 1308 | /* Concat two strings, put the result in *pleft and drop the right object |
| 1309 | (sets *pleft to NULL on error) */ |
| 1310 | |
| 1311 | PyAPI_FUNC(void) PyUnicode_AppendAndDel( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1312 | PyObject **pleft, /* Pointer to left string */ |
| 1313 | PyObject *right /* Right string */ |
Walter Dörwald | 1ab8330 | 2007-05-18 17:15:44 +0000 | [diff] [blame] | 1314 | ); |
| 1315 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1316 | /* Split a string giving a list of Unicode strings. |
| 1317 | |
| 1318 | If sep is NULL, splitting will be done at all whitespace |
| 1319 | substrings. Otherwise, splits occur at the given separator. |
| 1320 | |
| 1321 | At most maxsplit splits will be done. If negative, no limit is set. |
| 1322 | |
| 1323 | Separators are not included in the resulting list. |
| 1324 | |
| 1325 | */ |
| 1326 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1327 | PyAPI_FUNC(PyObject*) PyUnicode_Split( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1328 | PyObject *s, /* String to split */ |
| 1329 | PyObject *sep, /* String separator */ |
| 1330 | Py_ssize_t maxsplit /* Maxsplit count */ |
| 1331 | ); |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1332 | |
| 1333 | /* Dito, but split at line breaks. |
| 1334 | |
| 1335 | CRLF is considered to be one line break. Line breaks are not |
| 1336 | included in the resulting list. */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1337 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1338 | PyAPI_FUNC(PyObject*) PyUnicode_Splitlines( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1339 | PyObject *s, /* String to split */ |
| 1340 | int keepends /* If true, line end markers are included */ |
| 1341 | ); |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1342 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1343 | /* Partition a string using a given separator. */ |
| 1344 | |
| 1345 | PyAPI_FUNC(PyObject*) PyUnicode_Partition( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1346 | PyObject *s, /* String to partition */ |
| 1347 | PyObject *sep /* String separator */ |
| 1348 | ); |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1349 | |
| 1350 | /* Partition a string using a given separator, searching from the end of the |
| 1351 | string. */ |
| 1352 | |
| 1353 | PyAPI_FUNC(PyObject*) PyUnicode_RPartition( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1354 | PyObject *s, /* String to partition */ |
| 1355 | PyObject *sep /* String separator */ |
| 1356 | ); |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1357 | |
Hye-Shik Chang | 3ae811b | 2003-12-15 18:49:53 +0000 | [diff] [blame] | 1358 | /* Split a string giving a list of Unicode strings. |
| 1359 | |
| 1360 | If sep is NULL, splitting will be done at all whitespace |
| 1361 | substrings. Otherwise, splits occur at the given separator. |
| 1362 | |
| 1363 | At most maxsplit splits will be done. But unlike PyUnicode_Split |
| 1364 | PyUnicode_RSplit splits from the end of the string. If negative, |
| 1365 | no limit is set. |
| 1366 | |
| 1367 | Separators are not included in the resulting list. |
| 1368 | |
| 1369 | */ |
| 1370 | |
| 1371 | PyAPI_FUNC(PyObject*) PyUnicode_RSplit( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1372 | PyObject *s, /* String to split */ |
| 1373 | PyObject *sep, /* String separator */ |
| 1374 | Py_ssize_t maxsplit /* Maxsplit count */ |
| 1375 | ); |
Hye-Shik Chang | 3ae811b | 2003-12-15 18:49:53 +0000 | [diff] [blame] | 1376 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1377 | /* Translate a string by applying a character mapping table to it and |
| 1378 | return the resulting Unicode object. |
| 1379 | |
| 1380 | The mapping table must map Unicode ordinal integers to Unicode |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1381 | ordinal integers or None (causing deletion of the character). |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1382 | |
| 1383 | Mapping tables may be dictionaries or sequences. Unmapped character |
| 1384 | ordinals (ones which cause a LookupError) are left untouched and |
| 1385 | are copied as-is. |
| 1386 | |
| 1387 | */ |
| 1388 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1389 | PyAPI_FUNC(PyObject *) PyUnicode_Translate( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1390 | PyObject *str, /* String */ |
| 1391 | PyObject *table, /* Translate table */ |
| 1392 | const char *errors /* error handling */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1393 | ); |
| 1394 | |
| 1395 | /* Join a sequence of strings using the given separator and return |
| 1396 | the resulting Unicode string. */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1397 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1398 | PyAPI_FUNC(PyObject*) PyUnicode_Join( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1399 | PyObject *separator, /* Separator string */ |
| 1400 | PyObject *seq /* Sequence object */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1401 | ); |
| 1402 | |
| 1403 | /* Return 1 if substr matches str[start:end] at the given tail end, 0 |
| 1404 | otherwise. */ |
| 1405 | |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 1406 | PyAPI_FUNC(Py_ssize_t) PyUnicode_Tailmatch( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1407 | PyObject *str, /* String */ |
| 1408 | PyObject *substr, /* Prefix or Suffix string */ |
| 1409 | Py_ssize_t start, /* Start index */ |
| 1410 | Py_ssize_t end, /* Stop index */ |
| 1411 | int direction /* Tail end: -1 prefix, +1 suffix */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1412 | ); |
| 1413 | |
| 1414 | /* Return the first position of substr in str[start:end] using the |
Marc-André Lemburg | 4da6fd6 | 2002-05-29 11:33:13 +0000 | [diff] [blame] | 1415 | given search direction or -1 if not found. -2 is returned in case |
| 1416 | an error occurred and an exception is set. */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1417 | |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 1418 | PyAPI_FUNC(Py_ssize_t) PyUnicode_Find( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1419 | PyObject *str, /* String */ |
| 1420 | PyObject *substr, /* Substring to find */ |
| 1421 | Py_ssize_t start, /* Start index */ |
| 1422 | Py_ssize_t end, /* Stop index */ |
| 1423 | int direction /* Find direction: +1 forward, -1 backward */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1424 | ); |
| 1425 | |
Barry Warsaw | 51ac580 | 2000-03-20 16:36:48 +0000 | [diff] [blame] | 1426 | /* Count the number of occurrences of substr in str[start:end]. */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1427 | |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 1428 | PyAPI_FUNC(Py_ssize_t) PyUnicode_Count( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1429 | PyObject *str, /* String */ |
| 1430 | PyObject *substr, /* Substring to count */ |
| 1431 | Py_ssize_t start, /* Start index */ |
| 1432 | Py_ssize_t end /* Stop index */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1433 | ); |
| 1434 | |
Barry Warsaw | 51ac580 | 2000-03-20 16:36:48 +0000 | [diff] [blame] | 1435 | /* Replace at most maxcount occurrences of substr in str with replstr |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1436 | and return the resulting Unicode object. */ |
| 1437 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1438 | PyAPI_FUNC(PyObject *) PyUnicode_Replace( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1439 | PyObject *str, /* String */ |
| 1440 | PyObject *substr, /* Substring to find */ |
| 1441 | PyObject *replstr, /* Substring to replace */ |
| 1442 | Py_ssize_t maxcount /* Max. number of replacements to apply; |
| 1443 | -1 = all */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1444 | ); |
| 1445 | |
| 1446 | /* Compare two strings and return -1, 0, 1 for less than, equal, |
| 1447 | greater than resp. */ |
| 1448 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1449 | PyAPI_FUNC(int) PyUnicode_Compare( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1450 | PyObject *left, /* Left string */ |
| 1451 | PyObject *right /* Right string */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1452 | ); |
| 1453 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 1454 | PyAPI_FUNC(int) PyUnicode_CompareWithASCIIString( |
| 1455 | PyObject *left, |
| 1456 | const char *right |
| 1457 | ); |
| 1458 | |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 1459 | /* Rich compare two strings and return one of the following: |
| 1460 | |
| 1461 | - NULL in case an exception was raised |
| 1462 | - Py_True or Py_False for successfuly comparisons |
| 1463 | - Py_NotImplemented in case the type combination is unknown |
| 1464 | |
| 1465 | Note that Py_EQ and Py_NE comparisons can cause a UnicodeWarning in |
| 1466 | case the conversion of the arguments to Unicode fails with a |
| 1467 | UnicodeDecodeError. |
| 1468 | |
| 1469 | Possible values for op: |
| 1470 | |
| 1471 | Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE |
| 1472 | |
| 1473 | */ |
| 1474 | |
| 1475 | PyAPI_FUNC(PyObject *) PyUnicode_RichCompare( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1476 | PyObject *left, /* Left string */ |
| 1477 | PyObject *right, /* Right string */ |
| 1478 | int op /* Operation: Py_EQ, Py_NE, Py_GT, etc. */ |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 1479 | ); |
| 1480 | |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 1481 | /* Apply a argument tuple or dictionary to a format string and return |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1482 | the resulting Unicode string. */ |
| 1483 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1484 | PyAPI_FUNC(PyObject *) PyUnicode_Format( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1485 | PyObject *format, /* Format string */ |
| 1486 | PyObject *args /* Argument tuple or dictionary */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1487 | ); |
| 1488 | |
Guido van Rossum | d0d366b | 2000-03-13 23:22:24 +0000 | [diff] [blame] | 1489 | /* Checks whether element is contained in container and return 1/0 |
| 1490 | accordingly. |
| 1491 | |
| 1492 | element has to coerce to an one element Unicode string. -1 is |
| 1493 | returned in case of an error. */ |
| 1494 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1495 | PyAPI_FUNC(int) PyUnicode_Contains( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1496 | PyObject *container, /* Container string */ |
| 1497 | PyObject *element /* Element string */ |
Guido van Rossum | d0d366b | 2000-03-13 23:22:24 +0000 | [diff] [blame] | 1498 | ); |
| 1499 | |
Martin v. Löwis | 4738340 | 2007-08-15 07:32:56 +0000 | [diff] [blame] | 1500 | /* Checks whether argument is a valid identifier. */ |
| 1501 | |
| 1502 | PyAPI_FUNC(int) PyUnicode_IsIdentifier(PyObject *s); |
| 1503 | |
Walter Dörwald | de02bcb | 2002-04-22 17:42:37 +0000 | [diff] [blame] | 1504 | /* Externally visible for str.strip(unicode) */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1505 | PyAPI_FUNC(PyObject *) _PyUnicode_XStrip( |
Walter Dörwald | de02bcb | 2002-04-22 17:42:37 +0000 | [diff] [blame] | 1506 | PyUnicodeObject *self, |
| 1507 | int striptype, |
| 1508 | PyObject *sepobj |
| 1509 | ); |
| 1510 | |
Eric Smith | 5807c41 | 2008-05-11 21:00:57 +0000 | [diff] [blame] | 1511 | /* Using the current locale, insert the thousands grouping |
| 1512 | into the string pointed to by buffer. For the argument descriptions, |
| 1513 | see Objects/stringlib/localeutil.h */ |
| 1514 | |
Eric Smith | 0923d1d | 2009-04-16 20:16:10 +0000 | [diff] [blame] | 1515 | PyAPI_FUNC(Py_ssize_t) _PyUnicode_InsertThousandsGroupingLocale(Py_UNICODE *buffer, |
| 1516 | Py_ssize_t n_buffer, |
| 1517 | Py_UNICODE *digits, |
| 1518 | Py_ssize_t n_digits, |
| 1519 | Py_ssize_t min_width); |
Eric Smith | 5807c41 | 2008-05-11 21:00:57 +0000 | [diff] [blame] | 1520 | |
Eric Smith | a3b1ac8 | 2009-04-03 14:45:06 +0000 | [diff] [blame] | 1521 | /* Using explicit passed-in values, insert the thousands grouping |
| 1522 | into the string pointed to by buffer. For the argument descriptions, |
| 1523 | see Objects/stringlib/localeutil.h */ |
Eric Smith | 0923d1d | 2009-04-16 20:16:10 +0000 | [diff] [blame] | 1524 | PyAPI_FUNC(Py_ssize_t) _PyUnicode_InsertThousandsGrouping(Py_UNICODE *buffer, |
| 1525 | Py_ssize_t n_buffer, |
| 1526 | Py_UNICODE *digits, |
| 1527 | Py_ssize_t n_digits, |
| 1528 | Py_ssize_t min_width, |
| 1529 | const char *grouping, |
| 1530 | const char *thousands_sep); |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1531 | /* === Characters Type APIs =============================================== */ |
| 1532 | |
Benjamin Peterson | 960cf0f | 2009-01-09 04:11:44 +0000 | [diff] [blame] | 1533 | /* Helper array used by Py_UNICODE_ISSPACE(). */ |
| 1534 | |
| 1535 | PyAPI_DATA(const unsigned char) _Py_ascii_whitespace[]; |
| 1536 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1537 | /* These should not be used directly. Use the Py_UNICODE_IS* and |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1538 | Py_UNICODE_TO* macros instead. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1539 | |
| 1540 | These APIs are implemented in Objects/unicodectype.c. |
| 1541 | |
| 1542 | */ |
| 1543 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1544 | PyAPI_FUNC(int) _PyUnicode_IsLowercase( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1545 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1546 | ); |
| 1547 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1548 | PyAPI_FUNC(int) _PyUnicode_IsUppercase( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1549 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1550 | ); |
| 1551 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1552 | PyAPI_FUNC(int) _PyUnicode_IsTitlecase( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1553 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1554 | ); |
| 1555 | |
Martin v. Löwis | 13c3e38 | 2007-08-14 22:37:03 +0000 | [diff] [blame] | 1556 | PyAPI_FUNC(int) _PyUnicode_IsXidStart( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1557 | Py_UNICODE ch /* Unicode character */ |
Martin v. Löwis | 13c3e38 | 2007-08-14 22:37:03 +0000 | [diff] [blame] | 1558 | ); |
| 1559 | |
| 1560 | PyAPI_FUNC(int) _PyUnicode_IsXidContinue( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1561 | Py_UNICODE ch /* Unicode character */ |
Martin v. Löwis | 13c3e38 | 2007-08-14 22:37:03 +0000 | [diff] [blame] | 1562 | ); |
| 1563 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1564 | PyAPI_FUNC(int) _PyUnicode_IsWhitespace( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1565 | const Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1566 | ); |
| 1567 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1568 | PyAPI_FUNC(int) _PyUnicode_IsLinebreak( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1569 | const Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1570 | ); |
| 1571 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1572 | PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToLowercase( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1573 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1574 | ); |
| 1575 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1576 | PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToUppercase( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1577 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1578 | ); |
| 1579 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1580 | PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToTitlecase( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1581 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1582 | ); |
| 1583 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1584 | PyAPI_FUNC(int) _PyUnicode_ToDecimalDigit( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1585 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1586 | ); |
| 1587 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1588 | PyAPI_FUNC(int) _PyUnicode_ToDigit( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1589 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1590 | ); |
| 1591 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1592 | PyAPI_FUNC(double) _PyUnicode_ToNumeric( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1593 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1594 | ); |
| 1595 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1596 | PyAPI_FUNC(int) _PyUnicode_IsDecimalDigit( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1597 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1598 | ); |
| 1599 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1600 | PyAPI_FUNC(int) _PyUnicode_IsDigit( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1601 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1602 | ); |
| 1603 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1604 | PyAPI_FUNC(int) _PyUnicode_IsNumeric( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1605 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1606 | ); |
| 1607 | |
Georg Brandl | 559e5d7 | 2008-06-11 18:37:52 +0000 | [diff] [blame] | 1608 | PyAPI_FUNC(int) _PyUnicode_IsPrintable( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1609 | Py_UNICODE ch /* Unicode character */ |
Georg Brandl | 559e5d7 | 2008-06-11 18:37:52 +0000 | [diff] [blame] | 1610 | ); |
| 1611 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 1612 | PyAPI_FUNC(int) _PyUnicode_IsAlpha( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1613 | Py_UNICODE ch /* Unicode character */ |
Marc-André Lemburg | f03e741 | 2000-07-05 09:45:59 +0000 | [diff] [blame] | 1614 | ); |
| 1615 | |
Victor Stinner | ef8d95c | 2010-08-16 22:03:11 +0000 | [diff] [blame] | 1616 | PyAPI_FUNC(size_t) Py_UNICODE_strlen( |
| 1617 | const Py_UNICODE *u |
| 1618 | ); |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 1619 | |
| 1620 | PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcpy( |
Victor Stinner | ef8d95c | 2010-08-16 22:03:11 +0000 | [diff] [blame] | 1621 | Py_UNICODE *s1, |
| 1622 | const Py_UNICODE *s2); |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 1623 | |
| 1624 | PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strncpy( |
Victor Stinner | ef8d95c | 2010-08-16 22:03:11 +0000 | [diff] [blame] | 1625 | Py_UNICODE *s1, |
| 1626 | const Py_UNICODE *s2, |
| 1627 | size_t n); |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 1628 | |
| 1629 | PyAPI_FUNC(int) Py_UNICODE_strcmp( |
Victor Stinner | ef8d95c | 2010-08-16 22:03:11 +0000 | [diff] [blame] | 1630 | const Py_UNICODE *s1, |
| 1631 | const Py_UNICODE *s2 |
| 1632 | ); |
| 1633 | |
| 1634 | PyAPI_FUNC(int) Py_UNICODE_strncmp( |
| 1635 | const Py_UNICODE *s1, |
| 1636 | const Py_UNICODE *s2, |
| 1637 | size_t n |
| 1638 | ); |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 1639 | |
| 1640 | PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr( |
Victor Stinner | ef8d95c | 2010-08-16 22:03:11 +0000 | [diff] [blame] | 1641 | const Py_UNICODE *s, |
| 1642 | Py_UNICODE c |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 1643 | ); |
| 1644 | |
Victor Stinner | 331ea92 | 2010-08-10 16:37:20 +0000 | [diff] [blame] | 1645 | PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr( |
Victor Stinner | ef8d95c | 2010-08-16 22:03:11 +0000 | [diff] [blame] | 1646 | const Py_UNICODE *s, |
| 1647 | Py_UNICODE c |
Victor Stinner | 331ea92 | 2010-08-10 16:37:20 +0000 | [diff] [blame] | 1648 | ); |
| 1649 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1650 | #ifdef __cplusplus |
| 1651 | } |
| 1652 | #endif |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 1653 | #endif /* !Py_UNICODEOBJECT_H */ |