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 | |
| 4 | /* |
| 5 | |
| 6 | Unicode implementation based on original code by Fredrik Lundh, |
| 7 | modified by Marc-Andre Lemburg (mal@lemburg.com) according to the |
| 8 | Unicode Integration Proposal (see file Misc/unicode.txt). |
| 9 | |
Guido van Rossum | 16b1ad9 | 2000-08-03 16:24:25 +0000 | [diff] [blame] | 10 | Copyright (c) Corporation for National Research Initiatives. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 11 | |
| 12 | |
| 13 | Original header: |
| 14 | -------------------------------------------------------------------- |
| 15 | |
| 16 | * Yet another Unicode string type for Python. This type supports the |
| 17 | * 16-bit Basic Multilingual Plane (BMP) only. |
| 18 | * |
| 19 | * Written by Fredrik Lundh, January 1999. |
| 20 | * |
| 21 | * Copyright (c) 1999 by Secret Labs AB. |
| 22 | * Copyright (c) 1999 by Fredrik Lundh. |
| 23 | * |
| 24 | * fredrik@pythonware.com |
| 25 | * http://www.pythonware.com |
| 26 | * |
| 27 | * -------------------------------------------------------------------- |
| 28 | * This Unicode String Type is |
| 29 | * |
| 30 | * Copyright (c) 1999 by Secret Labs AB |
| 31 | * Copyright (c) 1999 by Fredrik Lundh |
| 32 | * |
| 33 | * By obtaining, using, and/or copying this software and/or its |
| 34 | * associated documentation, you agree that you have read, understood, |
| 35 | * and will comply with the following terms and conditions: |
| 36 | * |
| 37 | * Permission to use, copy, modify, and distribute this software and its |
| 38 | * associated documentation for any purpose and without fee is hereby |
| 39 | * granted, provided that the above copyright notice appears in all |
| 40 | * copies, and that both that copyright notice and this permission notice |
| 41 | * appear in supporting documentation, and that the name of Secret Labs |
| 42 | * AB or the author not be used in advertising or publicity pertaining to |
| 43 | * distribution of the software without specific, written prior |
| 44 | * permission. |
| 45 | * |
| 46 | * SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 47 | * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 48 | * FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR |
| 49 | * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 50 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 51 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 52 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 53 | * -------------------------------------------------------------------- */ |
| 54 | |
| 55 | #include "ctype.h" |
| 56 | |
| 57 | /* === Internal API ======================================================= */ |
| 58 | |
| 59 | /* --- Internal Unicode Format -------------------------------------------- */ |
| 60 | |
Fredrik Lundh | 9b14ab3 | 2001-06-26 22:59:49 +0000 | [diff] [blame] | 61 | /* FIXME: MvL's new implementation assumes that Py_UNICODE_SIZE is |
| 62 | properly set, but the default rules below doesn't set it. I'll |
| 63 | sort this out some other day -- fredrik@pythonware.com */ |
| 64 | |
| 65 | #ifndef Py_UNICODE_SIZE |
| 66 | #error Must define Py_UNICODE_SIZE |
| 67 | #endif |
| 68 | |
Fredrik Lundh | 8f45585 | 2001-06-27 18:59:43 +0000 | [diff] [blame] | 69 | /* Setting Py_UNICODE_WIDE enables UCS-4 storage. Otherwise, Unicode |
| 70 | strings are stored as UCS-2 (with limited support for UTF-16) */ |
| 71 | |
| 72 | #if Py_UNICODE_SIZE >= 4 |
| 73 | #define Py_UNICODE_WIDE |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 74 | #endif |
Fredrik Lundh | 1294ad0 | 2001-06-26 17:17:07 +0000 | [diff] [blame] | 75 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 76 | /* Set these flags if the platform has "wchar.h", "wctype.h" and the |
| 77 | wchar_t type is a 16-bit unsigned type */ |
| 78 | /* #define HAVE_WCHAR_H */ |
| 79 | /* #define HAVE_USABLE_WCHAR_T */ |
| 80 | |
| 81 | /* Defaults for various platforms */ |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 82 | #ifndef PY_UNICODE_TYPE |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 83 | |
Fredrik Lundh | 1294ad0 | 2001-06-26 17:17:07 +0000 | [diff] [blame] | 84 | /* 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] | 85 | # if defined(MS_WIN32) && Py_UNICODE_SIZE == 2 |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 86 | # define HAVE_USABLE_WCHAR_T |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 87 | # define PY_UNICODE_TYPE wchar_t |
| 88 | # endif |
| 89 | |
Fredrik Lundh | 8f45585 | 2001-06-27 18:59:43 +0000 | [diff] [blame] | 90 | # if defined(Py_UNICODE_WIDE) |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 91 | # define PY_UNICODE_TYPE Py_UCS4 |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 92 | # endif |
| 93 | |
| 94 | #endif |
| 95 | |
| 96 | /* If the compiler provides a wchar_t type we try to support it |
| 97 | through the interface functions PyUnicode_FromWideChar() and |
| 98 | PyUnicode_AsWideChar(). */ |
| 99 | |
| 100 | #ifdef HAVE_USABLE_WCHAR_T |
Marc-André Lemburg | 1a731c6 | 2000-08-11 11:43:10 +0000 | [diff] [blame] | 101 | # ifndef HAVE_WCHAR_H |
| 102 | # define HAVE_WCHAR_H |
| 103 | # endif |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 104 | #endif |
| 105 | |
| 106 | #ifdef HAVE_WCHAR_H |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 107 | /* Work around a cosmetic bug in BSDI 4.x wchar.h; thanks to Thomas Wouters */ |
| 108 | # ifdef _HAVE_BSDI |
| 109 | # include <time.h> |
| 110 | # endif |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 111 | # include "wchar.h" |
| 112 | #endif |
| 113 | |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 114 | /* |
| 115 | * Use this typedef when you need to represent a UTF-16 surrogate pair |
| 116 | * as single unsigned integer. |
| 117 | */ |
| 118 | #if SIZEOF_INT >= 4 |
| 119 | typedef unsigned int Py_UCS4; |
| 120 | #elif SIZEOF_LONG >= 4 |
| 121 | typedef unsigned long Py_UCS4; |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 122 | #endif |
| 123 | |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 124 | #if SIZEOF_SHORT == 2 |
| 125 | typedef unsigned short Py_UCS2; |
| 126 | #else |
| 127 | #error Cannot find a two-byte type |
| 128 | #endif |
Marc-André Lemburg | 4327910 | 2000-07-07 09:01:41 +0000 | [diff] [blame] | 129 | |
Martin v. Löwis | 0ba70cc | 2001-06-26 22:22:37 +0000 | [diff] [blame] | 130 | typedef PY_UNICODE_TYPE Py_UNICODE; |
Marc-André Lemburg | 4327910 | 2000-07-07 09:01:41 +0000 | [diff] [blame] | 131 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 132 | /* --- Internal Unicode Operations ---------------------------------------- */ |
| 133 | |
| 134 | /* 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] | 135 | of the ones supplied with Python, define WANT_WCTYPE_FUNCTIONS or |
| 136 | configure Python using --with-ctype-functions. This reduces the |
| 137 | interpreter's code size. */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 138 | |
| 139 | #if defined(HAVE_USABLE_WCHAR_T) && defined(WANT_WCTYPE_FUNCTIONS) |
| 140 | |
| 141 | #include "wctype.h" |
| 142 | |
| 143 | #define Py_UNICODE_ISSPACE(ch) iswspace(ch) |
| 144 | |
| 145 | #define Py_UNICODE_ISLOWER(ch) iswlower(ch) |
| 146 | #define Py_UNICODE_ISUPPER(ch) iswupper(ch) |
| 147 | #define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch) |
| 148 | #define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch) |
| 149 | |
| 150 | #define Py_UNICODE_TOLOWER(ch) towlower(ch) |
| 151 | #define Py_UNICODE_TOUPPER(ch) towupper(ch) |
| 152 | #define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch) |
| 153 | |
| 154 | #define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch) |
| 155 | #define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch) |
| 156 | #define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch) |
| 157 | |
| 158 | #define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch) |
| 159 | #define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch) |
| 160 | #define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch) |
| 161 | |
Marc-André Lemburg | f03e741 | 2000-07-05 09:45:59 +0000 | [diff] [blame] | 162 | #define Py_UNICODE_ISALPHA(ch) iswalpha(ch) |
| 163 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 164 | #else |
| 165 | |
| 166 | #define Py_UNICODE_ISSPACE(ch) _PyUnicode_IsWhitespace(ch) |
| 167 | |
| 168 | #define Py_UNICODE_ISLOWER(ch) _PyUnicode_IsLowercase(ch) |
| 169 | #define Py_UNICODE_ISUPPER(ch) _PyUnicode_IsUppercase(ch) |
| 170 | #define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch) |
| 171 | #define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch) |
| 172 | |
| 173 | #define Py_UNICODE_TOLOWER(ch) _PyUnicode_ToLowercase(ch) |
| 174 | #define Py_UNICODE_TOUPPER(ch) _PyUnicode_ToUppercase(ch) |
| 175 | #define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch) |
| 176 | |
| 177 | #define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch) |
| 178 | #define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch) |
| 179 | #define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch) |
| 180 | |
| 181 | #define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch) |
| 182 | #define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch) |
| 183 | #define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch) |
| 184 | |
Marc-André Lemburg | f03e741 | 2000-07-05 09:45:59 +0000 | [diff] [blame] | 185 | #define Py_UNICODE_ISALPHA(ch) _PyUnicode_IsAlpha(ch) |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 186 | |
Marc-André Lemburg | f03e741 | 2000-07-05 09:45:59 +0000 | [diff] [blame] | 187 | #endif |
Marc-André Lemburg | a9c103b | 2000-07-03 10:52:13 +0000 | [diff] [blame] | 188 | |
| 189 | #define Py_UNICODE_ISALNUM(ch) \ |
| 190 | (Py_UNICODE_ISALPHA(ch) || \ |
| 191 | Py_UNICODE_ISDECIMAL(ch) || \ |
| 192 | Py_UNICODE_ISDIGIT(ch) || \ |
| 193 | Py_UNICODE_ISNUMERIC(ch)) |
| 194 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 195 | #define Py_UNICODE_COPY(target, source, length)\ |
| 196 | (memcpy((target), (source), (length)*sizeof(Py_UNICODE))) |
| 197 | |
| 198 | #define Py_UNICODE_FILL(target, value, length) do\ |
| 199 | {int i; for (i = 0; i < (length); i++) (target)[i] = (value);}\ |
| 200 | while (0) |
| 201 | |
| 202 | #define Py_UNICODE_MATCH(string, offset, substring)\ |
Marc-André Lemburg | 2f4d0e9 | 2000-06-18 22:22:27 +0000 | [diff] [blame] | 203 | ((*((string)->str + (offset)) == *((substring)->str)) &&\ |
| 204 | !memcmp((string)->str + (offset), (substring)->str,\ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 205 | (substring)->length*sizeof(Py_UNICODE))) |
| 206 | |
Barry Warsaw | 51ac580 | 2000-03-20 16:36:48 +0000 | [diff] [blame] | 207 | #ifdef __cplusplus |
| 208 | extern "C" { |
| 209 | #endif |
| 210 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 211 | /* --- Unicode Type ------------------------------------------------------- */ |
| 212 | |
| 213 | typedef struct { |
| 214 | PyObject_HEAD |
| 215 | int length; /* Length of raw Unicode data in buffer */ |
| 216 | Py_UNICODE *str; /* Raw Unicode buffer */ |
| 217 | long hash; /* Hash value; -1 if not set */ |
Marc-André Lemburg | bff879c | 2000-08-03 18:46:08 +0000 | [diff] [blame] | 218 | PyObject *defenc; /* (Default) Encoded version as Python |
| 219 | string, or NULL; this is used for |
| 220 | implementing the buffer protocol */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 221 | } PyUnicodeObject; |
| 222 | |
| 223 | extern DL_IMPORT(PyTypeObject) PyUnicode_Type; |
| 224 | |
| 225 | #define PyUnicode_Check(op) (((op)->ob_type == &PyUnicode_Type)) |
| 226 | |
| 227 | /* Fast access macros */ |
| 228 | #define PyUnicode_GET_SIZE(op) \ |
| 229 | (((PyUnicodeObject *)(op))->length) |
| 230 | #define PyUnicode_GET_DATA_SIZE(op) \ |
| 231 | (((PyUnicodeObject *)(op))->length * sizeof(Py_UNICODE)) |
| 232 | #define PyUnicode_AS_UNICODE(op) \ |
| 233 | (((PyUnicodeObject *)(op))->str) |
| 234 | #define PyUnicode_AS_DATA(op) \ |
| 235 | ((const char *)((PyUnicodeObject *)(op))->str) |
| 236 | |
| 237 | /* --- Constants ---------------------------------------------------------- */ |
| 238 | |
| 239 | /* This Unicode character will be used as replacement character during |
| 240 | decoding if the errors argument is set to "replace". Note: the |
| 241 | Unicode character U+FFFD is the official REPLACEMENT CHARACTER in |
| 242 | Unicode 3.0. */ |
| 243 | |
| 244 | #define Py_UNICODE_REPLACEMENT_CHARACTER ((Py_UNICODE) 0xFFFD) |
| 245 | |
| 246 | /* === Public API ========================================================= */ |
| 247 | |
| 248 | /* --- Plain Py_UNICODE --------------------------------------------------- */ |
| 249 | |
| 250 | /* Create a Unicode Object from the Py_UNICODE buffer u of the given |
Marc-André Lemburg | 8155e0e | 2001-04-23 14:44:21 +0000 | [diff] [blame] | 251 | size. |
| 252 | |
| 253 | u may be NULL which causes the contents to be undefined. It is the |
| 254 | user's responsibility to fill in the needed data afterwards. Note |
| 255 | that modifying the Unicode object contents after construction is |
| 256 | only allowed if u was set to NULL. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 257 | |
| 258 | The buffer is copied into the new object. */ |
| 259 | |
| 260 | extern DL_IMPORT(PyObject*) PyUnicode_FromUnicode( |
| 261 | const Py_UNICODE *u, /* Unicode buffer */ |
| 262 | int size /* size of buffer */ |
| 263 | ); |
| 264 | |
| 265 | /* Return a read-only pointer to the Unicode object's internal |
| 266 | Py_UNICODE buffer. */ |
| 267 | |
| 268 | extern DL_IMPORT(Py_UNICODE *) PyUnicode_AsUnicode( |
| 269 | PyObject *unicode /* Unicode object */ |
| 270 | ); |
| 271 | |
| 272 | /* Get the length of the Unicode object. */ |
| 273 | |
| 274 | extern DL_IMPORT(int) PyUnicode_GetSize( |
| 275 | PyObject *unicode /* Unicode object */ |
| 276 | ); |
| 277 | |
Martin v. Löwis | ce9b5a5 | 2001-06-27 06:28:56 +0000 | [diff] [blame] | 278 | /* Get the maximum ordinal for a Unicode character. */ |
| 279 | extern DL_IMPORT(Py_UNICODE) PyUnicode_GetMax(void); |
| 280 | |
Guido van Rossum | 52c2359 | 2000-04-10 13:41:41 +0000 | [diff] [blame] | 281 | /* Resize an already allocated Unicode object to the new size length. |
| 282 | |
| 283 | *unicode is modified to point to the new (resized) object and 0 |
| 284 | returned on success. |
| 285 | |
| 286 | This API may only be called by the function which also called the |
| 287 | Unicode constructor. The refcount on the object must be 1. Otherwise, |
| 288 | an error is returned. |
| 289 | |
| 290 | Error handling is implemented as follows: an exception is set, -1 |
| 291 | is returned and *unicode left untouched. |
| 292 | |
| 293 | */ |
| 294 | |
| 295 | extern DL_IMPORT(int) PyUnicode_Resize( |
| 296 | PyObject **unicode, /* Pointer to the Unicode object */ |
| 297 | int length /* New length */ |
| 298 | ); |
| 299 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 300 | /* Coerce obj to an Unicode object and return a reference with |
| 301 | *incremented* refcount. |
| 302 | |
| 303 | Coercion is done in the following way: |
| 304 | |
| 305 | 1. Unicode objects are passed back as-is with incremented |
| 306 | refcount. |
| 307 | |
| 308 | 2. String and other char buffer compatible objects are decoded |
Fred Drake | cb093fe | 2000-05-09 19:51:53 +0000 | [diff] [blame] | 309 | under the assumptions that they contain data using the current |
| 310 | default encoding. Decoding is done in "strict" mode. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 311 | |
| 312 | 3. All other objects raise an exception. |
| 313 | |
| 314 | The API returns NULL in case of an error. The caller is responsible |
| 315 | for decref'ing the returned objects. |
| 316 | |
| 317 | */ |
| 318 | |
Marc-André Lemburg | 5a5c81a | 2000-07-07 13:46:42 +0000 | [diff] [blame] | 319 | extern DL_IMPORT(PyObject*) PyUnicode_FromEncodedObject( |
| 320 | register PyObject *obj, /* Object */ |
| 321 | const char *encoding, /* encoding */ |
| 322 | const char *errors /* error handling */ |
| 323 | ); |
| 324 | |
| 325 | /* Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict"); |
| 326 | which results in using the default encoding as basis for |
| 327 | decoding the object. |
| 328 | |
| 329 | Coerces obj to an Unicode object and return a reference with |
| 330 | *incremented* refcount. |
| 331 | |
| 332 | The API returns NULL in case of an error. The caller is responsible |
| 333 | for decref'ing the returned objects. |
| 334 | |
| 335 | */ |
| 336 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 337 | extern DL_IMPORT(PyObject*) PyUnicode_FromObject( |
| 338 | register PyObject *obj /* Object */ |
| 339 | ); |
| 340 | |
| 341 | /* --- wchar_t support for platforms which support it --------------------- */ |
| 342 | |
| 343 | #ifdef HAVE_WCHAR_H |
| 344 | |
| 345 | /* Create a Unicode Object from the whcar_t buffer w of the given |
| 346 | size. |
| 347 | |
| 348 | The buffer is copied into the new object. */ |
| 349 | |
| 350 | extern DL_IMPORT(PyObject*) PyUnicode_FromWideChar( |
| 351 | register const wchar_t *w, /* wchar_t buffer */ |
| 352 | int size /* size of buffer */ |
| 353 | ); |
| 354 | |
| 355 | /* Copies the Unicode Object contents into the whcar_t buffer w. At |
| 356 | most size wchar_t characters are copied. |
| 357 | |
| 358 | Returns the number of wchar_t characters copied or -1 in case of an |
| 359 | error. */ |
| 360 | |
| 361 | extern DL_IMPORT(int) PyUnicode_AsWideChar( |
| 362 | PyUnicodeObject *unicode, /* Unicode object */ |
| 363 | register wchar_t *w, /* wchar_t buffer */ |
| 364 | int size /* size of buffer */ |
| 365 | ); |
| 366 | |
| 367 | #endif |
| 368 | |
| 369 | /* === Builtin Codecs ===================================================== |
| 370 | |
| 371 | Many of these APIs take two arguments encoding and errors. These |
| 372 | parameters encoding and errors have the same semantics as the ones |
| 373 | of the builtin unicode() API. |
| 374 | |
Fred Drake | cb093fe | 2000-05-09 19:51:53 +0000 | [diff] [blame] | 375 | Setting encoding to NULL causes the default encoding to be used. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 376 | |
| 377 | Error handling is set by errors which may also be set to NULL |
| 378 | meaning to use the default handling defined for the codec. Default |
| 379 | error handling for all builtin codecs is "strict" (ValueErrors are |
| 380 | raised). |
| 381 | |
| 382 | The codecs all use a similar interface. Only deviation from the |
| 383 | generic ones are documented. |
| 384 | |
| 385 | */ |
| 386 | |
Fred Drake | cb093fe | 2000-05-09 19:51:53 +0000 | [diff] [blame] | 387 | /* --- Manage the default encoding ---------------------------------------- */ |
| 388 | |
| 389 | /* Returns the currently active default encoding. |
| 390 | |
| 391 | The default encoding is currently implemented as run-time settable |
| 392 | process global. This may change in future versions of the |
| 393 | interpreter to become a parameter which is managed on a per-thread |
| 394 | basis. |
| 395 | |
| 396 | */ |
| 397 | |
Thomas Wouters | 5f37591 | 2000-07-22 23:30:03 +0000 | [diff] [blame] | 398 | extern DL_IMPORT(const char*) PyUnicode_GetDefaultEncoding(void); |
Fred Drake | cb093fe | 2000-05-09 19:51:53 +0000 | [diff] [blame] | 399 | |
| 400 | /* Sets the currently active default encoding. |
| 401 | |
| 402 | Returns 0 on success, -1 in case of an error. |
| 403 | |
| 404 | */ |
| 405 | |
| 406 | extern DL_IMPORT(int) PyUnicode_SetDefaultEncoding( |
| 407 | const char *encoding /* Encoding name in standard form */ |
| 408 | ); |
| 409 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 410 | /* --- Generic Codecs ----------------------------------------------------- */ |
| 411 | |
| 412 | /* Create a Unicode object by decoding the encoded string s of the |
| 413 | given size. */ |
| 414 | |
| 415 | extern DL_IMPORT(PyObject*) PyUnicode_Decode( |
| 416 | const char *s, /* encoded string */ |
| 417 | int size, /* size of buffer */ |
| 418 | const char *encoding, /* encoding */ |
| 419 | const char *errors /* error handling */ |
| 420 | ); |
| 421 | |
| 422 | /* Encodes a Py_UNICODE buffer of the given size and returns a |
| 423 | Python string object. */ |
| 424 | |
| 425 | extern DL_IMPORT(PyObject*) PyUnicode_Encode( |
| 426 | const Py_UNICODE *s, /* Unicode char buffer */ |
| 427 | int size, /* number of Py_UNICODE chars to encode */ |
| 428 | const char *encoding, /* encoding */ |
| 429 | const char *errors /* error handling */ |
| 430 | ); |
| 431 | |
| 432 | /* Encodes a Unicode object and returns the result as Python string |
| 433 | object. */ |
| 434 | |
| 435 | extern DL_IMPORT(PyObject*) PyUnicode_AsEncodedString( |
| 436 | PyObject *unicode, /* Unicode object */ |
| 437 | const char *encoding, /* encoding */ |
| 438 | const char *errors /* error handling */ |
| 439 | ); |
| 440 | |
| 441 | /* --- UTF-8 Codecs ------------------------------------------------------- */ |
| 442 | |
| 443 | extern DL_IMPORT(PyObject*) PyUnicode_DecodeUTF8( |
| 444 | const char *string, /* UTF-8 encoded string */ |
| 445 | int length, /* size of string */ |
| 446 | const char *errors /* error handling */ |
| 447 | ); |
| 448 | |
| 449 | extern DL_IMPORT(PyObject*) PyUnicode_AsUTF8String( |
| 450 | PyObject *unicode /* Unicode object */ |
| 451 | ); |
| 452 | |
| 453 | extern DL_IMPORT(PyObject*) PyUnicode_EncodeUTF8( |
| 454 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 455 | int length, /* number of Py_UNICODE chars to encode */ |
| 456 | const char *errors /* error handling */ |
| 457 | ); |
| 458 | |
| 459 | /* --- UTF-16 Codecs ------------------------------------------------------ */ |
| 460 | |
Guido van Rossum | 9e896b3 | 2000-04-05 20:11:21 +0000 | [diff] [blame] | 461 | /* 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] | 462 | the corresponding Unicode object. |
| 463 | |
| 464 | errors (if non-NULL) defines the error handling. It defaults |
| 465 | to "strict". |
| 466 | |
| 467 | If byteorder is non-NULL, the decoder starts decoding using the |
| 468 | given byte order: |
| 469 | |
| 470 | *byteorder == -1: little endian |
| 471 | *byteorder == 0: native order |
| 472 | *byteorder == 1: big endian |
| 473 | |
Marc-André Lemburg | 489b56e | 2001-05-21 20:30:15 +0000 | [diff] [blame] | 474 | In native mode, the first two bytes of the stream are checked for a |
| 475 | BOM mark. If found, the BOM mark is analysed, the byte order |
| 476 | adjusted and the BOM skipped. In the other modes, no BOM mark |
| 477 | interpretation is done. After completion, *byteorder is set to the |
| 478 | current byte order at the end of input data. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 479 | |
| 480 | If byteorder is NULL, the codec starts in native order mode. |
| 481 | |
| 482 | */ |
| 483 | |
| 484 | extern DL_IMPORT(PyObject*) PyUnicode_DecodeUTF16( |
| 485 | const char *string, /* UTF-16 encoded string */ |
| 486 | int length, /* size of string */ |
| 487 | const char *errors, /* error handling */ |
| 488 | int *byteorder /* pointer to byteorder to use |
| 489 | 0=native;-1=LE,1=BE; updated on |
| 490 | exit */ |
| 491 | ); |
| 492 | |
| 493 | /* Returns a Python string using the UTF-16 encoding in native byte |
| 494 | order. The string always starts with a BOM mark. */ |
| 495 | |
| 496 | extern DL_IMPORT(PyObject*) PyUnicode_AsUTF16String( |
| 497 | PyObject *unicode /* Unicode object */ |
| 498 | ); |
| 499 | |
| 500 | /* 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] | 501 | the Unicode data. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 502 | |
| 503 | If byteorder is not 0, output is written according to the following |
| 504 | byte order: |
| 505 | |
| 506 | byteorder == -1: little endian |
| 507 | byteorder == 0: native byte order (writes a BOM mark) |
| 508 | byteorder == 1: big endian |
| 509 | |
| 510 | If byteorder is 0, the output string will always start with the |
| 511 | Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is |
| 512 | prepended. |
| 513 | |
| 514 | Note that Py_UNICODE data is being interpreted as UTF-16 reduced to |
| 515 | 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] | 516 | at a later point without compromising the APIs. |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 517 | |
| 518 | */ |
| 519 | |
| 520 | extern DL_IMPORT(PyObject*) PyUnicode_EncodeUTF16( |
| 521 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 522 | int length, /* number of Py_UNICODE chars to encode */ |
| 523 | const char *errors, /* error handling */ |
| 524 | int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */ |
| 525 | ); |
| 526 | |
| 527 | /* --- Unicode-Escape Codecs ---------------------------------------------- */ |
| 528 | |
| 529 | extern DL_IMPORT(PyObject*) PyUnicode_DecodeUnicodeEscape( |
| 530 | const char *string, /* Unicode-Escape encoded string */ |
| 531 | int length, /* size of string */ |
| 532 | const char *errors /* error handling */ |
| 533 | ); |
| 534 | |
| 535 | extern DL_IMPORT(PyObject*) PyUnicode_AsUnicodeEscapeString( |
| 536 | PyObject *unicode /* Unicode object */ |
| 537 | ); |
| 538 | |
| 539 | extern DL_IMPORT(PyObject*) PyUnicode_EncodeUnicodeEscape( |
| 540 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 541 | int length /* Number of Py_UNICODE chars to encode */ |
| 542 | ); |
| 543 | |
| 544 | /* --- Raw-Unicode-Escape Codecs ------------------------------------------ */ |
| 545 | |
| 546 | extern DL_IMPORT(PyObject*) PyUnicode_DecodeRawUnicodeEscape( |
| 547 | const char *string, /* Raw-Unicode-Escape encoded string */ |
| 548 | int length, /* size of string */ |
| 549 | const char *errors /* error handling */ |
| 550 | ); |
| 551 | |
| 552 | extern DL_IMPORT(PyObject*) PyUnicode_AsRawUnicodeEscapeString( |
| 553 | PyObject *unicode /* Unicode object */ |
| 554 | ); |
| 555 | |
| 556 | extern DL_IMPORT(PyObject*) PyUnicode_EncodeRawUnicodeEscape( |
| 557 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 558 | int length /* Number of Py_UNICODE chars to encode */ |
| 559 | ); |
| 560 | |
| 561 | /* --- Latin-1 Codecs ----------------------------------------------------- |
| 562 | |
| 563 | Note: Latin-1 corresponds to the first 256 Unicode ordinals. |
| 564 | |
| 565 | */ |
| 566 | |
| 567 | extern DL_IMPORT(PyObject*) PyUnicode_DecodeLatin1( |
| 568 | const char *string, /* Latin-1 encoded string */ |
| 569 | int length, /* size of string */ |
| 570 | const char *errors /* error handling */ |
| 571 | ); |
| 572 | |
| 573 | extern DL_IMPORT(PyObject*) PyUnicode_AsLatin1String( |
| 574 | PyObject *unicode /* Unicode object */ |
| 575 | ); |
| 576 | |
| 577 | extern DL_IMPORT(PyObject*) PyUnicode_EncodeLatin1( |
| 578 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 579 | int length, /* Number of Py_UNICODE chars to encode */ |
| 580 | const char *errors /* error handling */ |
| 581 | ); |
| 582 | |
| 583 | /* --- ASCII Codecs ------------------------------------------------------- |
| 584 | |
| 585 | Only 7-bit ASCII data is excepted. All other codes generate errors. |
| 586 | |
| 587 | */ |
| 588 | |
| 589 | extern DL_IMPORT(PyObject*) PyUnicode_DecodeASCII( |
| 590 | const char *string, /* ASCII encoded string */ |
| 591 | int length, /* size of string */ |
| 592 | const char *errors /* error handling */ |
| 593 | ); |
| 594 | |
| 595 | extern DL_IMPORT(PyObject*) PyUnicode_AsASCIIString( |
| 596 | PyObject *unicode /* Unicode object */ |
| 597 | ); |
| 598 | |
| 599 | extern DL_IMPORT(PyObject*) PyUnicode_EncodeASCII( |
| 600 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 601 | int length, /* Number of Py_UNICODE chars to encode */ |
| 602 | const char *errors /* error handling */ |
| 603 | ); |
| 604 | |
| 605 | /* --- Character Map Codecs ----------------------------------------------- |
| 606 | |
| 607 | This codec uses mappings to encode and decode characters. |
| 608 | |
| 609 | Decoding mappings must map single string characters to single |
| 610 | Unicode characters, integers (which are then interpreted as Unicode |
| 611 | ordinals) or None (meaning "undefined mapping" and causing an |
| 612 | error). |
| 613 | |
| 614 | Encoding mappings must map single Unicode characters to single |
| 615 | string characters, integers (which are then interpreted as Latin-1 |
| 616 | ordinals) or None (meaning "undefined mapping" and causing an |
| 617 | error). |
| 618 | |
| 619 | If a character lookup fails with a LookupError, the character is |
| 620 | copied as-is meaning that its ordinal value will be interpreted as |
| 621 | Unicode or Latin-1 ordinal resp. Because of this mappings only need |
| 622 | to contain those mappings which map characters to different code |
| 623 | points. |
| 624 | |
| 625 | */ |
| 626 | |
| 627 | extern DL_IMPORT(PyObject*) PyUnicode_DecodeCharmap( |
| 628 | const char *string, /* Encoded string */ |
| 629 | int length, /* size of string */ |
| 630 | PyObject *mapping, /* character mapping |
| 631 | (char ordinal -> unicode ordinal) */ |
| 632 | const char *errors /* error handling */ |
| 633 | ); |
| 634 | |
| 635 | extern DL_IMPORT(PyObject*) PyUnicode_AsCharmapString( |
| 636 | PyObject *unicode, /* Unicode object */ |
| 637 | PyObject *mapping /* character mapping |
| 638 | (unicode ordinal -> char ordinal) */ |
| 639 | ); |
| 640 | |
| 641 | extern DL_IMPORT(PyObject*) PyUnicode_EncodeCharmap( |
| 642 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 643 | int length, /* Number of Py_UNICODE chars to encode */ |
| 644 | PyObject *mapping, /* character mapping |
| 645 | (unicode ordinal -> char ordinal) */ |
| 646 | const char *errors /* error handling */ |
| 647 | ); |
| 648 | |
| 649 | /* Translate a Py_UNICODE buffer of the given length by applying a |
| 650 | character mapping table to it and return the resulting Unicode |
| 651 | object. |
| 652 | |
| 653 | The mapping table must map Unicode ordinal integers to Unicode |
| 654 | ordinal integers or None (causing deletion of the character). |
| 655 | |
| 656 | Mapping tables may be dictionaries or sequences. Unmapped character |
| 657 | ordinals (ones which cause a LookupError) are left untouched and |
| 658 | are copied as-is. |
| 659 | |
| 660 | */ |
| 661 | |
| 662 | extern DL_IMPORT(PyObject *) PyUnicode_TranslateCharmap( |
| 663 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 664 | int length, /* Number of Py_UNICODE chars to encode */ |
| 665 | PyObject *table, /* Translate table */ |
| 666 | const char *errors /* error handling */ |
| 667 | ); |
| 668 | |
Guido van Rossum | efec115 | 2000-03-28 02:01:15 +0000 | [diff] [blame] | 669 | #ifdef MS_WIN32 |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 670 | |
Guido van Rossum | efec115 | 2000-03-28 02:01:15 +0000 | [diff] [blame] | 671 | /* --- MBCS codecs for Windows -------------------------------------------- */ |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 672 | |
Guido van Rossum | efec115 | 2000-03-28 02:01:15 +0000 | [diff] [blame] | 673 | extern DL_IMPORT(PyObject*) PyUnicode_DecodeMBCS( |
| 674 | const char *string, /* MBCS encoded string */ |
| 675 | int length, /* size of string */ |
| 676 | const char *errors /* error handling */ |
| 677 | ); |
| 678 | |
| 679 | extern DL_IMPORT(PyObject*) PyUnicode_AsMBCSString( |
| 680 | PyObject *unicode /* Unicode object */ |
| 681 | ); |
| 682 | |
| 683 | extern DL_IMPORT(PyObject*) PyUnicode_EncodeMBCS( |
| 684 | const Py_UNICODE *data, /* Unicode char buffer */ |
| 685 | int length, /* Number of Py_UNICODE chars to encode */ |
| 686 | const char *errors /* error handling */ |
| 687 | ); |
| 688 | |
Guido van Rossum | efec115 | 2000-03-28 02:01:15 +0000 | [diff] [blame] | 689 | #endif /* MS_WIN32 */ |
Guido van Rossum | 24bdb04 | 2000-03-28 20:29:59 +0000 | [diff] [blame] | 690 | |
Guido van Rossum | 9e896b3 | 2000-04-05 20:11:21 +0000 | [diff] [blame] | 691 | /* --- Decimal Encoder ---------------------------------------------------- */ |
| 692 | |
| 693 | /* Takes a Unicode string holding a decimal value and writes it into |
| 694 | an output buffer using standard ASCII digit codes. |
| 695 | |
| 696 | The output buffer has to provide at least length+1 bytes of storage |
| 697 | area. The output string is 0-terminated. |
| 698 | |
| 699 | The encoder converts whitespace to ' ', decimal characters to their |
| 700 | corresponding ASCII digit and all other Latin-1 characters except |
| 701 | \0 as-is. Characters outside this range (Unicode ordinals 1-256) |
| 702 | are treated as errors. This includes embedded NULL bytes. |
| 703 | |
| 704 | Error handling is defined by the errors argument: |
| 705 | |
| 706 | NULL or "strict": raise a ValueError |
| 707 | "ignore": ignore the wrong characters (these are not copied to the |
| 708 | output buffer) |
| 709 | "replace": replaces illegal characters with '?' |
| 710 | |
| 711 | Returns 0 on success, -1 on failure. |
| 712 | |
| 713 | */ |
| 714 | |
| 715 | extern DL_IMPORT(int) PyUnicode_EncodeDecimal( |
| 716 | Py_UNICODE *s, /* Unicode buffer */ |
| 717 | int length, /* Number of Py_UNICODE chars to encode */ |
| 718 | char *output, /* Output buffer; must have size >= length */ |
| 719 | const char *errors /* error handling */ |
| 720 | ); |
| 721 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 722 | /* --- Methods & Slots ---------------------------------------------------- |
| 723 | |
| 724 | These are capable of handling Unicode objects and strings on input |
| 725 | (we refer to them as strings in the descriptions) and return |
| 726 | Unicode objects or integers as apporpriate. */ |
| 727 | |
| 728 | /* Concat two strings giving a new Unicode string. */ |
| 729 | |
| 730 | extern DL_IMPORT(PyObject*) PyUnicode_Concat( |
| 731 | PyObject *left, /* Left string */ |
| 732 | PyObject *right /* Right string */ |
| 733 | ); |
| 734 | |
| 735 | /* Split a string giving a list of Unicode strings. |
| 736 | |
| 737 | If sep is NULL, splitting will be done at all whitespace |
| 738 | substrings. Otherwise, splits occur at the given separator. |
| 739 | |
| 740 | At most maxsplit splits will be done. If negative, no limit is set. |
| 741 | |
| 742 | Separators are not included in the resulting list. |
| 743 | |
| 744 | */ |
| 745 | |
| 746 | extern DL_IMPORT(PyObject*) PyUnicode_Split( |
| 747 | PyObject *s, /* String to split */ |
| 748 | PyObject *sep, /* String separator */ |
| 749 | int maxsplit /* Maxsplit count */ |
| 750 | ); |
| 751 | |
| 752 | /* Dito, but split at line breaks. |
| 753 | |
| 754 | CRLF is considered to be one line break. Line breaks are not |
| 755 | included in the resulting list. */ |
| 756 | |
| 757 | extern DL_IMPORT(PyObject*) PyUnicode_Splitlines( |
| 758 | PyObject *s, /* String to split */ |
Guido van Rossum | 004d64f | 2000-04-11 15:39:46 +0000 | [diff] [blame] | 759 | int keepends /* If true, line end markers are included */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 760 | ); |
| 761 | |
| 762 | /* Translate a string by applying a character mapping table to it and |
| 763 | return the resulting Unicode object. |
| 764 | |
| 765 | The mapping table must map Unicode ordinal integers to Unicode |
| 766 | ordinal integers or None (causing deletion of the character). |
| 767 | |
| 768 | Mapping tables may be dictionaries or sequences. Unmapped character |
| 769 | ordinals (ones which cause a LookupError) are left untouched and |
| 770 | are copied as-is. |
| 771 | |
| 772 | */ |
| 773 | |
| 774 | extern DL_IMPORT(PyObject *) PyUnicode_Translate( |
| 775 | PyObject *str, /* String */ |
| 776 | PyObject *table, /* Translate table */ |
| 777 | const char *errors /* error handling */ |
| 778 | ); |
| 779 | |
| 780 | /* Join a sequence of strings using the given separator and return |
| 781 | the resulting Unicode string. */ |
| 782 | |
| 783 | extern DL_IMPORT(PyObject*) PyUnicode_Join( |
| 784 | PyObject *separator, /* Separator string */ |
| 785 | PyObject *seq /* Sequence object */ |
| 786 | ); |
| 787 | |
| 788 | /* Return 1 if substr matches str[start:end] at the given tail end, 0 |
| 789 | otherwise. */ |
| 790 | |
| 791 | extern DL_IMPORT(int) PyUnicode_Tailmatch( |
| 792 | PyObject *str, /* String */ |
| 793 | PyObject *substr, /* Prefix or Suffix string */ |
| 794 | int start, /* Start index */ |
| 795 | int end, /* Stop index */ |
| 796 | int direction /* Tail end: -1 prefix, +1 suffix */ |
| 797 | ); |
| 798 | |
| 799 | /* Return the first position of substr in str[start:end] using the |
| 800 | given search direction or -1 if not found. */ |
| 801 | |
| 802 | extern DL_IMPORT(int) PyUnicode_Find( |
| 803 | PyObject *str, /* String */ |
| 804 | PyObject *substr, /* Substring to find */ |
| 805 | int start, /* Start index */ |
| 806 | int end, /* Stop index */ |
| 807 | int direction /* Find direction: +1 forward, -1 backward */ |
| 808 | ); |
| 809 | |
Barry Warsaw | 51ac580 | 2000-03-20 16:36:48 +0000 | [diff] [blame] | 810 | /* Count the number of occurrences of substr in str[start:end]. */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 811 | |
| 812 | extern DL_IMPORT(int) PyUnicode_Count( |
| 813 | PyObject *str, /* String */ |
| 814 | PyObject *substr, /* Substring to count */ |
| 815 | int start, /* Start index */ |
| 816 | int end /* Stop index */ |
| 817 | ); |
| 818 | |
Barry Warsaw | 51ac580 | 2000-03-20 16:36:48 +0000 | [diff] [blame] | 819 | /* Replace at most maxcount occurrences of substr in str with replstr |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 820 | and return the resulting Unicode object. */ |
| 821 | |
| 822 | extern DL_IMPORT(PyObject *) PyUnicode_Replace( |
| 823 | PyObject *str, /* String */ |
| 824 | PyObject *substr, /* Substring to find */ |
| 825 | PyObject *replstr, /* Substring to replace */ |
| 826 | int maxcount /* Max. number of replacements to apply; |
| 827 | -1 = all */ |
| 828 | ); |
| 829 | |
| 830 | /* Compare two strings and return -1, 0, 1 for less than, equal, |
| 831 | greater than resp. */ |
| 832 | |
| 833 | extern DL_IMPORT(int) PyUnicode_Compare( |
| 834 | PyObject *left, /* Left string */ |
| 835 | PyObject *right /* Right string */ |
| 836 | ); |
| 837 | |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 838 | /* 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] | 839 | the resulting Unicode string. */ |
| 840 | |
| 841 | extern DL_IMPORT(PyObject *) PyUnicode_Format( |
| 842 | PyObject *format, /* Format string */ |
| 843 | PyObject *args /* Argument tuple or dictionary */ |
| 844 | ); |
| 845 | |
Guido van Rossum | d0d366b | 2000-03-13 23:22:24 +0000 | [diff] [blame] | 846 | /* Checks whether element is contained in container and return 1/0 |
| 847 | accordingly. |
| 848 | |
| 849 | element has to coerce to an one element Unicode string. -1 is |
| 850 | returned in case of an error. */ |
| 851 | |
| 852 | extern DL_IMPORT(int) PyUnicode_Contains( |
| 853 | PyObject *container, /* Container string */ |
| 854 | PyObject *element /* Element string */ |
| 855 | ); |
| 856 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 857 | /* === Characters Type APIs =============================================== */ |
| 858 | |
| 859 | /* These should not be used directly. Use the Py_UNICODE_IS* and |
| 860 | Py_UNICODE_TO* macros instead. |
| 861 | |
| 862 | These APIs are implemented in Objects/unicodectype.c. |
| 863 | |
| 864 | */ |
| 865 | |
| 866 | extern DL_IMPORT(int) _PyUnicode_IsLowercase( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 867 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 868 | ); |
| 869 | |
| 870 | extern DL_IMPORT(int) _PyUnicode_IsUppercase( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 871 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 872 | ); |
| 873 | |
| 874 | extern DL_IMPORT(int) _PyUnicode_IsTitlecase( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 875 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 876 | ); |
| 877 | |
| 878 | extern DL_IMPORT(int) _PyUnicode_IsWhitespace( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 879 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 880 | ); |
| 881 | |
| 882 | extern DL_IMPORT(int) _PyUnicode_IsLinebreak( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 883 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 884 | ); |
| 885 | |
| 886 | extern DL_IMPORT(Py_UNICODE) _PyUnicode_ToLowercase( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 887 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 888 | ); |
| 889 | |
| 890 | extern DL_IMPORT(Py_UNICODE) _PyUnicode_ToUppercase( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 891 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 892 | ); |
| 893 | |
| 894 | extern DL_IMPORT(Py_UNICODE) _PyUnicode_ToTitlecase( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 895 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 896 | ); |
| 897 | |
| 898 | extern DL_IMPORT(int) _PyUnicode_ToDecimalDigit( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 899 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 900 | ); |
| 901 | |
| 902 | extern DL_IMPORT(int) _PyUnicode_ToDigit( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 903 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 904 | ); |
| 905 | |
| 906 | extern DL_IMPORT(double) _PyUnicode_ToNumeric( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 907 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 908 | ); |
| 909 | |
| 910 | extern DL_IMPORT(int) _PyUnicode_IsDecimalDigit( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 911 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 912 | ); |
| 913 | |
| 914 | extern DL_IMPORT(int) _PyUnicode_IsDigit( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 915 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 916 | ); |
| 917 | |
| 918 | extern DL_IMPORT(int) _PyUnicode_IsNumeric( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 919 | Py_UNICODE ch /* Unicode character */ |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 920 | ); |
| 921 | |
Marc-André Lemburg | f03e741 | 2000-07-05 09:45:59 +0000 | [diff] [blame] | 922 | extern DL_IMPORT(int) _PyUnicode_IsAlpha( |
Fredrik Lundh | 72b0685 | 2001-06-27 22:08:26 +0000 | [diff] [blame] | 923 | Py_UNICODE ch /* Unicode character */ |
Marc-André Lemburg | f03e741 | 2000-07-05 09:45:59 +0000 | [diff] [blame] | 924 | ); |
| 925 | |
Guido van Rossum | d822518 | 2000-03-10 22:33:05 +0000 | [diff] [blame] | 926 | #ifdef __cplusplus |
| 927 | } |
| 928 | #endif |
| 929 | #endif /* !Py_UNICODEOBJECT_H */ |