1 /** 2 Mirror _unicodeobject.h 3 4 Unicode API names are mangled to assure that UCS-2 and UCS-4 builds 5 produce different external names and thus cause import errors in 6 case Python interpreters and extensions with mixed compiled in 7 Unicode width assumptions are combined. 8 */ 9 module deimos.python.unicodeobject; 10 11 import core.stdc.stdarg; 12 import core.stdc..string; 13 import deimos.python.pyport; 14 import deimos.python.object; 15 16 extern(C): 17 // Python-header-file: Include/unicodeobject.h: 18 19 /** Py_UNICODE is the native Unicode storage format (code unit) used by 20 Python and represents a single Unicode element in the Unicode 21 type. */ 22 version (Python_Unicode_UCS2) { 23 version (Windows) { 24 alias wchar Py_UNICODE; 25 } else { 26 alias ushort Py_UNICODE; 27 } 28 } else { 29 alias uint Py_UNICODE; 30 } 31 alias Py_UNICODE Py_UCS4; 32 33 /** 34 subclass of PyObject. 35 */ 36 struct PyUnicodeObject { 37 mixin PyObject_HEAD; 38 /** Length of raw Unicode data in buffer */ 39 Py_ssize_t length; 40 /** Raw Unicode buffer */ 41 Py_UNICODE* str; 42 /** Hash value; -1 if not set */ 43 C_long hash; 44 /** (Default) Encoded version as Python 45 string, or NULL; this is used for 46 implementing the buffer protocol */ 47 PyObject* defenc; 48 } 49 50 /// _ 51 mixin(PyAPI_DATA!"PyTypeObject PyUnicode_Type"); 52 53 // D translations of C macros: 54 /** Fast access macros */ 55 int PyUnicode_Check()(PyObject* op) { 56 return PyObject_TypeCheck(op, &PyUnicode_Type); 57 } 58 /// ditto 59 int PyUnicode_CheckExact()(PyObject* op) { 60 return Py_TYPE(op) == &PyUnicode_Type; 61 } 62 63 /// ditto 64 size_t PyUnicode_GET_SIZE()(PyUnicodeObject* op) { 65 return op.length; 66 } 67 /// ditto 68 size_t PyUnicode_GET_DATA_SIZE()(PyUnicodeObject* op) { 69 return op.length * Py_UNICODE.sizeof; 70 } 71 /// ditto 72 Py_UNICODE* PyUnicode_AS_UNICODE()(PyUnicodeObject* op) { 73 return op.str; 74 } 75 /// ditto 76 const(char)* PyUnicode_AS_DATA()(PyUnicodeObject* op) { 77 return cast(const(char)*) op.str; 78 } 79 80 /** This Unicode character will be used as replacement character during 81 decoding if the errors argument is set to "replace". Note: the 82 Unicode character U+FFFD is the official REPLACEMENT CHARACTER in 83 Unicode 3.0. */ 84 enum Py_UNICODE Py_UNICODE_REPLACEMENT_CHARACTER = 0xFFFD; 85 86 version(Python_3_3_Or_Later) { 87 enum PyUnicode_ = "PyUnicode_"; 88 }else version(Python_Unicode_UCS2) { 89 enum PyUnicode_ = "PyUnicodeUCS2_"; 90 }else{ 91 enum PyUnicode_ = "PyUnicodeUCS4_"; 92 } 93 94 /* 95 this function takes defs PyUnicode_XX and transforms them to 96 PyUnicodeUCS4_XX(); 97 alias PyUnicodeUCS4_XX PyUnicode_XX; 98 99 */ 100 string substitute_and_alias()(string code) { 101 import std.algorithm; 102 import std.array; 103 string[] newcodes; 104 LOOP: 105 while(true) { 106 if(startsWith(code,"/*")) { 107 size_t comm_end_index = countUntil(code[2 .. $], "*/"); 108 if(comm_end_index == -1) break; 109 newcodes ~= code[0 .. comm_end_index]; 110 code = code[comm_end_index .. $]; 111 continue; 112 } 113 if(!(startsWith(code,"PyUnicode_") || startsWith(code,"_PyUnicode"))) { 114 size_t index = 0; 115 while(index < code.length) { 116 if(code[index] == '_') { 117 if(startsWith(code[index .. $], "_PyUnicode_")) { 118 break; 119 } 120 }else if(code[index] == 'P') { 121 if(startsWith(code[index .. $], "PyUnicode_")) { 122 break; 123 } 124 }else if(code[index] == '/') { 125 if(startsWith(code[index .. $], "/*")) { 126 break; 127 } 128 } 129 index++; 130 } 131 if(index == code.length) break; 132 newcodes ~= code[0 .. index]; 133 code = code[index .. $]; 134 continue; 135 } 136 size_t end_index = countUntil(code, "("); 137 if(end_index == -1) break; 138 string alias_name = code[0 .. end_index]; 139 string func_name = replace(alias_name, "PyUnicode_", PyUnicode_); 140 size_t index0 = end_index+1; 141 int parencount = 1; 142 while(parencount && index0 < code.length) { 143 if(startsWith(code[index0 .. $], "/*")) { 144 size_t comm_end_index = countUntil(code[index0+2 .. $], "*/"); 145 if(comm_end_index == -1) break LOOP; 146 index0 += comm_end_index; 147 continue; 148 }else if(code[index0] == '(') { 149 parencount++; 150 index0++; 151 }else if(code[index0] == ')') { 152 parencount--; 153 index0++; 154 }else{ 155 index0++; 156 } 157 } 158 size_t semi = countUntil(code[index0 .. $], ";"); 159 if(semi == -1) break; 160 index0 += semi+1; 161 162 string alias_line = "\nalias " ~ func_name ~ " " ~ alias_name ~ ";\n"; 163 newcodes ~= func_name; 164 newcodes ~= code[end_index .. index0]; 165 newcodes ~= "\n /// ditto \n"; 166 newcodes ~= alias_line; 167 168 code = code[index0 .. $]; 169 } 170 171 string newcode; 172 foreach(c; newcodes) { 173 newcode ~= c; 174 } 175 return newcode; 176 } 177 178 enum string unicode_funs = q{ 179 version(Python_2_6_Or_Later) { 180 181 /** Create a Unicode Object from the Py_UNICODE buffer u of the given 182 size. 183 184 u may be NULL which causes the contents to be undefined. It is the 185 user's responsibility to fill in the needed data afterwards. Note 186 that modifying the Unicode object contents after construction is 187 only allowed if u was set to NULL. 188 189 The buffer is copied into the new object. */ 190 /// Availability: >= 2.6 191 PyObject* PyUnicode_FromUnicode(Py_UNICODE* u, Py_ssize_t size); 192 193 /** Similar to PyUnicode_FromUnicode(), but u points to Latin-1 encoded bytes */ 194 /// Availability: >= 2.6 195 PyObject* PyUnicode_FromStringAndSize( 196 const(char)*u, /* char buffer */ 197 Py_ssize_t size /* size of buffer */ 198 ); 199 200 /** Similar to PyUnicode_FromUnicode(), but u points to null-terminated 201 Latin-1 encoded bytes */ 202 /// Availability: >= 2.6 203 PyObject* PyUnicode_FromString( 204 const(char)*u /* string */ 205 ); 206 /// Availability: >= 2.6 207 PyObject* PyUnicode_FromFormatV(const(char)*, va_list); 208 /// Availability: >= 2.6 209 PyObject* PyUnicode_FromFormat(const(char)*, ...); 210 211 /** Format the object based on the format_spec, as defined in PEP 3101 212 (Advanced String Formatting). */ 213 /// Availability: >= 2.6 214 PyObject* _PyUnicode_FormatAdvanced(PyObject *obj, 215 Py_UNICODE *format_spec, 216 Py_ssize_t format_spec_len); 217 /// Availability: >= 2.6 218 int PyUnicode_ClearFreeList(); 219 /** 220 Params: 221 string = UTF-7 encoded string 222 length = size of string 223 error = error handling 224 consumed = bytes consumed 225 */ 226 /// Availability: >= 2.6 227 PyObject* PyUnicode_DecodeUTF7Stateful( 228 const(char)* string, 229 Py_ssize_t length, 230 const(char)*errors, 231 Py_ssize_t *consumed 232 ); 233 /** 234 Params: 235 string = UTF-32 encoded string 236 length = size of string 237 error = error handling 238 byteorder = pointer to byteorder to use 0=native;-1=LE,1=BE; updated on exit 239 */ 240 /// Availability: >= 2.6 241 PyObject* PyUnicode_DecodeUTF32( 242 const(char)* string, 243 Py_ssize_t length, 244 const(char)*errors, 245 int *byteorder 246 ); 247 248 /** 249 Params: 250 string = UTF-32 encoded string 251 length = size of string 252 error = error handling 253 byteorder = pointer to byteorder to use 0=native;-1=LE,1=BE; updated on exit 254 */ 255 /// Availability: >= 2.6 256 PyObject* PyUnicode_DecodeUTF32Stateful( 257 const(char)*string, 258 Py_ssize_t length, 259 const(char)*errors, 260 int *byteorder, 261 Py_ssize_t *consumed 262 ); 263 /** Returns a Python string using the UTF-32 encoding in native byte 264 order. The string always starts with a BOM mark. */ 265 /// Availability: >= 2.6 266 267 PyObject* PyUnicode_AsUTF32String( 268 PyObject *unicode 269 ); 270 271 /** Returns a Python string object holding the UTF-32 encoded value of 272 the Unicode data. 273 274 If byteorder is not 0, output is written according to the following 275 byte order: 276 277 byteorder == -1: little endian 278 byteorder == 0: native byte order (writes a BOM mark) 279 byteorder == 1: big endian 280 281 If byteorder is 0, the output string will always start with the 282 Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is 283 prepended. 284 Params: 285 data = Unicode char buffer 286 length = number of Py_UNICODE chars to encode 287 errors = error handling 288 byteorder = byteorder to use 0=BOM+native;-1=LE,1=BE 289 290 */ 291 /// Availability: >= 2.6 292 PyObject* PyUnicode_EncodeUTF32( 293 const Py_UNICODE *data, 294 Py_ssize_t length, 295 const(char)* errors, 296 int byteorder 297 ); 298 } 299 300 /** Return a read-only pointer to the Unicode object's internal 301 Py_UNICODE buffer. */ 302 Py_UNICODE* PyUnicode_AsUnicode(PyObject* unicode); 303 /** Get the length of the Unicode object. */ 304 Py_ssize_t PyUnicode_GetSize(PyObject* unicode); 305 306 /** Get the maximum ordinal for a Unicode character. */ 307 Py_UNICODE PyUnicode_GetMax(); 308 309 /** Resize an already allocated Unicode object to the new size length. 310 311 _*unicode is modified to point to the new (resized) object and 0 312 returned on success. 313 314 This API may only be called by the function which also called the 315 Unicode constructor. The refcount on the object must be 1. Otherwise, 316 an error is returned. 317 318 Error handling is implemented as follows: an exception is set, -1 319 is returned and *unicode left untouched. 320 Params: 321 unicode = pointer to the new unicode object. 322 length = New length. 323 324 */ 325 int PyUnicode_Resize(PyObject** unicode, Py_ssize_t length); 326 /** Coerce obj to an Unicode object and return a reference with 327 _*incremented* refcount. 328 329 Coercion is done in the following way: 330 331 1. String and other char buffer compatible objects are decoded 332 under the assumptions that they contain data using the current 333 default encoding. Decoding is done in "strict" mode. 334 335 2. All other objects (including Unicode objects) raise an 336 exception. 337 338 The API returns NULL in case of an error. The caller is responsible 339 for decref'ing the returned objects. 340 341 */ 342 PyObject* PyUnicode_FromEncodedObject( 343 PyObject* obj, 344 const(char)* encoding, 345 const(char)* errors); 346 347 /** Coerce obj to an Unicode object and return a reference with 348 _*incremented* refcount. 349 350 Unicode objects are passed back as-is (subclasses are converted to 351 true Unicode objects), all other objects are delegated to 352 PyUnicode_FromEncodedObject(obj, NULL, "strict") which results in 353 using the default encoding as basis for decoding the object. 354 355 The API returns NULL in case of an error. The caller is responsible 356 for decref'ing the returned objects. 357 358 */ 359 PyObject* PyUnicode_FromObject(PyObject* obj); 360 361 /** Create a Unicode Object from the whcar_t buffer w of the given 362 size. 363 364 The buffer is copied into the new object. */ 365 PyObject* PyUnicode_FromWideChar(const(wchar)* w, Py_ssize_t size); 366 367 /** Copies the Unicode Object contents into the wchar_t buffer w. At 368 most size wchar_t characters are copied. 369 370 Note that the resulting wchar_t string may or may not be 371 0-terminated. It is the responsibility of the caller to make sure 372 that the wchar_t string is 0-terminated in case this is required by 373 the application. 374 375 Returns the number of wchar_t characters copied (excluding a 376 possibly trailing 0-termination character) or -1 in case of an 377 error. */ 378 Py_ssize_t PyUnicode_AsWideChar( 379 PyUnicodeObject* unicode, 380 const(wchar)* w, 381 Py_ssize_t size); 382 383 /** Create a Unicode Object from the given Unicode code point ordinal. 384 385 The ordinal must be in range(0x10000) on narrow Python builds 386 (UCS2), and range(0x110000) on wide builds (UCS4). A ValueError is 387 raised in case it is not. 388 389 */ 390 PyObject* PyUnicode_FromOrdinal(int ordinal); 391 392 /** Return a Python string holding the default encoded value of the 393 Unicode object. 394 395 The resulting string is cached in the Unicode object for subsequent 396 usage by this function. The cached version is needed to implement 397 the character buffer interface and will live (at least) as long as 398 the Unicode object itself. 399 400 The refcount of the string is *not* incremented. 401 402 _*** Exported for internal use by the interpreter only !!! *** 403 404 */ 405 PyObject* _PyUnicode_AsDefaultEncodedString(PyObject *, const(char)*); 406 407 /** Returns the currently active default encoding. 408 409 The default encoding is currently implemented as run-time settable 410 process global. This may change in future versions of the 411 interpreter to become a parameter which is managed on a per-thread 412 basis. 413 414 */ 415 const(char)* PyUnicode_GetDefaultEncoding(); 416 417 /** Sets the currently active default encoding. 418 419 Returns 0 on success, -1 in case of an error. 420 421 */ 422 int PyUnicode_SetDefaultEncoding(const(char)*encoding); 423 424 /** Create a Unicode object by decoding the encoded string s of the 425 given size. 426 Params: 427 s = encoded string 428 size = size of buffer 429 encoding = encoding 430 errors = error handling 431 */ 432 PyObject* PyUnicode_Decode( 433 const(char)* s, 434 Py_ssize_t size, 435 const(char)* encoding, 436 const(char)* errors); 437 438 version(Python_3_6_Or_Later) { 439 /** Decode a Unicode object unicode and return the result as Python 440 object. */ 441 /// Deprecated in 3.6 442 deprecated("Deprecated in 3.6") 443 PyObject* PyUnicode_AsDecodedObject( 444 PyObject* unicode, 445 const(char)* encoding, 446 const(char)* errors 447 ); 448 /** Decode a Unicode object unicode and return the result as Unicode 449 object. */ 450 /// Availability: 3.* 451 452 /// Deprecated in 3.6 453 deprecated("Deprecated in 3.6") 454 PyObject* PyUnicode_AsDecodedUnicode( 455 PyObject* unicode, 456 const(char)* encoding, 457 const(char)* errors 458 ); 459 }else version(Python_3_0_Or_Later) { 460 /** Decode a Unicode object unicode and return the result as Python 461 object. */ 462 /// Availability: 3.* 463 PyObject* PyUnicode_AsDecodedObject( 464 PyObject* unicode, 465 const(char)* encoding, 466 const(char)* errors 467 ); 468 /** Decode a Unicode object unicode and return the result as Unicode 469 object. */ 470 /// Availability: 3.* 471 472 PyObject* PyUnicode_AsDecodedUnicode( 473 PyObject* unicode, 474 const(char)* encoding, 475 const(char)* errors 476 ); 477 } 478 479 /** Encodes a Py_UNICODE buffer of the given size and returns a 480 Python string object. 481 Params: 482 s = Unicode char buffer 483 size = number of Py_UNICODE chars to encode 484 encoding = encoding 485 errors = error handling 486 */ 487 PyObject* PyUnicode_Encode( 488 Py_UNICODE* s, 489 Py_ssize_t size, 490 const(char)* encoding, 491 const(char)* errors); 492 493 version(Python_3_6_Or_Later) { 494 /** Encodes a Unicode object and returns the result as Python object. 495 */ 496 deprecated("Deprecated in 3.6") 497 PyObject* PyUnicode_AsEncodedObject( 498 PyObject* unicode, 499 const(char)* encoding, 500 const(char)* errors); 501 }else{ 502 /** Encodes a Unicode object and returns the result as Python object. 503 */ 504 PyObject* PyUnicode_AsEncodedObject( 505 PyObject* unicode, 506 const(char)* encoding, 507 const(char)* errors); 508 } 509 510 /** Encodes a Unicode object and returns the result as Python string 511 object. */ 512 PyObject* PyUnicode_AsEncodedString( 513 PyObject* unicode, 514 const(char)* encoding, 515 const(char)* errors); 516 517 version(Python_3_0_Or_Later) { 518 /** Encodes a Unicode object and returns the result as Unicode 519 object. */ 520 deprecated("Deprecated in 3.6") 521 PyObject* PyUnicode_AsEncodedUnicode( 522 PyObject* unicode, 523 const(char)* encoding, 524 const(char)* errors 525 ); 526 }else version(Python_3_0_Or_Later) { 527 /** Encodes a Unicode object and returns the result as Unicode 528 object. */ 529 /// Availability: >= 3.* 530 PyObject* PyUnicode_AsEncodedUnicode( 531 PyObject* unicode, 532 const(char)* encoding, 533 const(char)* errors 534 ); 535 } 536 537 /** 538 Params: 539 string = UTF-7 encoded string 540 length = size of string 541 errors = error handling 542 */ 543 PyObject* PyUnicode_DecodeUTF7( 544 const(char)* string, 545 Py_ssize_t length, 546 const(char)* errors); 547 548 /** 549 Params: 550 data = Unicode char buffer 551 length = number of Py_UNICODE chars to encode 552 base64SetO = Encode RFC2152 Set O characters in base64 553 base64WhiteSpace = Encode whitespace (sp, ht, nl, cr) in base64 554 errors = error handling 555 */ 556 PyObject* PyUnicode_EncodeUTF7( 557 Py_UNICODE* data, 558 Py_ssize_t length, 559 int encodeSetO, 560 int encodeWhiteSpace, 561 const(char)* errors 562 ); 563 564 /// _ 565 PyObject* PyUnicode_DecodeUTF8( 566 const(char)* string, 567 Py_ssize_t length, 568 const(char)* errors); 569 /// _ 570 PyObject* PyUnicode_DecodeUTF8Stateful( 571 const(char)* string, 572 Py_ssize_t length, 573 const(char)* errors, 574 Py_ssize_t* consumed 575 ); 576 /// _ 577 PyObject* PyUnicode_AsUTF8String(PyObject* unicode); 578 /// _ 579 PyObject* PyUnicode_EncodeUTF8( 580 Py_UNICODE* data, 581 Py_ssize_t length, 582 const(char) *errors); 583 584 /** Decodes length bytes from a UTF-16 encoded buffer string and returns 585 the corresponding Unicode object. 586 587 errors (if non-NULL) defines the error handling. It defaults 588 to "strict". 589 590 If byteorder is non-NULL, the decoder starts decoding using the 591 given byte order: 592 593 *byteorder == -1: little endian 594 *byteorder == 0: native order 595 *byteorder == 1: big endian 596 597 In native mode, the first two bytes of the stream are checked for a 598 BOM mark. If found, the BOM mark is analysed, the byte order 599 adjusted and the BOM skipped. In the other modes, no BOM mark 600 interpretation is done. After completion, *byteorder is set to the 601 current byte order at the end of input data. 602 603 If byteorder is NULL, the codec starts in native order mode. 604 605 */ 606 PyObject* PyUnicode_DecodeUTF16( 607 const(char)* string, 608 Py_ssize_t length, 609 const(char)* errors, 610 int* byteorder); 611 /** 612 Params: 613 string = UTF-16 encoded string 614 length = size of string 615 errors = error handling 616 byteorder = pointer to byteorder to use 0=native;-1=LE,1=BE; updated on exit 617 consumed = bytes consumed 618 */ 619 PyObject* PyUnicode_DecodeUTF16Stateful( 620 const(char)* string, 621 Py_ssize_t length, 622 const(char)* errors, 623 int* byteorder, 624 Py_ssize_t* consumed 625 ); 626 /** Returns a Python string using the UTF-16 encoding in native byte 627 order. The string always starts with a BOM mark. */ 628 PyObject* PyUnicode_AsUTF16String(PyObject *unicode); 629 /** Returns a Python string object holding the UTF-16 encoded value of 630 the Unicode data. 631 632 If byteorder is not 0, output is written according to the following 633 byte order: 634 635 byteorder == -1: little endian 636 byteorder == 0: native byte order (writes a BOM mark) 637 byteorder == 1: big endian 638 639 If byteorder is 0, the output string will always start with the 640 Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is 641 prepended. 642 643 Note that Py_UNICODE data is being interpreted as UTF-16 reduced to 644 UCS-2. This trick makes it possible to add full UTF-16 capabilities 645 at a later point without compromising the APIs. 646 647 */ 648 PyObject* PyUnicode_EncodeUTF16( 649 Py_UNICODE* data, 650 Py_ssize_t length, 651 const(char)* errors, 652 int byteorder 653 ); 654 655 /// _ 656 PyObject* PyUnicode_DecodeUnicodeEscape( 657 const(char)* string, 658 Py_ssize_t length, 659 const(char)* errors); 660 /// _ 661 PyObject* PyUnicode_AsUnicodeEscapeString( 662 PyObject* unicode); 663 /// _ 664 PyObject* PyUnicode_EncodeUnicodeEscape( 665 Py_UNICODE* data, 666 Py_ssize_t length); 667 /** 668 Params: 669 string = Raw-Unicode-Escape encoded string 670 length = size of string 671 errors = error handling 672 */ 673 PyObject* PyUnicode_DecodeRawUnicodeEscape( 674 const(char)* string, 675 Py_ssize_t length, 676 const(char)* errors); 677 /// _ 678 PyObject* PyUnicode_AsRawUnicodeEscapeString(PyObject* unicode); 679 /// _ 680 PyObject* PyUnicode_EncodeRawUnicodeEscape( 681 Py_UNICODE* data, Py_ssize_t length); 682 683 /// _ 684 PyObject* _PyUnicode_DecodeUnicodeInternal( 685 const(char)* string, 686 Py_ssize_t length, 687 const(char)* errors); 688 689 /** 690 Params: 691 string = Latin-1 encoded string 692 length = size of string 693 errors = error handling 694 */ 695 PyObject* PyUnicode_DecodeLatin1( 696 const(char)* string, 697 Py_ssize_t length, 698 const(char)* errors); 699 /// _ 700 PyObject* PyUnicode_AsLatin1String(PyObject *unicode); 701 /** 702 Params: 703 data = Unicode char buffer 704 length = Number of Py_UNICODE chars to encode 705 errors = error handling 706 */ 707 PyObject* PyUnicode_EncodeLatin1( 708 Py_UNICODE* data, 709 Py_ssize_t length, 710 const(char)* errors); 711 712 /** 713 Params: 714 data = Unicode char buffer 715 length = Number of Py_UNICODE chars to encode 716 errors = error handling 717 */ 718 PyObject* PyUnicode_DecodeASCII( 719 const(char)* string, 720 Py_ssize_t length, 721 const(char)* errors); 722 /// _ 723 PyObject* PyUnicode_AsASCIIString(PyObject *unicode); 724 /** 725 Params: 726 data = Unicode char buffer 727 length = Number of Py_UNICODE chars to encode 728 errors = error handling 729 */ 730 PyObject* PyUnicode_EncodeASCII( 731 Py_UNICODE* data, 732 Py_ssize_t length, 733 const(char)* errors); 734 735 /** 736 Params: 737 string = Encoded string 738 length = size of string 739 mapping = character mapping (char ordinal -> unicode ordinal) 740 errors = error handling 741 */ 742 PyObject* PyUnicode_DecodeCharmap( 743 const(char)* string, 744 Py_ssize_t length, 745 PyObject* mapping, 746 const(char)* errors 747 ); 748 /** 749 Params: 750 unicode = Unicode object 751 mapping = character mapping (unicode ordinal -> char ordinal) 752 */ 753 PyObject* PyUnicode_AsCharmapString( 754 PyObject* unicode, 755 PyObject* mapping); 756 /** 757 Params: 758 data = Unicode char buffer 759 length = Number of Py_UNICODE chars to encode 760 mapping = character mapping (unicode ordinal -> char ordinal) 761 errors = error handling 762 */ 763 PyObject* PyUnicode_EncodeCharmap( 764 Py_UNICODE* data, 765 Py_ssize_t length, 766 PyObject* mapping, 767 const(char)* errors 768 ); 769 /** Translate a Py_UNICODE buffer of the given length by applying a 770 character mapping table to it and return the resulting Unicode 771 object. 772 773 The mapping table must map Unicode ordinal integers to Unicode 774 ordinal integers or None (causing deletion of the character). 775 776 Mapping tables may be dictionaries or sequences. Unmapped character 777 ordinals (ones which cause a LookupError) are left untouched and 778 are copied as-is. 779 780 */ 781 PyObject* PyUnicode_TranslateCharmap( 782 Py_UNICODE* data, 783 Py_ssize_t length, 784 PyObject* table, 785 const(char)* errors 786 ); 787 788 version (Windows) { 789 /// Availability: Windows only 790 PyObject* PyUnicode_DecodeMBCS( 791 const(char)* string, 792 Py_ssize_t length, 793 const(char)* errors); 794 /// Availability: Windows only 795 PyObject* PyUnicode_AsMBCSString(PyObject* unicode); 796 /// Availability: Windows only 797 PyObject* PyUnicode_EncodeMBCS( 798 Py_UNICODE* data, 799 Py_ssize_t length, 800 const(char)* errors); 801 } 802 /** Takes a Unicode string holding a decimal value and writes it into 803 an output buffer using standard ASCII digit codes. 804 805 The output buffer has to provide at least length+1 bytes of storage 806 area. The output string is 0-terminated. 807 808 The encoder converts whitespace to ' ', decimal characters to their 809 corresponding ASCII digit and all other Latin-1 characters except 810 \0 as-is. Characters outside this range (Unicode ordinals 1-256) 811 are treated as errors. This includes embedded NULL bytes. 812 813 Error handling is defined by the errors argument: 814 815 NULL or "strict": raise a ValueError 816 "ignore": ignore the wrong characters (these are not copied to the 817 output buffer) 818 "replace": replaces illegal characters with '?' 819 820 Returns 0 on success, -1 on failure. 821 822 */ 823 int PyUnicode_EncodeDecimal( 824 Py_UNICODE* s, 825 Py_ssize_t length, 826 char* output, 827 const(char)* errors); 828 829 /** Concat two strings giving a new Unicode string. */ 830 PyObject* PyUnicode_Concat( 831 PyObject* left, 832 PyObject* right); 833 834 version(Python_3_0_Or_Later) { 835 /** Concat two strings and put the result in *pleft 836 (sets *pleft to NULL on error) 837 Params: 838 pleft = Pointer to left string 839 right = Right string 840 */ 841 /// Availability: 3.* 842 843 void PyUnicode_Append( 844 PyObject** pleft, 845 PyObject* right 846 ); 847 848 /** Concat two strings, put the result in *pleft and drop the right object 849 (sets *pleft to NULL on error) 850 Params: 851 pleft = Pointer to left string 852 */ 853 /// Availability: 3.* 854 void PyUnicode_AppendAndDel( 855 PyObject** pleft, 856 PyObject* right 857 ); 858 } 859 860 /** Split a string giving a list of Unicode strings. 861 862 If sep is NULL, splitting will be done at all whitespace 863 substrings. Otherwise, splits occur at the given separator. 864 865 At most maxsplit splits will be done. If negative, no limit is set. 866 867 Separators are not included in the resulting list. 868 869 */ 870 PyObject* PyUnicode_Split( 871 PyObject* s, 872 PyObject* sep, 873 Py_ssize_t maxsplit); 874 875 /** Ditto PyUnicode_Split, but split at line breaks. 876 877 CRLF is considered to be one line break. Line breaks are not 878 included in the resulting list. */ 879 PyObject* PyUnicode_Splitlines( 880 PyObject* s, 881 int keepends); 882 883 version(Python_2_5_Or_Later) { 884 /** Partition a string using a given separator. */ 885 /// Availability: >= 2.5 886 PyObject* PyUnicode_Partition( 887 PyObject* s, 888 PyObject* sep 889 ); 890 891 /** Partition a string using a given separator, searching from the end 892 of the string. */ 893 894 PyObject* PyUnicode_RPartition( 895 PyObject* s, 896 PyObject* sep 897 ); 898 } 899 900 /** Split a string giving a list of Unicode strings. 901 902 If sep is NULL, splitting will be done at all whitespace 903 substrings. Otherwise, splits occur at the given separator. 904 905 At most maxsplit splits will be done. But unlike PyUnicode_Split 906 PyUnicode_RSplit splits from the end of the string. If negative, 907 no limit is set. 908 909 Separators are not included in the resulting list. 910 911 */ 912 PyObject* PyUnicode_RSplit( 913 PyObject* s, 914 PyObject* sep, 915 Py_ssize_t maxsplit); 916 917 /** Translate a string by applying a character mapping table to it and 918 return the resulting Unicode object. 919 920 The mapping table must map Unicode ordinal integers to Unicode 921 ordinal integers or None (causing deletion of the character). 922 923 Mapping tables may be dictionaries or sequences. Unmapped character 924 ordinals (ones which cause a LookupError) are left untouched and 925 are copied as-is. 926 927 */ 928 PyObject* PyUnicode_Translate( 929 PyObject* str, 930 PyObject* table, 931 const(char)* errors); 932 933 /** Join a sequence of strings using the given separator and return 934 the resulting Unicode string. */ 935 PyObject* PyUnicode_Join( 936 PyObject* separator, 937 PyObject* seq); 938 939 /** Return 1 if substr matches str[start:end] at the given tail end, 0 940 otherwise. */ 941 Py_ssize_t PyUnicode_Tailmatch( 942 PyObject* str, 943 PyObject* substr, 944 Py_ssize_t start, 945 Py_ssize_t end, 946 int direction 947 ); 948 949 /** Return the first position of substr in str[start:end] using the 950 given search direction or -1 if not found. -2 is returned in case 951 an error occurred and an exception is set. */ 952 Py_ssize_t PyUnicode_Find( 953 PyObject* str, 954 PyObject* substr, 955 Py_ssize_t start, 956 Py_ssize_t end, 957 int direction 958 ); 959 960 /** Count the number of occurrences of substr in str[start:end]. */ 961 Py_ssize_t PyUnicode_Count( 962 PyObject* str, 963 PyObject* substr, 964 Py_ssize_t start, 965 Py_ssize_t end); 966 967 /** Replace at most maxcount occurrences of substr in str with replstr 968 and return the resulting Unicode object. */ 969 PyObject* PyUnicode_Replace( 970 PyObject* str, 971 PyObject* substr, 972 PyObject* replstr, 973 Py_ssize_t maxcount 974 ); 975 976 /** Compare two strings and return -1, 0, 1 for less than, equal, 977 greater than resp. */ 978 int PyUnicode_Compare(PyObject* left, PyObject* right); 979 version(Python_3_0_Or_Later) { 980 /** Compare two strings and return -1, 0, 1 for less than, equal, 981 greater than resp. 982 Params: 983 left = 984 right = ASCII-encoded string 985 */ 986 /// Availability: 3.* 987 int PyUnicode_CompareWithASCIIString( 988 PyObject* left, 989 const(char)* right 990 ); 991 } 992 993 version(Python_2_5_Or_Later) { 994 /** Rich compare two strings and return one of the following: 995 996 - NULL in case an exception was raised 997 - Py_True or Py_False for successfuly comparisons 998 - Py_NotImplemented in case the type combination is unknown 999 1000 Note that Py_EQ and Py_NE comparisons can cause a UnicodeWarning in 1001 case the conversion of the arguments to Unicode fails with a 1002 UnicodeDecodeError. 1003 1004 Possible values for op: 1005 1006 Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE 1007 1008 */ 1009 /// Availability: >= 2.5 1010 PyObject* PyUnicode_RichCompare( 1011 PyObject* left, 1012 PyObject* right, 1013 int op 1014 ); 1015 } 1016 1017 /** Apply a argument tuple or dictionary to a format string and return 1018 the resulting Unicode string. */ 1019 PyObject* PyUnicode_Format(PyObject* format, PyObject* args); 1020 1021 /** Checks whether element is contained in container and return 1/0 1022 accordingly. 1023 1024 element has to coerce to an one element Unicode string. -1 is 1025 returned in case of an error. */ 1026 int PyUnicode_Contains(PyObject* container, PyObject* element); 1027 1028 version(Python_3_0_Or_Later) { 1029 /** Checks whether argument is a valid identifier. */ 1030 /// Availability: 3.* 1031 int PyUnicode_IsIdentifier(PyObject* s); 1032 } 1033 1034 1035 /// _ 1036 int _PyUnicode_IsLowercase(Py_UNICODE ch); 1037 /// _ 1038 int _PyUnicode_IsUppercase(Py_UNICODE ch); 1039 /// _ 1040 int _PyUnicode_IsTitlecase(Py_UNICODE ch); 1041 /// _ 1042 int _PyUnicode_IsWhitespace(Py_UNICODE ch); 1043 /// _ 1044 int _PyUnicode_IsLinebreak(Py_UNICODE ch); 1045 /// _ 1046 Py_UNICODE _PyUnicode_ToLowercase(Py_UNICODE ch); 1047 /// _ 1048 Py_UNICODE _PyUnicode_ToUppercase(Py_UNICODE ch); 1049 /// _ 1050 Py_UNICODE _PyUnicode_ToTitlecase(Py_UNICODE ch); 1051 /// _ 1052 int _PyUnicode_ToDecimalDigit(Py_UNICODE ch); 1053 /// _ 1054 int _PyUnicode_ToDigit(Py_UNICODE ch); 1055 /// _ 1056 double _PyUnicode_ToNumeric(Py_UNICODE ch); 1057 /// _ 1058 int _PyUnicode_IsDecimalDigit(Py_UNICODE ch); 1059 /// _ 1060 int _PyUnicode_IsDigit(Py_UNICODE ch); 1061 /// _ 1062 int _PyUnicode_IsNumeric(Py_UNICODE ch); 1063 /// _ 1064 int _PyUnicode_IsAlpha(Py_UNICODE ch); 1065 1066 }; 1067 1068 /* 1069 pragma(msg,substitute_and_alias(unicode_funs)); 1070 mixin(substitute_and_alias(unicode_funs)); 1071 */ 1072 1073 // waaaa! calling substitute_and_alias breaks linking! 1074 // oh, well. this is probably faster anyways. 1075 // following code is generated by substitute_and_alias. 1076 // don't modify it; modify unicode_funs! 1077 version(Python_3_3_Or_Later) { 1078 version(Python_2_6_Or_Later) { 1079 1080 /** Create a Unicode Object from the Py_UNICODE buffer u of the given 1081 size. 1082 1083 u may be NULL which causes the contents to be undefined. It is the 1084 user's responsibility to fill in the needed data afterwards. Note 1085 that modifying the Unicode object contents after construction is 1086 only allowed if u was set to NULL. 1087 1088 The buffer is copied into the new object. */ 1089 /// Availability: >= 2.6 1090 PyObject* PyUnicode_FromUnicode(Py_UNICODE* u, Py_ssize_t size); 1091 1092 /** Similar to PyUnicode_FromUnicode(), but u points to Latin-1 encoded bytes */ 1093 /// Availability: >= 2.6 1094 PyObject* PyUnicode_FromStringAndSize( 1095 const(char)*u, /* char buffer */ 1096 Py_ssize_t size /* size of buffer */ 1097 ); 1098 1099 /** Similar to PyUnicode_FromUnicode(), but u points to null-terminated 1100 Latin-1 encoded bytes */ 1101 /// Availability: >= 2.6 1102 PyObject* PyUnicode_FromString( 1103 const(char)*u /* string */ 1104 ); 1105 1106 /// Availability: >= 2.6 1107 PyObject* PyUnicode_FromFormatV(const(char)*, va_list); 1108 1109 /// Availability: >= 2.6 1110 PyObject* PyUnicode_FromFormat(const(char)*, ...); 1111 1112 /** Format the object based on the format_spec, as defined in PEP 3101 1113 (Advanced String Formatting). */ 1114 /// Availability: >= 2.6 1115 PyObject* _PyUnicode_FormatAdvanced(PyObject *obj, 1116 Py_UNICODE *format_spec, 1117 Py_ssize_t format_spec_len); 1118 1119 /// Availability: >= 2.6 1120 int PyUnicode_ClearFreeList(); 1121 1122 /** 1123 Params: 1124 string = UTF-7 encoded string 1125 length = size of string 1126 error = error handling 1127 consumed = bytes consumed 1128 */ 1129 /// Availability: >= 2.6 1130 PyObject* PyUnicode_DecodeUTF7Stateful( 1131 const(char)* string, 1132 Py_ssize_t length, 1133 const(char)*errors, 1134 Py_ssize_t *consumed 1135 ); 1136 1137 /** 1138 Params: 1139 string = UTF-32 encoded string 1140 length = size of string 1141 error = error handling 1142 byteorder = pointer to byteorder to use 0=native;-1=LE,1=BE; updated on exit 1143 */ 1144 /// Availability: >= 2.6 1145 PyObject* PyUnicode_DecodeUTF32( 1146 const(char)* string, 1147 Py_ssize_t length, 1148 const(char)*errors, 1149 int *byteorder 1150 ); 1151 1152 /** 1153 Params: 1154 string = UTF-32 encoded string 1155 length = size of string 1156 error = error handling 1157 byteorder = pointer to byteorder to use 0=native;-1=LE,1=BE; updated on exit 1158 */ 1159 /// Availability: >= 2.6 1160 PyObject* PyUnicode_DecodeUTF32Stateful( 1161 const(char)*string, 1162 Py_ssize_t length, 1163 const(char)*errors, 1164 int *byteorder, 1165 Py_ssize_t *consumed 1166 ); 1167 1168 /** Returns a Python string using the UTF-32 encoding in native byte 1169 order. The string always starts with a BOM mark. */ 1170 /// Availability: >= 2.6 1171 1172 PyObject* PyUnicode_AsUTF32String( 1173 PyObject *unicode 1174 ); 1175 1176 /** Returns a Python string object holding the UTF-32 encoded value of 1177 the Unicode data. 1178 1179 If byteorder is not 0, output is written according to the following 1180 byte order: 1181 1182 byteorder == -1: little endian 1183 byteorder == 0: native byte order (writes a BOM mark) 1184 byteorder == 1: big endian 1185 1186 If byteorder is 0, the output string will always start with the 1187 Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is 1188 prepended. 1189 Params: 1190 data = Unicode char buffer 1191 length = number of Py_UNICODE chars to encode 1192 errors = error handling 1193 byteorder = byteorder to use 0=BOM+native;-1=LE,1=BE 1194 1195 */ 1196 /// Availability: >= 2.6 1197 PyObject* PyUnicode_EncodeUTF32( 1198 const Py_UNICODE *data, 1199 Py_ssize_t length, 1200 const(char)* errors, 1201 int byteorder 1202 ); 1203 1204 } 1205 1206 /** Return a read-only pointer to the Unicode object's internal 1207 Py_UNICODE buffer. */ 1208 Py_UNICODE* PyUnicode_AsUnicode(PyObject* unicode); 1209 1210 /** Get the length of the Unicode object. */ 1211 Py_ssize_t PyUnicode_GetSize(PyObject* unicode); 1212 1213 /** Get the maximum ordinal for a Unicode character. */ 1214 Py_UNICODE PyUnicode_GetMax(); 1215 1216 /** Resize an already allocated Unicode object to the new size length. 1217 1218 _*unicode is modified to point to the new (resized) object and 0 1219 returned on success. 1220 1221 This API may only be called by the function which also called the 1222 Unicode constructor. The refcount on the object must be 1. Otherwise, 1223 an error is returned. 1224 1225 Error handling is implemented as follows: an exception is set, -1 1226 is returned and *unicode left untouched. 1227 Params: 1228 unicode = pointer to the new unicode object. 1229 length = New length. 1230 1231 */ 1232 int PyUnicode_Resize(PyObject** unicode, Py_ssize_t length); 1233 1234 /** Coerce obj to an Unicode object and return a reference with 1235 _*incremented* refcount. 1236 1237 Coercion is done in the following way: 1238 1239 1. String and other char buffer compatible objects are decoded 1240 under the assumptions that they contain data using the current 1241 default encoding. Decoding is done in "strict" mode. 1242 1243 2. All other objects (including Unicode objects) raise an 1244 exception. 1245 1246 The API returns NULL in case of an error. The caller is responsible 1247 for decref'ing the returned objects. 1248 1249 */ 1250 PyObject* PyUnicode_FromEncodedObject( 1251 PyObject* obj, 1252 const(char)* encoding, 1253 const(char)* errors); 1254 1255 /** Coerce obj to an Unicode object and return a reference with 1256 _*incremented* refcount. 1257 1258 Unicode objects are passed back as-is (subclasses are converted to 1259 true Unicode objects), all other objects are delegated to 1260 PyUnicode_FromEncodedObject(obj, NULL, "strict") which results in 1261 using the default encoding as basis for decoding the object. 1262 1263 The API returns NULL in case of an error. The caller is responsible 1264 for decref'ing the returned objects. 1265 1266 */ 1267 PyObject* PyUnicode_FromObject(PyObject* obj); 1268 1269 /** Create a Unicode Object from the whcar_t buffer w of the given 1270 size. 1271 1272 The buffer is copied into the new object. */ 1273 PyObject* PyUnicode_FromWideChar(const(wchar)* w, Py_ssize_t size); 1274 1275 /** Copies the Unicode Object contents into the wchar_t buffer w. At 1276 most size wchar_t characters are copied. 1277 1278 Note that the resulting wchar_t string may or may not be 1279 0-terminated. It is the responsibility of the caller to make sure 1280 that the wchar_t string is 0-terminated in case this is required by 1281 the application. 1282 1283 Returns the number of wchar_t characters copied (excluding a 1284 possibly trailing 0-termination character) or -1 in case of an 1285 error. */ 1286 Py_ssize_t PyUnicode_AsWideChar( 1287 PyUnicodeObject* unicode, 1288 const(wchar)* w, 1289 Py_ssize_t size); 1290 1291 /** Create a Unicode Object from the given Unicode code point ordinal. 1292 1293 The ordinal must be in range(0x10000) on narrow Python builds 1294 (UCS2), and range(0x110000) on wide builds (UCS4). A ValueError is 1295 raised in case it is not. 1296 1297 */ 1298 PyObject* PyUnicode_FromOrdinal(int ordinal); 1299 1300 /** Return a Python string holding the default encoded value of the 1301 Unicode object. 1302 1303 The resulting string is cached in the Unicode object for subsequent 1304 usage by this function. The cached version is needed to implement 1305 the character buffer interface and will live (at least) as long as 1306 the Unicode object itself. 1307 1308 The refcount of the string is *not* incremented. 1309 1310 _*** Exported for internal use by the interpreter only !!! *** 1311 1312 */ 1313 PyObject* _PyUnicode_AsDefaultEncodedString(PyObject *, const(char)*); 1314 1315 /** Returns the currently active default encoding. 1316 1317 The default encoding is currently implemented as run-time settable 1318 process global. This may change in future versions of the 1319 interpreter to become a parameter which is managed on a per-thread 1320 basis. 1321 1322 */ 1323 const(char)* PyUnicode_GetDefaultEncoding(); 1324 1325 /** Sets the currently active default encoding. 1326 1327 Returns 0 on success, -1 in case of an error. 1328 1329 */ 1330 int PyUnicode_SetDefaultEncoding(const(char)*encoding); 1331 1332 /** Create a Unicode object by decoding the encoded string s of the 1333 given size. 1334 Params: 1335 s = encoded string 1336 size = size of buffer 1337 encoding = encoding 1338 errors = error handling 1339 */ 1340 PyObject* PyUnicode_Decode( 1341 const(char)* s, 1342 Py_ssize_t size, 1343 const(char)* encoding, 1344 const(char)* errors); 1345 1346 version(Python_3_0_Or_Later) { 1347 /** Decode a Unicode object unicode and return the result as Python 1348 object. */ 1349 /// Availability: 3.* 1350 1351 PyObject* PyUnicode_AsDecodedObject( 1352 PyObject* unicode, 1353 const(char)* encoding, 1354 const(char)* errors 1355 ); 1356 1357 /** Decode a Unicode object unicode and return the result as Unicode 1358 object. */ 1359 /// Availability: 3.* 1360 1361 PyObject* PyUnicode_AsDecodedUnicode( 1362 PyObject* unicode, 1363 const(char)* encoding, 1364 const(char)* errors 1365 ); 1366 1367 } 1368 1369 /** Encodes a Py_UNICODE buffer of the given size and returns a 1370 Python string object. 1371 Params: 1372 s = Unicode char buffer 1373 size = number of Py_UNICODE chars to encode 1374 encoding = encoding 1375 errors = error handling 1376 */ 1377 PyObject* PyUnicode_Encode( 1378 Py_UNICODE* s, 1379 Py_ssize_t size, 1380 const(char)* encoding, 1381 const(char)* errors); 1382 1383 /** Encodes a Unicode object and returns the result as Python object. 1384 */ 1385 PyObject* PyUnicode_AsEncodedObject( 1386 PyObject* unicode, 1387 const(char)* encoding, 1388 const(char)* errors); 1389 1390 /** Encodes a Unicode object and returns the result as Python string 1391 object. */ 1392 PyObject* PyUnicode_AsEncodedString( 1393 PyObject* unicode, 1394 const(char)* encoding, 1395 const(char)* errors); 1396 1397 version(Python_3_0_Or_Later) { 1398 /** Encodes a Unicode object and returns the result as Unicode 1399 object. */ 1400 /// Availability: >= 3.* 1401 PyObject* PyUnicode_AsEncodedUnicode( 1402 PyObject* unicode, 1403 const(char)* encoding, 1404 const(char)* errors 1405 ); 1406 1407 } 1408 1409 /** 1410 Params: 1411 string = UTF-7 encoded string 1412 length = size of string 1413 errors = error handling 1414 */ 1415 PyObject* PyUnicode_DecodeUTF7( 1416 const(char)* string, 1417 Py_ssize_t length, 1418 const(char)* errors); 1419 1420 /** 1421 Params: 1422 data = Unicode char buffer 1423 length = number of Py_UNICODE chars to encode 1424 base64SetO = Encode RFC2152 Set O characters in base64 1425 base64WhiteSpace = Encode whitespace (sp, ht, nl, cr) in base64 1426 errors = error handling 1427 */ 1428 PyObject* PyUnicode_EncodeUTF7( 1429 Py_UNICODE* data, 1430 Py_ssize_t length, 1431 int encodeSetO, 1432 int encodeWhiteSpace, 1433 const(char)* errors 1434 ); 1435 1436 /// _ 1437 PyObject* PyUnicode_DecodeUTF8( 1438 const(char)* string, 1439 Py_ssize_t length, 1440 const(char)* errors); 1441 1442 /// _ 1443 PyObject* PyUnicode_DecodeUTF8Stateful( 1444 const(char)* string, 1445 Py_ssize_t length, 1446 const(char)* errors, 1447 Py_ssize_t* consumed 1448 ); 1449 1450 /// _ 1451 PyObject* PyUnicode_AsUTF8String(PyObject* unicode); 1452 1453 /// _ 1454 PyObject* PyUnicode_EncodeUTF8( 1455 Py_UNICODE* data, 1456 Py_ssize_t length, 1457 const(char) *errors); 1458 1459 1460 1461 /** Decodes length bytes from a UTF-16 encoded buffer string and returns 1462 the corresponding Unicode object. 1463 1464 errors (if non-NULL) defines the error handling. It defaults 1465 to "strict". 1466 1467 If byteorder is non-NULL, the decoder starts decoding using the 1468 given byte order: 1469 1470 *byteorder == -1: little endian 1471 *byteorder == 0: native order 1472 *byteorder == 1: big endian 1473 1474 In native mode, the first two bytes of the stream are checked for a 1475 BOM mark. If found, the BOM mark is analysed, the byte order 1476 adjusted and the BOM skipped. In the other modes, no BOM mark 1477 interpretation is done. After completion, *byteorder is set to the 1478 current byte order at the end of input data. 1479 1480 If byteorder is NULL, the codec starts in native order mode. 1481 1482 */ 1483 PyObject* PyUnicode_DecodeUTF16( 1484 const(char)* string, 1485 Py_ssize_t length, 1486 const(char)* errors, 1487 int* byteorder); 1488 1489 1490 /** 1491 Params: 1492 string = UTF-16 encoded string 1493 length = size of string 1494 errors = error handling 1495 byteorder = pointer to byteorder to use 0=native;-1=LE,1=BE; updated on exit 1496 consumed = bytes consumed 1497 */ 1498 PyObject* PyUnicode_DecodeUTF16Stateful( 1499 const(char)* string, 1500 Py_ssize_t length, 1501 const(char)* errors, 1502 int* byteorder, 1503 Py_ssize_t* consumed 1504 ); 1505 1506 1507 /** Returns a Python string using the UTF-16 encoding in native byte 1508 order. The string always starts with a BOM mark. */ 1509 PyObject* PyUnicode_AsUTF16String(PyObject *unicode); 1510 1511 1512 /** Returns a Python string object holding the UTF-16 encoded value of 1513 the Unicode data. 1514 1515 If byteorder is not 0, output is written according to the following 1516 byte order: 1517 1518 byteorder == -1: little endian 1519 byteorder == 0: native byte order (writes a BOM mark) 1520 byteorder == 1: big endian 1521 1522 If byteorder is 0, the output string will always start with the 1523 Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is 1524 prepended. 1525 1526 Note that Py_UNICODE data is being interpreted as UTF-16 reduced to 1527 UCS-2. This trick makes it possible to add full UTF-16 capabilities 1528 at a later point without compromising the APIs. 1529 1530 */ 1531 PyObject* PyUnicode_EncodeUTF16( 1532 Py_UNICODE* data, 1533 Py_ssize_t length, 1534 const(char)* errors, 1535 int byteorder 1536 ); 1537 1538 1539 1540 /// _ 1541 PyObject* PyUnicode_DecodeUnicodeEscape( 1542 const(char)* string, 1543 Py_ssize_t length, 1544 const(char)* errors); 1545 1546 1547 /// _ 1548 PyObject* PyUnicode_AsUnicodeEscapeString( 1549 PyObject* unicode); 1550 1551 1552 /// _ 1553 PyObject* PyUnicode_EncodeUnicodeEscape( 1554 Py_UNICODE* data, 1555 Py_ssize_t length); 1556 1557 1558 /** 1559 Params: 1560 string = Raw-Unicode-Escape encoded string 1561 length = size of string 1562 errors = error handling 1563 */ 1564 PyObject* PyUnicode_DecodeRawUnicodeEscape( 1565 const(char)* string, 1566 Py_ssize_t length, 1567 const(char)* errors); 1568 1569 /// _ 1570 PyObject* PyUnicode_AsRawUnicodeEscapeString(PyObject* unicode); 1571 1572 /// _ 1573 PyObject* PyUnicode_EncodeRawUnicodeEscape( 1574 Py_UNICODE* data, Py_ssize_t length); 1575 1576 /// _ 1577 PyObject* _PyUnicode_DecodeUnicodeInternal( 1578 const(char)* string, 1579 Py_ssize_t length, 1580 const(char)* errors); 1581 1582 /** 1583 Params: 1584 string = Latin-1 encoded string 1585 length = size of string 1586 errors = error handling 1587 */ 1588 PyObject* PyUnicode_DecodeLatin1( 1589 const(char)* string, 1590 Py_ssize_t length, 1591 const(char)* errors); 1592 1593 /// _ 1594 PyObject* PyUnicode_AsLatin1String(PyObject *unicode); 1595 1596 /** 1597 Params: 1598 data = Unicode char buffer 1599 length = Number of Py_UNICODE chars to encode 1600 errors = error handling 1601 */ 1602 PyObject* PyUnicode_EncodeLatin1( 1603 Py_UNICODE* data, 1604 Py_ssize_t length, 1605 const(char)* errors); 1606 1607 /** 1608 Params: 1609 data = Unicode char buffer 1610 length = Number of Py_UNICODE chars to encode 1611 errors = error handling 1612 */ 1613 PyObject* PyUnicode_DecodeASCII( 1614 const(char)* string, 1615 Py_ssize_t length, 1616 const(char)* errors); 1617 1618 /// _ 1619 PyObject* PyUnicode_AsASCIIString(PyObject *unicode); 1620 1621 /** 1622 Params: 1623 data = Unicode char buffer 1624 length = Number of Py_UNICODE chars to encode 1625 errors = error handling 1626 */ 1627 PyObject* PyUnicode_EncodeASCII( 1628 Py_UNICODE* data, 1629 Py_ssize_t length, 1630 const(char)* errors); 1631 1632 /** 1633 Params: 1634 string = Encoded string 1635 length = size of string 1636 mapping = character mapping (char ordinal -> unicode ordinal) 1637 errors = error handling 1638 */ 1639 PyObject* PyUnicode_DecodeCharmap( 1640 const(char)* string, 1641 Py_ssize_t length, 1642 PyObject* mapping, 1643 const(char)* errors 1644 ); 1645 1646 /** 1647 Params: 1648 unicode = Unicode object 1649 mapping = character mapping (unicode ordinal -> char ordinal) 1650 */ 1651 PyObject* PyUnicode_AsCharmapString( 1652 PyObject* unicode, 1653 PyObject* mapping); 1654 1655 /** 1656 Params: 1657 data = Unicode char buffer 1658 length = Number of Py_UNICODE chars to encode 1659 mapping = character mapping (unicode ordinal -> char ordinal) 1660 errors = error handling 1661 */ 1662 PyObject* PyUnicode_EncodeCharmap( 1663 Py_UNICODE* data, 1664 Py_ssize_t length, 1665 PyObject* mapping, 1666 const(char)* errors 1667 ); 1668 1669 /** Translate a Py_UNICODE buffer of the given length by applying a 1670 character mapping table to it and return the resulting Unicode 1671 object. 1672 1673 The mapping table must map Unicode ordinal integers to Unicode 1674 ordinal integers or None (causing deletion of the character). 1675 1676 Mapping tables may be dictionaries or sequences. Unmapped character 1677 ordinals (ones which cause a LookupError) are left untouched and 1678 are copied as-is. 1679 1680 */ 1681 PyObject* PyUnicode_TranslateCharmap( 1682 Py_UNICODE* data, 1683 Py_ssize_t length, 1684 PyObject* table, 1685 const(char)* errors 1686 ); 1687 1688 version (Windows) { 1689 /// Availability: Windows only 1690 PyObject* PyUnicode_DecodeMBCS( 1691 const(char)* string, 1692 Py_ssize_t length, 1693 const(char)* errors); 1694 1695 /// Availability: Windows only 1696 PyObject* PyUnicode_AsMBCSString(PyObject* unicode); 1697 1698 /// Availability: Windows only 1699 PyObject* PyUnicode_EncodeMBCS( 1700 Py_UNICODE* data, 1701 Py_ssize_t length, 1702 const(char)* errors); 1703 1704 } 1705 /** Takes a Unicode string holding a decimal value and writes it into 1706 an output buffer using standard ASCII digit codes. 1707 1708 The output buffer has to provide at least length+1 bytes of storage 1709 area. The output string is 0-terminated. 1710 1711 The encoder converts whitespace to ' ', decimal characters to their 1712 corresponding ASCII digit and all other Latin-1 characters except 1713 \0 as-is. Characters outside this range (Unicode ordinals 1-256) 1714 are treated as errors. This includes embedded NULL bytes. 1715 1716 Error handling is defined by the errors argument: 1717 1718 NULL or "strict": raise a ValueError 1719 "ignore": ignore the wrong characters (these are not copied to the 1720 output buffer) 1721 "replace": replaces illegal characters with '?' 1722 1723 Returns 0 on success, -1 on failure. 1724 1725 */ 1726 int PyUnicode_EncodeDecimal( 1727 Py_UNICODE* s, 1728 Py_ssize_t length, 1729 char* output, 1730 const(char)* errors); 1731 1732 /** Concat two strings giving a new Unicode string. */ 1733 PyObject* PyUnicode_Concat( 1734 PyObject* left, 1735 PyObject* right); 1736 1737 version(Python_3_0_Or_Later) { 1738 /** Concat two strings and put the result in *pleft 1739 (sets *pleft to NULL on error) 1740 Params: 1741 pleft = Pointer to left string 1742 right = Right string 1743 */ 1744 /// Availability: 3.* 1745 1746 void PyUnicode_Append( 1747 PyObject** pleft, 1748 PyObject* right 1749 ); 1750 1751 /** Concat two strings, put the result in *pleft and drop the right object 1752 (sets *pleft to NULL on error) 1753 Params: 1754 pleft = Pointer to left string 1755 */ 1756 /// Availability: 3.* 1757 void PyUnicode_AppendAndDel( 1758 PyObject** pleft, 1759 PyObject* right 1760 ); 1761 1762 } 1763 1764 /** Split a string giving a list of Unicode strings. 1765 1766 If sep is NULL, splitting will be done at all whitespace 1767 substrings. Otherwise, splits occur at the given separator. 1768 1769 At most maxsplit splits will be done. If negative, no limit is set. 1770 1771 Separators are not included in the resulting list. 1772 1773 */ 1774 PyObject* PyUnicode_Split( 1775 PyObject* s, 1776 PyObject* sep, 1777 Py_ssize_t maxsplit); 1778 1779 /** Ditto PyUnicode_Split, but split at line breaks. 1780 1781 CRLF is considered to be one line break. Line breaks are not 1782 included in the resulting list. */ 1783 PyObject* PyUnicode_Splitlines( 1784 PyObject* s, 1785 int keepends); 1786 1787 version(Python_2_5_Or_Later) { 1788 /** Partition a string using a given separator. */ 1789 /// Availability: >= 2.5 1790 PyObject* PyUnicode_Partition( 1791 PyObject* s, 1792 PyObject* sep 1793 ); 1794 1795 1796 /** Partition a string using a given separator, searching from the end 1797 of the string. */ 1798 1799 PyObject* PyUnicode_RPartition( 1800 PyObject* s, 1801 PyObject* sep 1802 ); 1803 1804 } 1805 1806 /** Split a string giving a list of Unicode strings. 1807 1808 If sep is NULL, splitting will be done at all whitespace 1809 substrings. Otherwise, splits occur at the given separator. 1810 1811 At most maxsplit splits will be done. But unlike PyUnicode_Split 1812 PyUnicode_RSplit splits from the end of the string. If negative, 1813 no limit is set. 1814 1815 Separators are not included in the resulting list. 1816 1817 */ 1818 PyObject* PyUnicode_RSplit( 1819 PyObject* s, 1820 PyObject* sep, 1821 Py_ssize_t maxsplit); 1822 1823 1824 /** Translate a string by applying a character mapping table to it and 1825 return the resulting Unicode object. 1826 1827 The mapping table must map Unicode ordinal integers to Unicode 1828 ordinal integers or None (causing deletion of the character). 1829 1830 Mapping tables may be dictionaries or sequences. Unmapped character 1831 ordinals (ones which cause a LookupError) are left untouched and 1832 are copied as-is. 1833 1834 */ 1835 PyObject* PyUnicode_Translate( 1836 PyObject* str, 1837 PyObject* table, 1838 const(char)* errors); 1839 1840 /** Join a sequence of strings using the given separator and return 1841 the resulting Unicode string. */ 1842 PyObject* PyUnicode_Join( 1843 PyObject* separator, 1844 PyObject* seq); 1845 1846 /** Return 1 if substr matches str[start:end] at the given tail end, 0 1847 otherwise. */ 1848 Py_ssize_t PyUnicode_Tailmatch( 1849 PyObject* str, 1850 PyObject* substr, 1851 Py_ssize_t start, 1852 Py_ssize_t end, 1853 int direction 1854 ); 1855 1856 1857 /** Return the first position of substr in str[start:end] using the 1858 given search direction or -1 if not found. -2 is returned in case 1859 an error occurred and an exception is set. */ 1860 Py_ssize_t PyUnicode_Find( 1861 PyObject* str, 1862 PyObject* substr, 1863 Py_ssize_t start, 1864 Py_ssize_t end, 1865 int direction 1866 ); 1867 1868 /** Count the number of occurrences of substr in str[start:end]. */ 1869 Py_ssize_t PyUnicode_Count( 1870 PyObject* str, 1871 PyObject* substr, 1872 Py_ssize_t start, 1873 Py_ssize_t end); 1874 1875 /** Replace at most maxcount occurrences of substr in str with replstr 1876 and return the resulting Unicode object. */ 1877 PyObject* PyUnicode_Replace( 1878 PyObject* str, 1879 PyObject* substr, 1880 PyObject* replstr, 1881 Py_ssize_t maxcount 1882 ); 1883 1884 /** Compare two strings and return -1, 0, 1 for less than, equal, 1885 greater than resp. */ 1886 int PyUnicode_Compare(PyObject* left, PyObject* right); 1887 1888 version(Python_3_0_Or_Later) { 1889 /** Compare two strings and return -1, 0, 1 for less than, equal, 1890 greater than resp. 1891 Params: 1892 left = 1893 right = ASCII-encoded string 1894 */ 1895 /// Availability: 3.* 1896 int PyUnicode_CompareWithASCIIString( 1897 PyObject* left, 1898 const(char)* right 1899 ); 1900 } 1901 1902 version(Python_2_5_Or_Later) { 1903 /** Rich compare two strings and return one of the following: 1904 1905 - NULL in case an exception was raised 1906 - Py_True or Py_False for successfuly comparisons 1907 - Py_NotImplemented in case the type combination is unknown 1908 1909 Note that Py_EQ and Py_NE comparisons can cause a UnicodeWarning in 1910 case the conversion of the arguments to Unicode fails with a 1911 UnicodeDecodeError. 1912 1913 Possible values for op: 1914 1915 Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE 1916 1917 */ 1918 /// Availability: >= 2.5 1919 PyObject* PyUnicode_RichCompare( 1920 PyObject* left, 1921 PyObject* right, 1922 int op 1923 ); 1924 } 1925 1926 /** Apply a argument tuple or dictionary to a format string and return 1927 the resulting Unicode string. */ 1928 PyObject* PyUnicode_Format(PyObject* format, PyObject* args); 1929 1930 /** Checks whether element is contained in container and return 1/0 1931 accordingly. 1932 1933 element has to coerce to an one element Unicode string. -1 is 1934 returned in case of an error. */ 1935 int PyUnicode_Contains(PyObject* container, PyObject* element); 1936 1937 version(Python_3_0_Or_Later) { 1938 /** Checks whether argument is a valid identifier. */ 1939 /// Availability: 3.* 1940 int PyUnicode_IsIdentifier(PyObject* s); 1941 } 1942 1943 1944 /// _ 1945 int _PyUnicode_IsLowercase(Py_UNICODE ch); 1946 1947 /// _ 1948 int _PyUnicode_IsUppercase(Py_UNICODE ch); 1949 1950 /// _ 1951 int _PyUnicode_IsTitlecase(Py_UNICODE ch); 1952 1953 /// _ 1954 int _PyUnicode_IsWhitespace(Py_UNICODE ch); 1955 1956 /// _ 1957 int _PyUnicode_IsLinebreak(Py_UNICODE ch); 1958 1959 /// _ 1960 Py_UNICODE _PyUnicode_ToLowercase(Py_UNICODE ch); 1961 1962 /// _ 1963 Py_UNICODE _PyUnicode_ToUppercase(Py_UNICODE ch); 1964 1965 /// _ 1966 Py_UNICODE _PyUnicode_ToTitlecase(Py_UNICODE ch); 1967 1968 /// _ 1969 int _PyUnicode_ToDecimalDigit(Py_UNICODE ch); 1970 1971 /// _ 1972 int _PyUnicode_ToDigit(Py_UNICODE ch); 1973 1974 /// _ 1975 double _PyUnicode_ToNumeric(Py_UNICODE ch); 1976 1977 /// _ 1978 int _PyUnicode_IsDecimalDigit(Py_UNICODE ch); 1979 1980 /// _ 1981 int _PyUnicode_IsDigit(Py_UNICODE ch); 1982 1983 /// _ 1984 int _PyUnicode_IsNumeric(Py_UNICODE ch); 1985 1986 /// _ 1987 int _PyUnicode_IsAlpha(Py_UNICODE ch); 1988 1989 }else version(Python_Unicode_UCS2) { 1990 1991 version(Python_2_6_Or_Later) { 1992 1993 /** Create a Unicode Object from the Py_UNICODE buffer u of the given 1994 size. 1995 1996 u may be NULL which causes the contents to be undefined. It is the 1997 user's responsibility to fill in the needed data afterwards. Note 1998 that modifying the Unicode object contents after construction is 1999 only allowed if u was set to NULL. 2000 2001 The buffer is copied into the new object. */ 2002 /// Availability: >= 2.6 2003 PyObject* PyUnicodeUCS2_FromUnicode(Py_UNICODE* u, Py_ssize_t size); 2004 /// ditto 2005 2006 alias PyUnicodeUCS2_FromUnicode PyUnicode_FromUnicode; 2007 2008 2009 /** Similar to PyUnicode_FromUnicode(), but u points to Latin-1 encoded bytes */ 2010 /// Availability: >= 2.6 2011 PyObject* PyUnicodeUCS2_FromStringAndSize( 2012 const(char)*u, /* char buffer */ 2013 Py_ssize_t size /* size of buffer */ 2014 ); 2015 /// ditto 2016 2017 alias PyUnicodeUCS2_FromStringAndSize PyUnicode_FromStringAndSize; 2018 2019 2020 /** Similar to PyUnicode_FromUnicode(), but u points to null-terminated 2021 Latin-1 encoded bytes */ 2022 /// Availability: >= 2.6 2023 PyObject* PyUnicodeUCS2_FromString( 2024 const(char)*u /* string */ 2025 ); 2026 /// ditto 2027 2028 alias PyUnicodeUCS2_FromString PyUnicode_FromString; 2029 2030 /// Availability: >= 2.6 2031 PyObject* PyUnicodeUCS2_FromFormatV(const(char)*, va_list); 2032 /// ditto 2033 2034 alias PyUnicodeUCS2_FromFormatV PyUnicode_FromFormatV; 2035 2036 /// Availability: >= 2.6 2037 PyObject* PyUnicodeUCS2_FromFormat(const(char)*, ...); 2038 /// ditto 2039 2040 alias PyUnicodeUCS2_FromFormat PyUnicode_FromFormat; 2041 2042 2043 /** Format the object based on the format_spec, as defined in PEP 3101 2044 (Advanced String Formatting). */ 2045 /// Availability: >= 2.6 2046 PyObject* _PyUnicodeUCS2_FormatAdvanced(PyObject *obj, 2047 Py_UNICODE *format_spec, 2048 Py_ssize_t format_spec_len); 2049 /// ditto 2050 2051 alias _PyUnicodeUCS2_FormatAdvanced _PyUnicode_FormatAdvanced; 2052 2053 /// Availability: >= 2.6 2054 int PyUnicodeUCS2_ClearFreeList(); 2055 /// ditto 2056 2057 alias PyUnicodeUCS2_ClearFreeList PyUnicode_ClearFreeList; 2058 2059 /** 2060 Params: 2061 string = UTF-7 encoded string 2062 length = size of string 2063 error = error handling 2064 consumed = bytes consumed 2065 */ 2066 /// Availability: >= 2.6 2067 PyObject* PyUnicodeUCS2_DecodeUTF7Stateful( 2068 const(char)* string, 2069 Py_ssize_t length, 2070 const(char)*errors, 2071 Py_ssize_t *consumed 2072 ); 2073 /// ditto 2074 2075 alias PyUnicodeUCS2_DecodeUTF7Stateful PyUnicode_DecodeUTF7Stateful; 2076 2077 /** 2078 Params: 2079 string = UTF-32 encoded string 2080 length = size of string 2081 error = error handling 2082 byteorder = pointer to byteorder to use 0=native;-1=LE,1=BE; updated on exit 2083 */ 2084 /// Availability: >= 2.6 2085 PyObject* PyUnicodeUCS2_DecodeUTF32( 2086 const(char)* string, 2087 Py_ssize_t length, 2088 const(char)*errors, 2089 int *byteorder 2090 ); 2091 /// ditto 2092 2093 alias PyUnicodeUCS2_DecodeUTF32 PyUnicode_DecodeUTF32; 2094 2095 2096 /** 2097 Params: 2098 string = UTF-32 encoded string 2099 length = size of string 2100 error = error handling 2101 byteorder = pointer to byteorder to use 0=native;-1=LE,1=BE; updated on exit 2102 */ 2103 /// Availability: >= 2.6 2104 PyObject* PyUnicodeUCS2_DecodeUTF32Stateful( 2105 const(char)*string, 2106 Py_ssize_t length, 2107 const(char)*errors, 2108 int *byteorder, 2109 Py_ssize_t *consumed 2110 ); 2111 /// ditto 2112 2113 alias PyUnicodeUCS2_DecodeUTF32Stateful PyUnicode_DecodeUTF32Stateful; 2114 2115 /** Returns a Python string using the UTF-32 encoding in native byte 2116 order. The string always starts with a BOM mark. */ 2117 /// Availability: >= 2.6 2118 2119 PyObject* PyUnicodeUCS2_AsUTF32String( 2120 PyObject *unicode 2121 ); 2122 /// ditto 2123 2124 alias PyUnicodeUCS2_AsUTF32String PyUnicode_AsUTF32String; 2125 2126 2127 /** Returns a Python string object holding the UTF-32 encoded value of 2128 the Unicode data. 2129 2130 If byteorder is not 0, output is written according to the following 2131 byte order: 2132 2133 byteorder == -1: little endian 2134 byteorder == 0: native byte order (writes a BOM mark) 2135 byteorder == 1: big endian 2136 2137 If byteorder is 0, the output string will always start with the 2138 Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is 2139 prepended. 2140 Params: 2141 data = Unicode char buffer 2142 length = number of Py_UNICODE chars to encode 2143 errors = error handling 2144 byteorder = byteorder to use 0=BOM+native;-1=LE,1=BE 2145 2146 */ 2147 /// Availability: >= 2.6 2148 PyObject* PyUnicodeUCS2_EncodeUTF32( 2149 const Py_UNICODE *data, 2150 Py_ssize_t length, 2151 const(char)* errors, 2152 int byteorder 2153 ); 2154 /// ditto 2155 2156 alias PyUnicodeUCS2_EncodeUTF32 PyUnicode_EncodeUTF32; 2157 2158 } 2159 2160 /** Return a read-only pointer to the Unicode object's internal 2161 Py_UNICODE buffer. */ 2162 Py_UNICODE* PyUnicodeUCS2_AsUnicode(PyObject* unicode); 2163 /// ditto 2164 2165 alias PyUnicodeUCS2_AsUnicode PyUnicode_AsUnicode; 2166 2167 /** Get the length of the Unicode object. */ 2168 Py_ssize_t PyUnicodeUCS2_GetSize(PyObject* unicode); 2169 /// ditto 2170 2171 alias PyUnicodeUCS2_GetSize PyUnicode_GetSize; 2172 2173 2174 /** Get the maximum ordinal for a Unicode character. */ 2175 Py_UNICODE PyUnicodeUCS2_GetMax(); 2176 /// ditto 2177 2178 alias PyUnicodeUCS2_GetMax PyUnicode_GetMax; 2179 2180 2181 /** Resize an already allocated Unicode object to the new size length. 2182 2183 _*unicode is modified to point to the new (resized) object and 0 2184 returned on success. 2185 2186 This API may only be called by the function which also called the 2187 Unicode constructor. The refcount on the object must be 1. Otherwise, 2188 an error is returned. 2189 2190 Error handling is implemented as follows: an exception is set, -1 2191 is returned and *unicode left untouched. 2192 Params: 2193 unicode = pointer to the new unicode object. 2194 length = New length. 2195 2196 */ 2197 int PyUnicodeUCS2_Resize(PyObject** unicode, Py_ssize_t length); 2198 /// ditto 2199 2200 alias PyUnicodeUCS2_Resize PyUnicode_Resize; 2201 2202 /** Coerce obj to an Unicode object and return a reference with 2203 _*incremented* refcount. 2204 2205 Coercion is done in the following way: 2206 2207 1. String and other char buffer compatible objects are decoded 2208 under the assumptions that they contain data using the current 2209 default encoding. Decoding is done in "strict" mode. 2210 2211 2. All other objects (including Unicode objects) raise an 2212 exception. 2213 2214 The API returns NULL in case of an error. The caller is responsible 2215 for decref'ing the returned objects. 2216 2217 */ 2218 PyObject* PyUnicodeUCS2_FromEncodedObject( 2219 PyObject* obj, 2220 const(char)* encoding, 2221 const(char)* errors); 2222 /// ditto 2223 2224 alias PyUnicodeUCS2_FromEncodedObject PyUnicode_FromEncodedObject; 2225 2226 2227 /** Coerce obj to an Unicode object and return a reference with 2228 _*incremented* refcount. 2229 2230 Unicode objects are passed back as-is (subclasses are converted to 2231 true Unicode objects), all other objects are delegated to 2232 PyUnicode_FromEncodedObject(obj, NULL, "strict") which results in 2233 using the default encoding as basis for decoding the object. 2234 2235 The API returns NULL in case of an error. The caller is responsible 2236 for decref'ing the returned objects. 2237 2238 */ 2239 PyObject* PyUnicodeUCS2_FromObject(PyObject* obj); 2240 /// ditto 2241 2242 alias PyUnicodeUCS2_FromObject PyUnicode_FromObject; 2243 2244 2245 /** Create a Unicode Object from the whcar_t buffer w of the given 2246 size. 2247 2248 The buffer is copied into the new object. */ 2249 PyObject* PyUnicodeUCS2_FromWideChar(const(wchar)* w, Py_ssize_t size); 2250 /// ditto 2251 2252 alias PyUnicodeUCS2_FromWideChar PyUnicode_FromWideChar; 2253 2254 2255 /** Copies the Unicode Object contents into the wchar_t buffer w. At 2256 most size wchar_t characters are copied. 2257 2258 Note that the resulting wchar_t string may or may not be 2259 0-terminated. It is the responsibility of the caller to make sure 2260 that the wchar_t string is 0-terminated in case this is required by 2261 the application. 2262 2263 Returns the number of wchar_t characters copied (excluding a 2264 possibly trailing 0-termination character) or -1 in case of an 2265 error. */ 2266 Py_ssize_t PyUnicodeUCS2_AsWideChar( 2267 PyUnicodeObject* unicode, 2268 const(wchar)* w, 2269 Py_ssize_t size); 2270 /// ditto 2271 2272 alias PyUnicodeUCS2_AsWideChar PyUnicode_AsWideChar; 2273 2274 2275 /** Create a Unicode Object from the given Unicode code point ordinal. 2276 2277 The ordinal must be in range(0x10000) on narrow Python builds 2278 (UCS2), and range(0x110000) on wide builds (UCS4). A ValueError is 2279 raised in case it is not. 2280 2281 */ 2282 PyObject* PyUnicodeUCS2_FromOrdinal(int ordinal); 2283 /// ditto 2284 2285 alias PyUnicodeUCS2_FromOrdinal PyUnicode_FromOrdinal; 2286 2287 2288 /** Return a Python string holding the default encoded value of the 2289 Unicode object. 2290 2291 The resulting string is cached in the Unicode object for subsequent 2292 usage by this function. The cached version is needed to implement 2293 the character buffer interface and will live (at least) as long as 2294 the Unicode object itself. 2295 2296 The refcount of the string is *not* incremented. 2297 2298 _*** Exported for internal use by the interpreter only !!! *** 2299 2300 */ 2301 PyObject* _PyUnicodeUCS2_AsDefaultEncodedString(PyObject *, const(char)*); 2302 /// ditto 2303 2304 alias _PyUnicodeUCS2_AsDefaultEncodedString _PyUnicode_AsDefaultEncodedString; 2305 2306 2307 /** Returns the currently active default encoding. 2308 2309 The default encoding is currently implemented as run-time settable 2310 process global. This may change in future versions of the 2311 interpreter to become a parameter which is managed on a per-thread 2312 basis. 2313 2314 */ 2315 const(char)* PyUnicodeUCS2_GetDefaultEncoding(); 2316 /// ditto 2317 2318 alias PyUnicodeUCS2_GetDefaultEncoding PyUnicode_GetDefaultEncoding; 2319 2320 2321 /** Sets the currently active default encoding. 2322 2323 Returns 0 on success, -1 in case of an error. 2324 2325 */ 2326 int PyUnicodeUCS2_SetDefaultEncoding(const(char)*encoding); 2327 /// ditto 2328 2329 alias PyUnicodeUCS2_SetDefaultEncoding PyUnicode_SetDefaultEncoding; 2330 2331 2332 /** Create a Unicode object by decoding the encoded string s of the 2333 given size. 2334 Params: 2335 s = encoded string 2336 size = size of buffer 2337 encoding = encoding 2338 errors = error handling 2339 */ 2340 PyObject* PyUnicodeUCS2_Decode( 2341 const(char)* s, 2342 Py_ssize_t size, 2343 const(char)* encoding, 2344 const(char)* errors); 2345 /// ditto 2346 2347 alias PyUnicodeUCS2_Decode PyUnicode_Decode; 2348 2349 2350 version(Python_3_0_Or_Later) { 2351 /** Decode a Unicode object unicode and return the result as Python 2352 object. */ 2353 /// Availability: 3.* 2354 2355 PyObject* PyUnicodeUCS2_AsDecodedObject( 2356 PyObject* unicode, 2357 const(char)* encoding, 2358 const(char)* errors 2359 ); 2360 /// ditto 2361 2362 alias PyUnicodeUCS2_AsDecodedObject PyUnicode_AsDecodedObject; 2363 2364 /** Decode a Unicode object unicode and return the result as Unicode 2365 object. */ 2366 /// Availability: 3.* 2367 2368 PyObject* PyUnicodeUCS2_AsDecodedUnicode( 2369 PyObject* unicode, 2370 const(char)* encoding, 2371 const(char)* errors 2372 ); 2373 /// ditto 2374 2375 alias PyUnicodeUCS2_AsDecodedUnicode PyUnicode_AsDecodedUnicode; 2376 2377 } 2378 2379 /** Encodes a Py_UNICODE buffer of the given size and returns a 2380 Python string object. 2381 Params: 2382 s = Unicode char buffer 2383 size = number of Py_UNICODE chars to encode 2384 encoding = encoding 2385 errors = error handling 2386 */ 2387 PyObject* PyUnicodeUCS2_Encode( 2388 Py_UNICODE* s, 2389 Py_ssize_t size, 2390 const(char)* encoding, 2391 const(char)* errors); 2392 /// ditto 2393 2394 alias PyUnicodeUCS2_Encode PyUnicode_Encode; 2395 2396 2397 /** Encodes a Unicode object and returns the result as Python object. 2398 */ 2399 PyObject* PyUnicodeUCS2_AsEncodedObject( 2400 PyObject* unicode, 2401 const(char)* encoding, 2402 const(char)* errors); 2403 /// ditto 2404 2405 alias PyUnicodeUCS2_AsEncodedObject PyUnicode_AsEncodedObject; 2406 2407 2408 /** Encodes a Unicode object and returns the result as Python string 2409 object. */ 2410 PyObject* PyUnicodeUCS2_AsEncodedString( 2411 PyObject* unicode, 2412 const(char)* encoding, 2413 const(char)* errors); 2414 /// ditto 2415 2416 alias PyUnicodeUCS2_AsEncodedString PyUnicode_AsEncodedString; 2417 2418 2419 version(Python_3_0_Or_Later) { 2420 /** Encodes a Unicode object and returns the result as Unicode 2421 object. */ 2422 /// Availability: >= 3.* 2423 PyObject* PyUnicodeUCS2_AsEncodedUnicode( 2424 PyObject* unicode, 2425 const(char)* encoding, 2426 const(char)* errors 2427 ); 2428 /// ditto 2429 2430 alias PyUnicodeUCS2_AsEncodedUnicode PyUnicode_AsEncodedUnicode; 2431 2432 } 2433 2434 /** 2435 Params: 2436 string = UTF-7 encoded string 2437 length = size of string 2438 errors = error handling 2439 */ 2440 PyObject* PyUnicodeUCS2_DecodeUTF7( 2441 const(char)* string, 2442 Py_ssize_t length, 2443 const(char)* errors); 2444 /// ditto 2445 2446 alias PyUnicodeUCS2_DecodeUTF7 PyUnicode_DecodeUTF7; 2447 2448 2449 /** 2450 Params: 2451 data = Unicode char buffer 2452 length = number of Py_UNICODE chars to encode 2453 base64SetO = Encode RFC2152 Set O characters in base64 2454 base64WhiteSpace = Encode whitespace (sp, ht, nl, cr) in base64 2455 errors = error handling 2456 */ 2457 PyObject* PyUnicodeUCS2_EncodeUTF7( 2458 Py_UNICODE* data, 2459 Py_ssize_t length, 2460 int encodeSetO, 2461 int encodeWhiteSpace, 2462 const(char)* errors 2463 ); 2464 /// ditto 2465 2466 alias PyUnicodeUCS2_EncodeUTF7 PyUnicode_EncodeUTF7; 2467 2468 2469 /// _ 2470 PyObject* PyUnicodeUCS2_DecodeUTF8( 2471 const(char)* string, 2472 Py_ssize_t length, 2473 const(char)* errors); 2474 /// ditto 2475 2476 alias PyUnicodeUCS2_DecodeUTF8 PyUnicode_DecodeUTF8; 2477 2478 /// _ 2479 PyObject* PyUnicodeUCS2_DecodeUTF8Stateful( 2480 const(char)* string, 2481 Py_ssize_t length, 2482 const(char)* errors, 2483 Py_ssize_t* consumed 2484 ); 2485 /// ditto 2486 2487 alias PyUnicodeUCS2_DecodeUTF8Stateful PyUnicode_DecodeUTF8Stateful; 2488 2489 /// _ 2490 PyObject* PyUnicodeUCS2_AsUTF8String(PyObject* unicode); 2491 /// ditto 2492 2493 alias PyUnicodeUCS2_AsUTF8String PyUnicode_AsUTF8String; 2494 2495 /// _ 2496 PyObject* PyUnicodeUCS2_EncodeUTF8( 2497 Py_UNICODE* data, 2498 Py_ssize_t length, 2499 const(char) *errors); 2500 /// ditto 2501 2502 alias PyUnicodeUCS2_EncodeUTF8 PyUnicode_EncodeUTF8; 2503 2504 2505 /** Decodes length bytes from a UTF-16 encoded buffer string and returns 2506 the corresponding Unicode object. 2507 2508 errors (if non-NULL) defines the error handling. It defaults 2509 to "strict". 2510 2511 If byteorder is non-NULL, the decoder starts decoding using the 2512 given byte order: 2513 2514 *byteorder == -1: little endian 2515 *byteorder == 0: native order 2516 *byteorder == 1: big endian 2517 2518 In native mode, the first two bytes of the stream are checked for a 2519 BOM mark. If found, the BOM mark is analysed, the byte order 2520 adjusted and the BOM skipped. In the other modes, no BOM mark 2521 interpretation is done. After completion, *byteorder is set to the 2522 current byte order at the end of input data. 2523 2524 If byteorder is NULL, the codec starts in native order mode. 2525 2526 */ 2527 PyObject* PyUnicodeUCS2_DecodeUTF16( 2528 const(char)* string, 2529 Py_ssize_t length, 2530 const(char)* errors, 2531 int* byteorder); 2532 /// ditto 2533 2534 alias PyUnicodeUCS2_DecodeUTF16 PyUnicode_DecodeUTF16; 2535 2536 /** 2537 Params: 2538 string = UTF-16 encoded string 2539 length = size of string 2540 errors = error handling 2541 byteorder = pointer to byteorder to use 0=native;-1=LE,1=BE; updated on exit 2542 consumed = bytes consumed 2543 */ 2544 PyObject* PyUnicodeUCS2_DecodeUTF16Stateful( 2545 const(char)* string, 2546 Py_ssize_t length, 2547 const(char)* errors, 2548 int* byteorder, 2549 Py_ssize_t* consumed 2550 ); 2551 /// ditto 2552 2553 alias PyUnicodeUCS2_DecodeUTF16Stateful PyUnicode_DecodeUTF16Stateful; 2554 2555 /** Returns a Python string using the UTF-16 encoding in native byte 2556 order. The string always starts with a BOM mark. */ 2557 PyObject* PyUnicodeUCS2_AsUTF16String(PyObject *unicode); 2558 /// ditto 2559 2560 alias PyUnicodeUCS2_AsUTF16String PyUnicode_AsUTF16String; 2561 2562 /** Returns a Python string object holding the UTF-16 encoded value of 2563 the Unicode data. 2564 2565 If byteorder is not 0, output is written according to the following 2566 byte order: 2567 2568 byteorder == -1: little endian 2569 byteorder == 0: native byte order (writes a BOM mark) 2570 byteorder == 1: big endian 2571 2572 If byteorder is 0, the output string will always start with the 2573 Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is 2574 prepended. 2575 2576 Note that Py_UNICODE data is being interpreted as UTF-16 reduced to 2577 UCS-2. This trick makes it possible to add full UTF-16 capabilities 2578 at a later point without compromising the APIs. 2579 2580 */ 2581 PyObject* PyUnicodeUCS2_EncodeUTF16( 2582 Py_UNICODE* data, 2583 Py_ssize_t length, 2584 const(char)* errors, 2585 int byteorder 2586 ); 2587 /// ditto 2588 2589 alias PyUnicodeUCS2_EncodeUTF16 PyUnicode_EncodeUTF16; 2590 2591 2592 /// _ 2593 PyObject* PyUnicodeUCS2_DecodeUnicodeEscape( 2594 const(char)* string, 2595 Py_ssize_t length, 2596 const(char)* errors); 2597 /// ditto 2598 2599 alias PyUnicodeUCS2_DecodeUnicodeEscape PyUnicode_DecodeUnicodeEscape; 2600 2601 /// _ 2602 PyObject* PyUnicodeUCS2_AsUnicodeEscapeString( 2603 PyObject* unicode); 2604 /// ditto 2605 2606 alias PyUnicodeUCS2_AsUnicodeEscapeString PyUnicode_AsUnicodeEscapeString; 2607 2608 /// _ 2609 PyObject* PyUnicodeUCS2_EncodeUnicodeEscape( 2610 Py_UNICODE* data, 2611 Py_ssize_t length); 2612 /// ditto 2613 2614 alias PyUnicodeUCS2_EncodeUnicodeEscape PyUnicode_EncodeUnicodeEscape; 2615 2616 /** 2617 Params: 2618 string = Raw-Unicode-Escape encoded string 2619 length = size of string 2620 errors = error handling 2621 */ 2622 PyObject* PyUnicodeUCS2_DecodeRawUnicodeEscape( 2623 const(char)* string, 2624 Py_ssize_t length, 2625 const(char)* errors); 2626 /// ditto 2627 2628 alias PyUnicodeUCS2_DecodeRawUnicodeEscape PyUnicode_DecodeRawUnicodeEscape; 2629 2630 /// _ 2631 PyObject* PyUnicodeUCS2_AsRawUnicodeEscapeString(PyObject* unicode); 2632 /// ditto 2633 2634 alias PyUnicodeUCS2_AsRawUnicodeEscapeString PyUnicode_AsRawUnicodeEscapeString; 2635 2636 /// _ 2637 PyObject* PyUnicodeUCS2_EncodeRawUnicodeEscape( 2638 Py_UNICODE* data, Py_ssize_t length); 2639 /// ditto 2640 2641 alias PyUnicodeUCS2_EncodeRawUnicodeEscape PyUnicode_EncodeRawUnicodeEscape; 2642 2643 2644 /// _ 2645 PyObject* _PyUnicodeUCS2_DecodeUnicodeInternal( 2646 const(char)* string, 2647 Py_ssize_t length, 2648 const(char)* errors); 2649 /// ditto 2650 2651 alias _PyUnicodeUCS2_DecodeUnicodeInternal _PyUnicode_DecodeUnicodeInternal; 2652 2653 2654 /** 2655 Params: 2656 string = Latin-1 encoded string 2657 length = size of string 2658 errors = error handling 2659 */ 2660 PyObject* PyUnicodeUCS2_DecodeLatin1( 2661 const(char)* string, 2662 Py_ssize_t length, 2663 const(char)* errors); 2664 /// ditto 2665 2666 alias PyUnicodeUCS2_DecodeLatin1 PyUnicode_DecodeLatin1; 2667 2668 /// _ 2669 PyObject* PyUnicodeUCS2_AsLatin1String(PyObject *unicode); 2670 /// ditto 2671 2672 alias PyUnicodeUCS2_AsLatin1String PyUnicode_AsLatin1String; 2673 2674 /** 2675 Params: 2676 data = Unicode char buffer 2677 length = Number of Py_UNICODE chars to encode 2678 errors = error handling 2679 */ 2680 PyObject* PyUnicodeUCS2_EncodeLatin1( 2681 Py_UNICODE* data, 2682 Py_ssize_t length, 2683 const(char)* errors); 2684 /// ditto 2685 2686 alias PyUnicodeUCS2_EncodeLatin1 PyUnicode_EncodeLatin1; 2687 2688 2689 /** 2690 Params: 2691 data = Unicode char buffer 2692 length = Number of Py_UNICODE chars to encode 2693 errors = error handling 2694 */ 2695 PyObject* PyUnicodeUCS2_DecodeASCII( 2696 const(char)* string, 2697 Py_ssize_t length, 2698 const(char)* errors); 2699 /// ditto 2700 2701 alias PyUnicodeUCS2_DecodeASCII PyUnicode_DecodeASCII; 2702 2703 /// _ 2704 PyObject* PyUnicodeUCS2_AsASCIIString(PyObject *unicode); 2705 /// ditto 2706 2707 alias PyUnicodeUCS2_AsASCIIString PyUnicode_AsASCIIString; 2708 2709 /** 2710 Params: 2711 data = Unicode char buffer 2712 length = Number of Py_UNICODE chars to encode 2713 errors = error handling 2714 */ 2715 PyObject* PyUnicodeUCS2_EncodeASCII( 2716 Py_UNICODE* data, 2717 Py_ssize_t length, 2718 const(char)* errors); 2719 /// ditto 2720 2721 alias PyUnicodeUCS2_EncodeASCII PyUnicode_EncodeASCII; 2722 2723 2724 /** 2725 Params: 2726 string = Encoded string 2727 length = size of string 2728 mapping = character mapping (char ordinal -> unicode ordinal) 2729 errors = error handling 2730 */ 2731 PyObject* PyUnicodeUCS2_DecodeCharmap( 2732 const(char)* string, 2733 Py_ssize_t length, 2734 PyObject* mapping, 2735 const(char)* errors 2736 ); 2737 /// ditto 2738 2739 alias PyUnicodeUCS2_DecodeCharmap PyUnicode_DecodeCharmap; 2740 2741 /** 2742 Params: 2743 unicode = Unicode object 2744 mapping = character mapping (unicode ordinal -> char ordinal) 2745 */ 2746 PyObject* PyUnicodeUCS2_AsCharmapString( 2747 PyObject* unicode, 2748 PyObject* mapping); 2749 /// ditto 2750 2751 alias PyUnicodeUCS2_AsCharmapString PyUnicode_AsCharmapString; 2752 2753 /** 2754 Params: 2755 data = Unicode char buffer 2756 length = Number of Py_UNICODE chars to encode 2757 mapping = character mapping (unicode ordinal -> char ordinal) 2758 errors = error handling 2759 */ 2760 PyObject* PyUnicodeUCS2_EncodeCharmap( 2761 Py_UNICODE* data, 2762 Py_ssize_t length, 2763 PyObject* mapping, 2764 const(char)* errors 2765 ); 2766 /// ditto 2767 2768 alias PyUnicodeUCS2_EncodeCharmap PyUnicode_EncodeCharmap; 2769 2770 /** Translate a Py_UNICODE buffer of the given length by applying a 2771 character mapping table to it and return the resulting Unicode 2772 object. 2773 2774 The mapping table must map Unicode ordinal integers to Unicode 2775 ordinal integers or None (causing deletion of the character). 2776 2777 Mapping tables may be dictionaries or sequences. Unmapped character 2778 ordinals (ones which cause a LookupError) are left untouched and 2779 are copied as-is. 2780 2781 */ 2782 PyObject* PyUnicodeUCS2_TranslateCharmap( 2783 Py_UNICODE* data, 2784 Py_ssize_t length, 2785 PyObject* table, 2786 const(char)* errors 2787 ); 2788 /// ditto 2789 2790 alias PyUnicodeUCS2_TranslateCharmap PyUnicode_TranslateCharmap; 2791 2792 2793 version (Windows) { 2794 /// Availability: Windows only 2795 PyObject* PyUnicodeUCS2_DecodeMBCS( 2796 const(char)* string, 2797 Py_ssize_t length, 2798 const(char)* errors); 2799 /// ditto 2800 2801 alias PyUnicodeUCS2_DecodeMBCS PyUnicode_DecodeMBCS; 2802 2803 /// Availability: Windows only 2804 PyObject* PyUnicodeUCS2_AsMBCSString(PyObject* unicode); 2805 /// ditto 2806 2807 alias PyUnicodeUCS2_AsMBCSString PyUnicode_AsMBCSString; 2808 2809 /// Availability: Windows only 2810 PyObject* PyUnicodeUCS2_EncodeMBCS( 2811 Py_UNICODE* data, 2812 Py_ssize_t length, 2813 const(char)* errors); 2814 /// ditto 2815 2816 alias PyUnicodeUCS2_EncodeMBCS PyUnicode_EncodeMBCS; 2817 2818 } 2819 /** Takes a Unicode string holding a decimal value and writes it into 2820 an output buffer using standard ASCII digit codes. 2821 2822 The output buffer has to provide at least length+1 bytes of storage 2823 area. The output string is 0-terminated. 2824 2825 The encoder converts whitespace to ' ', decimal characters to their 2826 corresponding ASCII digit and all other Latin-1 characters except 2827 \0 as-is. Characters outside this range (Unicode ordinals 1-256) 2828 are treated as errors. This includes embedded NULL bytes. 2829 2830 Error handling is defined by the errors argument: 2831 2832 NULL or "strict": raise a ValueError 2833 "ignore": ignore the wrong characters (these are not copied to the 2834 output buffer) 2835 "replace": replaces illegal characters with '?' 2836 2837 Returns 0 on success, -1 on failure. 2838 2839 */ 2840 int PyUnicodeUCS2_EncodeDecimal( 2841 Py_UNICODE* s, 2842 Py_ssize_t length, 2843 char* output, 2844 const(char)* errors); 2845 /// ditto 2846 2847 alias PyUnicodeUCS2_EncodeDecimal PyUnicode_EncodeDecimal; 2848 2849 2850 /** Concat two strings giving a new Unicode string. */ 2851 PyObject* PyUnicodeUCS2_Concat( 2852 PyObject* left, 2853 PyObject* right); 2854 /// ditto 2855 2856 alias PyUnicodeUCS2_Concat PyUnicode_Concat; 2857 2858 2859 version(Python_3_0_Or_Later) { 2860 /** Concat two strings and put the result in *pleft 2861 (sets *pleft to NULL on error) 2862 Params: 2863 pleft = Pointer to left string 2864 right = Right string 2865 */ 2866 /// Availability: 3.* 2867 2868 void PyUnicodeUCS2_Append( 2869 PyObject** pleft, 2870 PyObject* right 2871 ); 2872 /// ditto 2873 2874 alias PyUnicodeUCS2_Append PyUnicode_Append; 2875 2876 2877 /** Concat two strings, put the result in *pleft and drop the right object 2878 (sets *pleft to NULL on error) 2879 Params: 2880 pleft = Pointer to left string 2881 */ 2882 /// Availability: 3.* 2883 void PyUnicodeUCS2_AppendAndDel( 2884 PyObject** pleft, 2885 PyObject* right 2886 ); 2887 /// ditto 2888 2889 alias PyUnicodeUCS2_AppendAndDel PyUnicode_AppendAndDel; 2890 2891 } 2892 2893 /** Split a string giving a list of Unicode strings. 2894 2895 If sep is NULL, splitting will be done at all whitespace 2896 substrings. Otherwise, splits occur at the given separator. 2897 2898 At most maxsplit splits will be done. If negative, no limit is set. 2899 2900 Separators are not included in the resulting list. 2901 2902 */ 2903 PyObject* PyUnicodeUCS2_Split( 2904 PyObject* s, 2905 PyObject* sep, 2906 Py_ssize_t maxsplit); 2907 /// ditto 2908 2909 alias PyUnicodeUCS2_Split PyUnicode_Split; 2910 2911 2912 /** Ditto PyUnicode_Split, but split at line breaks. 2913 2914 CRLF is considered to be one line break. Line breaks are not 2915 included in the resulting list. */ 2916 PyObject* PyUnicodeUCS2_Splitlines( 2917 PyObject* s, 2918 int keepends); 2919 /// ditto 2920 2921 alias PyUnicodeUCS2_Splitlines PyUnicode_Splitlines; 2922 2923 2924 version(Python_2_5_Or_Later) { 2925 /** Partition a string using a given separator. */ 2926 /// Availability: >= 2.5 2927 PyObject* PyUnicodeUCS2_Partition( 2928 PyObject* s, 2929 PyObject* sep 2930 ); 2931 /// ditto 2932 2933 alias PyUnicodeUCS2_Partition PyUnicode_Partition; 2934 2935 2936 /** Partition a string using a given separator, searching from the end 2937 of the string. */ 2938 2939 PyObject* PyUnicodeUCS2_RPartition( 2940 PyObject* s, 2941 PyObject* sep 2942 ); 2943 /// ditto 2944 2945 alias PyUnicodeUCS2_RPartition PyUnicode_RPartition; 2946 2947 } 2948 2949 /** Split a string giving a list of Unicode strings. 2950 2951 If sep is NULL, splitting will be done at all whitespace 2952 substrings. Otherwise, splits occur at the given separator. 2953 2954 At most maxsplit splits will be done. But unlike PyUnicode_Split 2955 PyUnicode_RSplit splits from the end of the string. If negative, 2956 no limit is set. 2957 2958 Separators are not included in the resulting list. 2959 2960 */ 2961 PyObject* PyUnicodeUCS2_RSplit( 2962 PyObject* s, 2963 PyObject* sep, 2964 Py_ssize_t maxsplit); 2965 /// ditto 2966 2967 alias PyUnicodeUCS2_RSplit PyUnicode_RSplit; 2968 2969 2970 /** Translate a string by applying a character mapping table to it and 2971 return the resulting Unicode object. 2972 2973 The mapping table must map Unicode ordinal integers to Unicode 2974 ordinal integers or None (causing deletion of the character). 2975 2976 Mapping tables may be dictionaries or sequences. Unmapped character 2977 ordinals (ones which cause a LookupError) are left untouched and 2978 are copied as-is. 2979 2980 */ 2981 PyObject* PyUnicodeUCS2_Translate( 2982 PyObject* str, 2983 PyObject* table, 2984 const(char)* errors); 2985 /// ditto 2986 2987 alias PyUnicodeUCS2_Translate PyUnicode_Translate; 2988 2989 2990 /** Join a sequence of strings using the given separator and return 2991 the resulting Unicode string. */ 2992 PyObject* PyUnicodeUCS2_Join( 2993 PyObject* separator, 2994 PyObject* seq); 2995 /// ditto 2996 2997 alias PyUnicodeUCS2_Join PyUnicode_Join; 2998 2999 3000 /** Return 1 if substr matches str[start:end] at the given tail end, 0 3001 otherwise. */ 3002 Py_ssize_t PyUnicodeUCS2_Tailmatch( 3003 PyObject* str, 3004 PyObject* substr, 3005 Py_ssize_t start, 3006 Py_ssize_t end, 3007 int direction 3008 ); 3009 /// ditto 3010 3011 alias PyUnicodeUCS2_Tailmatch PyUnicode_Tailmatch; 3012 3013 3014 /** Return the first position of substr in str[start:end] using the 3015 given search direction or -1 if not found. -2 is returned in case 3016 an error occurred and an exception is set. */ 3017 Py_ssize_t PyUnicodeUCS2_Find( 3018 PyObject* str, 3019 PyObject* substr, 3020 Py_ssize_t start, 3021 Py_ssize_t end, 3022 int direction 3023 ); 3024 /// ditto 3025 3026 alias PyUnicodeUCS2_Find PyUnicode_Find; 3027 3028 3029 /** Count the number of occurrences of substr in str[start:end]. */ 3030 Py_ssize_t PyUnicodeUCS2_Count( 3031 PyObject* str, 3032 PyObject* substr, 3033 Py_ssize_t start, 3034 Py_ssize_t end); 3035 /// ditto 3036 3037 alias PyUnicodeUCS2_Count PyUnicode_Count; 3038 3039 3040 /** Replace at most maxcount occurrences of substr in str with replstr 3041 and return the resulting Unicode object. */ 3042 PyObject* PyUnicodeUCS2_Replace( 3043 PyObject* str, 3044 PyObject* substr, 3045 PyObject* replstr, 3046 Py_ssize_t maxcount 3047 ); 3048 /// ditto 3049 3050 alias PyUnicodeUCS2_Replace PyUnicode_Replace; 3051 3052 3053 /** Compare two strings and return -1, 0, 1 for less than, equal, 3054 greater than resp. */ 3055 int PyUnicodeUCS2_Compare(PyObject* left, PyObject* right); 3056 /// ditto 3057 3058 alias PyUnicodeUCS2_Compare PyUnicode_Compare; 3059 3060 version(Python_3_0_Or_Later) { 3061 /** Compare two strings and return -1, 0, 1 for less than, equal, 3062 greater than resp. 3063 Params: 3064 left = 3065 right = ASCII-encoded string 3066 */ 3067 /// Availability: 3.* 3068 int PyUnicodeUCS2_CompareWithASCIIString( 3069 PyObject* left, 3070 const(char)* right 3071 ); 3072 /// ditto 3073 3074 alias PyUnicodeUCS2_CompareWithASCIIString PyUnicode_CompareWithASCIIString; 3075 3076 } 3077 3078 version(Python_2_5_Or_Later) { 3079 /** Rich compare two strings and return one of the following: 3080 3081 - NULL in case an exception was raised 3082 - Py_True or Py_False for successfuly comparisons 3083 - Py_NotImplemented in case the type combination is unknown 3084 3085 Note that Py_EQ and Py_NE comparisons can cause a UnicodeWarning in 3086 case the conversion of the arguments to Unicode fails with a 3087 UnicodeDecodeError. 3088 3089 Possible values for op: 3090 3091 Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE 3092 3093 */ 3094 /// Availability: >= 2.5 3095 PyObject* PyUnicodeUCS2_RichCompare( 3096 PyObject* left, 3097 PyObject* right, 3098 int op 3099 ); 3100 /// ditto 3101 3102 alias PyUnicodeUCS2_RichCompare PyUnicode_RichCompare; 3103 3104 } 3105 3106 /** Apply a argument tuple or dictionary to a format string and return 3107 the resulting Unicode string. */ 3108 PyObject* PyUnicodeUCS2_Format(PyObject* format, PyObject* args); 3109 /// ditto 3110 3111 alias PyUnicodeUCS2_Format PyUnicode_Format; 3112 3113 3114 /** Checks whether element is contained in container and return 1/0 3115 accordingly. 3116 3117 element has to coerce to an one element Unicode string. -1 is 3118 returned in case of an error. */ 3119 int PyUnicodeUCS2_Contains(PyObject* container, PyObject* element); 3120 /// ditto 3121 3122 alias PyUnicodeUCS2_Contains PyUnicode_Contains; 3123 3124 3125 version(Python_3_0_Or_Later) { 3126 /** Checks whether argument is a valid identifier. */ 3127 /// Availability: 3.* 3128 int PyUnicodeUCS2_IsIdentifier(PyObject* s); 3129 /// ditto 3130 3131 alias PyUnicodeUCS2_IsIdentifier PyUnicode_IsIdentifier; 3132 3133 } 3134 3135 3136 /// _ 3137 int _PyUnicodeUCS2_IsLowercase(Py_UNICODE ch); 3138 /// ditto 3139 3140 alias _PyUnicodeUCS2_IsLowercase _PyUnicode_IsLowercase; 3141 3142 /// _ 3143 int _PyUnicodeUCS2_IsUppercase(Py_UNICODE ch); 3144 /// ditto 3145 3146 alias _PyUnicodeUCS2_IsUppercase _PyUnicode_IsUppercase; 3147 3148 /// _ 3149 int _PyUnicodeUCS2_IsTitlecase(Py_UNICODE ch); 3150 /// ditto 3151 3152 alias _PyUnicodeUCS2_IsTitlecase _PyUnicode_IsTitlecase; 3153 3154 /// _ 3155 int _PyUnicodeUCS2_IsWhitespace(Py_UNICODE ch); 3156 /// ditto 3157 3158 alias _PyUnicodeUCS2_IsWhitespace _PyUnicode_IsWhitespace; 3159 3160 /// _ 3161 int _PyUnicodeUCS2_IsLinebreak(Py_UNICODE ch); 3162 /// ditto 3163 3164 alias _PyUnicodeUCS2_IsLinebreak _PyUnicode_IsLinebreak; 3165 3166 /// _ 3167 Py_UNICODE _PyUnicodeUCS2_ToLowercase(Py_UNICODE ch); 3168 /// ditto 3169 3170 alias _PyUnicodeUCS2_ToLowercase _PyUnicode_ToLowercase; 3171 3172 /// _ 3173 Py_UNICODE _PyUnicodeUCS2_ToUppercase(Py_UNICODE ch); 3174 /// ditto 3175 3176 alias _PyUnicodeUCS2_ToUppercase _PyUnicode_ToUppercase; 3177 3178 /// _ 3179 Py_UNICODE _PyUnicodeUCS2_ToTitlecase(Py_UNICODE ch); 3180 /// ditto 3181 3182 alias _PyUnicodeUCS2_ToTitlecase _PyUnicode_ToTitlecase; 3183 3184 /// _ 3185 int _PyUnicodeUCS2_ToDecimalDigit(Py_UNICODE ch); 3186 /// ditto 3187 3188 alias _PyUnicodeUCS2_ToDecimalDigit _PyUnicode_ToDecimalDigit; 3189 3190 /// _ 3191 int _PyUnicodeUCS2_ToDigit(Py_UNICODE ch); 3192 /// ditto 3193 3194 alias _PyUnicodeUCS2_ToDigit _PyUnicode_ToDigit; 3195 3196 /// _ 3197 double _PyUnicodeUCS2_ToNumeric(Py_UNICODE ch); 3198 /// ditto 3199 3200 alias _PyUnicodeUCS2_ToNumeric _PyUnicode_ToNumeric; 3201 3202 /// _ 3203 int _PyUnicodeUCS2_IsDecimalDigit(Py_UNICODE ch); 3204 /// ditto 3205 3206 alias _PyUnicodeUCS2_IsDecimalDigit _PyUnicode_IsDecimalDigit; 3207 3208 /// _ 3209 int _PyUnicodeUCS2_IsDigit(Py_UNICODE ch); 3210 /// ditto 3211 3212 alias _PyUnicodeUCS2_IsDigit _PyUnicode_IsDigit; 3213 3214 /// _ 3215 int _PyUnicodeUCS2_IsNumeric(Py_UNICODE ch); 3216 /// ditto 3217 3218 alias _PyUnicodeUCS2_IsNumeric _PyUnicode_IsNumeric; 3219 3220 /// _ 3221 int _PyUnicodeUCS2_IsAlpha(Py_UNICODE ch); 3222 /// ditto 3223 3224 alias _PyUnicodeUCS2_IsAlpha _PyUnicode_IsAlpha; 3225 3226 }else{ 3227 3228 version(Python_2_6_Or_Later) { 3229 3230 /** Create a Unicode Object from the Py_UNICODE buffer u of the given 3231 size. 3232 3233 u may be NULL which causes the contents to be undefined. It is the 3234 user's responsibility to fill in the needed data afterwards. Note 3235 that modifying the Unicode object contents after construction is 3236 only allowed if u was set to NULL. 3237 3238 The buffer is copied into the new object. */ 3239 /// Availability: >= 2.6 3240 PyObject* PyUnicodeUCS4_FromUnicode(Py_UNICODE* u, Py_ssize_t size); 3241 /// ditto 3242 3243 alias PyUnicodeUCS4_FromUnicode PyUnicode_FromUnicode; 3244 3245 3246 /** Similar to PyUnicode_FromUnicode(), but u points to Latin-1 encoded bytes */ 3247 /// Availability: >= 2.6 3248 PyObject* PyUnicodeUCS4_FromStringAndSize( 3249 const(char)*u, /* char buffer */ 3250 Py_ssize_t size /* size of buffer */ 3251 ); 3252 /// ditto 3253 3254 alias PyUnicodeUCS4_FromStringAndSize PyUnicode_FromStringAndSize; 3255 3256 3257 /** Similar to PyUnicode_FromUnicode(), but u points to null-terminated 3258 Latin-1 encoded bytes */ 3259 /// Availability: >= 2.6 3260 PyObject* PyUnicodeUCS4_FromString( 3261 const(char)*u /* string */ 3262 ); 3263 /// ditto 3264 3265 alias PyUnicodeUCS4_FromString PyUnicode_FromString; 3266 3267 /// Availability: >= 2.6 3268 PyObject* PyUnicodeUCS4_FromFormatV(const(char)*, va_list); 3269 /// ditto 3270 3271 alias PyUnicodeUCS4_FromFormatV PyUnicode_FromFormatV; 3272 3273 /// Availability: >= 2.6 3274 PyObject* PyUnicodeUCS4_FromFormat(const(char)*, ...); 3275 /// ditto 3276 3277 alias PyUnicodeUCS4_FromFormat PyUnicode_FromFormat; 3278 3279 3280 /** Format the object based on the format_spec, as defined in PEP 3101 3281 (Advanced String Formatting). */ 3282 /// Availability: >= 2.6 3283 PyObject* _PyUnicodeUCS4_FormatAdvanced(PyObject *obj, 3284 Py_UNICODE *format_spec, 3285 Py_ssize_t format_spec_len); 3286 /// ditto 3287 3288 alias _PyUnicodeUCS4_FormatAdvanced _PyUnicode_FormatAdvanced; 3289 3290 /// Availability: >= 2.6 3291 int PyUnicodeUCS4_ClearFreeList(); 3292 /// ditto 3293 3294 alias PyUnicodeUCS4_ClearFreeList PyUnicode_ClearFreeList; 3295 3296 /** 3297 Params: 3298 string = UTF-7 encoded string 3299 length = size of string 3300 error = error handling 3301 consumed = bytes consumed 3302 */ 3303 /// Availability: >= 2.6 3304 PyObject* PyUnicodeUCS4_DecodeUTF7Stateful( 3305 const(char)* string, 3306 Py_ssize_t length, 3307 const(char)*errors, 3308 Py_ssize_t *consumed 3309 ); 3310 /// ditto 3311 3312 alias PyUnicodeUCS4_DecodeUTF7Stateful PyUnicode_DecodeUTF7Stateful; 3313 3314 /** 3315 Params: 3316 string = UTF-32 encoded string 3317 length = size of string 3318 error = error handling 3319 byteorder = pointer to byteorder to use 0=native;-1=LE,1=BE; updated on exit 3320 */ 3321 /// Availability: >= 2.6 3322 PyObject* PyUnicodeUCS4_DecodeUTF32( 3323 const(char)* string, 3324 Py_ssize_t length, 3325 const(char)*errors, 3326 int *byteorder 3327 ); 3328 /// ditto 3329 3330 alias PyUnicodeUCS4_DecodeUTF32 PyUnicode_DecodeUTF32; 3331 3332 3333 /** 3334 Params: 3335 string = UTF-32 encoded string 3336 length = size of string 3337 error = error handling 3338 byteorder = pointer to byteorder to use 0=native;-1=LE,1=BE; updated on exit 3339 */ 3340 /// Availability: >= 2.6 3341 PyObject* PyUnicodeUCS4_DecodeUTF32Stateful( 3342 const(char)*string, 3343 Py_ssize_t length, 3344 const(char)*errors, 3345 int *byteorder, 3346 Py_ssize_t *consumed 3347 ); 3348 /// ditto 3349 3350 alias PyUnicodeUCS4_DecodeUTF32Stateful PyUnicode_DecodeUTF32Stateful; 3351 3352 /** Returns a Python string using the UTF-32 encoding in native byte 3353 order. The string always starts with a BOM mark. */ 3354 /// Availability: >= 2.6 3355 3356 PyObject* PyUnicodeUCS4_AsUTF32String( 3357 PyObject *unicode 3358 ); 3359 /// ditto 3360 3361 alias PyUnicodeUCS4_AsUTF32String PyUnicode_AsUTF32String; 3362 3363 3364 /** Returns a Python string object holding the UTF-32 encoded value of 3365 the Unicode data. 3366 3367 If byteorder is not 0, output is written according to the following 3368 byte order: 3369 3370 byteorder == -1: little endian 3371 byteorder == 0: native byte order (writes a BOM mark) 3372 byteorder == 1: big endian 3373 3374 If byteorder is 0, the output string will always start with the 3375 Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is 3376 prepended. 3377 Params: 3378 data = Unicode char buffer 3379 length = number of Py_UNICODE chars to encode 3380 errors = error handling 3381 byteorder = byteorder to use 0=BOM+native;-1=LE,1=BE 3382 3383 */ 3384 /// Availability: >= 2.6 3385 PyObject* PyUnicodeUCS4_EncodeUTF32( 3386 const Py_UNICODE *data, 3387 Py_ssize_t length, 3388 const(char)* errors, 3389 int byteorder 3390 ); 3391 /// ditto 3392 3393 alias PyUnicodeUCS4_EncodeUTF32 PyUnicode_EncodeUTF32; 3394 3395 } 3396 3397 /** Return a read-only pointer to the Unicode object's internal 3398 Py_UNICODE buffer. */ 3399 Py_UNICODE* PyUnicodeUCS4_AsUnicode(PyObject* unicode); 3400 /// ditto 3401 3402 alias PyUnicodeUCS4_AsUnicode PyUnicode_AsUnicode; 3403 3404 /** Get the length of the Unicode object. */ 3405 Py_ssize_t PyUnicodeUCS4_GetSize(PyObject* unicode); 3406 /// ditto 3407 3408 alias PyUnicodeUCS4_GetSize PyUnicode_GetSize; 3409 3410 3411 /** Get the maximum ordinal for a Unicode character. */ 3412 Py_UNICODE PyUnicodeUCS4_GetMax(); 3413 /// ditto 3414 3415 alias PyUnicodeUCS4_GetMax PyUnicode_GetMax; 3416 3417 3418 /** Resize an already allocated Unicode object to the new size length. 3419 3420 _*unicode is modified to point to the new (resized) object and 0 3421 returned on success. 3422 3423 This API may only be called by the function which also called the 3424 Unicode constructor. The refcount on the object must be 1. Otherwise, 3425 an error is returned. 3426 3427 Error handling is implemented as follows: an exception is set, -1 3428 is returned and *unicode left untouched. 3429 Params: 3430 unicode = pointer to the new unicode object. 3431 length = New length. 3432 3433 */ 3434 int PyUnicodeUCS4_Resize(PyObject** unicode, Py_ssize_t length); 3435 /// ditto 3436 3437 alias PyUnicodeUCS4_Resize PyUnicode_Resize; 3438 3439 /** Coerce obj to an Unicode object and return a reference with 3440 _*incremented* refcount. 3441 3442 Coercion is done in the following way: 3443 3444 1. String and other char buffer compatible objects are decoded 3445 under the assumptions that they contain data using the current 3446 default encoding. Decoding is done in "strict" mode. 3447 3448 2. All other objects (including Unicode objects) raise an 3449 exception. 3450 3451 The API returns NULL in case of an error. The caller is responsible 3452 for decref'ing the returned objects. 3453 3454 */ 3455 PyObject* PyUnicodeUCS4_FromEncodedObject( 3456 PyObject* obj, 3457 const(char)* encoding, 3458 const(char)* errors); 3459 /// ditto 3460 3461 alias PyUnicodeUCS4_FromEncodedObject PyUnicode_FromEncodedObject; 3462 3463 3464 /** Coerce obj to an Unicode object and return a reference with 3465 _*incremented* refcount. 3466 3467 Unicode objects are passed back as-is (subclasses are converted to 3468 true Unicode objects), all other objects are delegated to 3469 PyUnicode_FromEncodedObject(obj, NULL, "strict") which results in 3470 using the default encoding as basis for decoding the object. 3471 3472 The API returns NULL in case of an error. The caller is responsible 3473 for decref'ing the returned objects. 3474 3475 */ 3476 PyObject* PyUnicodeUCS4_FromObject(PyObject* obj); 3477 /// ditto 3478 3479 alias PyUnicodeUCS4_FromObject PyUnicode_FromObject; 3480 3481 3482 /** Create a Unicode Object from the whcar_t buffer w of the given 3483 size. 3484 3485 The buffer is copied into the new object. */ 3486 PyObject* PyUnicodeUCS4_FromWideChar(const(wchar)* w, Py_ssize_t size); 3487 /// ditto 3488 3489 alias PyUnicodeUCS4_FromWideChar PyUnicode_FromWideChar; 3490 3491 3492 /** Copies the Unicode Object contents into the wchar_t buffer w. At 3493 most size wchar_t characters are copied. 3494 3495 Note that the resulting wchar_t string may or may not be 3496 0-terminated. It is the responsibility of the caller to make sure 3497 that the wchar_t string is 0-terminated in case this is required by 3498 the application. 3499 3500 Returns the number of wchar_t characters copied (excluding a 3501 possibly trailing 0-termination character) or -1 in case of an 3502 error. */ 3503 Py_ssize_t PyUnicodeUCS4_AsWideChar( 3504 PyUnicodeObject* unicode, 3505 const(wchar)* w, 3506 Py_ssize_t size); 3507 /// ditto 3508 3509 alias PyUnicodeUCS4_AsWideChar PyUnicode_AsWideChar; 3510 3511 3512 /** Create a Unicode Object from the given Unicode code point ordinal. 3513 3514 The ordinal must be in range(0x10000) on narrow Python builds 3515 (UCS2), and range(0x110000) on wide builds (UCS4). A ValueError is 3516 raised in case it is not. 3517 3518 */ 3519 PyObject* PyUnicodeUCS4_FromOrdinal(int ordinal); 3520 /// ditto 3521 3522 alias PyUnicodeUCS4_FromOrdinal PyUnicode_FromOrdinal; 3523 3524 3525 /** Return a Python string holding the default encoded value of the 3526 Unicode object. 3527 3528 The resulting string is cached in the Unicode object for subsequent 3529 usage by this function. The cached version is needed to implement 3530 the character buffer interface and will live (at least) as long as 3531 the Unicode object itself. 3532 3533 The refcount of the string is *not* incremented. 3534 3535 _*** Exported for internal use by the interpreter only !!! *** 3536 3537 */ 3538 PyObject* _PyUnicodeUCS4_AsDefaultEncodedString(PyObject *, const(char)*); 3539 /// ditto 3540 3541 alias _PyUnicodeUCS4_AsDefaultEncodedString _PyUnicode_AsDefaultEncodedString; 3542 3543 3544 /** Returns the currently active default encoding. 3545 3546 The default encoding is currently implemented as run-time settable 3547 process global. This may change in future versions of the 3548 interpreter to become a parameter which is managed on a per-thread 3549 basis. 3550 3551 */ 3552 const(char)* PyUnicodeUCS4_GetDefaultEncoding(); 3553 /// ditto 3554 3555 alias PyUnicodeUCS4_GetDefaultEncoding PyUnicode_GetDefaultEncoding; 3556 3557 3558 /** Sets the currently active default encoding. 3559 3560 Returns 0 on success, -1 in case of an error. 3561 3562 */ 3563 int PyUnicodeUCS4_SetDefaultEncoding(const(char)*encoding); 3564 /// ditto 3565 3566 alias PyUnicodeUCS4_SetDefaultEncoding PyUnicode_SetDefaultEncoding; 3567 3568 3569 /** Create a Unicode object by decoding the encoded string s of the 3570 given size. 3571 Params: 3572 s = encoded string 3573 size = size of buffer 3574 encoding = encoding 3575 errors = error handling 3576 */ 3577 PyObject* PyUnicodeUCS4_Decode( 3578 const(char)* s, 3579 Py_ssize_t size, 3580 const(char)* encoding, 3581 const(char)* errors); 3582 /// ditto 3583 3584 alias PyUnicodeUCS4_Decode PyUnicode_Decode; 3585 3586 3587 version(Python_3_0_Or_Later) { 3588 /** Decode a Unicode object unicode and return the result as Python 3589 object. */ 3590 /// Availability: 3.* 3591 3592 PyObject* PyUnicodeUCS4_AsDecodedObject( 3593 PyObject* unicode, 3594 const(char)* encoding, 3595 const(char)* errors 3596 ); 3597 /// ditto 3598 3599 alias PyUnicodeUCS4_AsDecodedObject PyUnicode_AsDecodedObject; 3600 3601 /** Decode a Unicode object unicode and return the result as Unicode 3602 object. */ 3603 /// Availability: 3.* 3604 3605 PyObject* PyUnicodeUCS4_AsDecodedUnicode( 3606 PyObject* unicode, 3607 const(char)* encoding, 3608 const(char)* errors 3609 ); 3610 /// ditto 3611 3612 alias PyUnicodeUCS4_AsDecodedUnicode PyUnicode_AsDecodedUnicode; 3613 3614 } 3615 3616 /** Encodes a Py_UNICODE buffer of the given size and returns a 3617 Python string object. 3618 Params: 3619 s = Unicode char buffer 3620 size = number of Py_UNICODE chars to encode 3621 encoding = encoding 3622 errors = error handling 3623 */ 3624 PyObject* PyUnicodeUCS4_Encode( 3625 Py_UNICODE* s, 3626 Py_ssize_t size, 3627 const(char)* encoding, 3628 const(char)* errors); 3629 /// ditto 3630 3631 alias PyUnicodeUCS4_Encode PyUnicode_Encode; 3632 3633 3634 /** Encodes a Unicode object and returns the result as Python object. 3635 */ 3636 PyObject* PyUnicodeUCS4_AsEncodedObject( 3637 PyObject* unicode, 3638 const(char)* encoding, 3639 const(char)* errors); 3640 /// ditto 3641 3642 alias PyUnicodeUCS4_AsEncodedObject PyUnicode_AsEncodedObject; 3643 3644 3645 /** Encodes a Unicode object and returns the result as Python string 3646 object. */ 3647 PyObject* PyUnicodeUCS4_AsEncodedString( 3648 PyObject* unicode, 3649 const(char)* encoding, 3650 const(char)* errors); 3651 /// ditto 3652 3653 alias PyUnicodeUCS4_AsEncodedString PyUnicode_AsEncodedString; 3654 3655 3656 version(Python_3_0_Or_Later) { 3657 /** Encodes a Unicode object and returns the result as Unicode 3658 object. */ 3659 /// Availability: >= 3.* 3660 PyObject* PyUnicodeUCS4_AsEncodedUnicode( 3661 PyObject* unicode, 3662 const(char)* encoding, 3663 const(char)* errors 3664 ); 3665 /// ditto 3666 3667 alias PyUnicodeUCS4_AsEncodedUnicode PyUnicode_AsEncodedUnicode; 3668 3669 } 3670 3671 /** 3672 Params: 3673 string = UTF-7 encoded string 3674 length = size of string 3675 errors = error handling 3676 */ 3677 PyObject* PyUnicodeUCS4_DecodeUTF7( 3678 const(char)* string, 3679 Py_ssize_t length, 3680 const(char)* errors); 3681 /// ditto 3682 3683 alias PyUnicodeUCS4_DecodeUTF7 PyUnicode_DecodeUTF7; 3684 3685 3686 /** 3687 Params: 3688 data = Unicode char buffer 3689 length = number of Py_UNICODE chars to encode 3690 base64SetO = Encode RFC2152 Set O characters in base64 3691 base64WhiteSpace = Encode whitespace (sp, ht, nl, cr) in base64 3692 errors = error handling 3693 */ 3694 PyObject* PyUnicodeUCS4_EncodeUTF7( 3695 Py_UNICODE* data, 3696 Py_ssize_t length, 3697 int encodeSetO, 3698 int encodeWhiteSpace, 3699 const(char)* errors 3700 ); 3701 /// ditto 3702 3703 alias PyUnicodeUCS4_EncodeUTF7 PyUnicode_EncodeUTF7; 3704 3705 3706 /// _ 3707 PyObject* PyUnicodeUCS4_DecodeUTF8( 3708 const(char)* string, 3709 Py_ssize_t length, 3710 const(char)* errors); 3711 /// ditto 3712 3713 alias PyUnicodeUCS4_DecodeUTF8 PyUnicode_DecodeUTF8; 3714 3715 /// _ 3716 PyObject* PyUnicodeUCS4_DecodeUTF8Stateful( 3717 const(char)* string, 3718 Py_ssize_t length, 3719 const(char)* errors, 3720 Py_ssize_t* consumed 3721 ); 3722 /// ditto 3723 3724 alias PyUnicodeUCS4_DecodeUTF8Stateful PyUnicode_DecodeUTF8Stateful; 3725 3726 /// _ 3727 PyObject* PyUnicodeUCS4_AsUTF8String(PyObject* unicode); 3728 /// ditto 3729 3730 alias PyUnicodeUCS4_AsUTF8String PyUnicode_AsUTF8String; 3731 3732 /// _ 3733 PyObject* PyUnicodeUCS4_EncodeUTF8( 3734 Py_UNICODE* data, 3735 Py_ssize_t length, 3736 const(char) *errors); 3737 /// ditto 3738 3739 alias PyUnicodeUCS4_EncodeUTF8 PyUnicode_EncodeUTF8; 3740 3741 3742 /** Decodes length bytes from a UTF-16 encoded buffer string and returns 3743 the corresponding Unicode object. 3744 3745 errors (if non-NULL) defines the error handling. It defaults 3746 to "strict". 3747 3748 If byteorder is non-NULL, the decoder starts decoding using the 3749 given byte order: 3750 3751 *byteorder == -1: little endian 3752 *byteorder == 0: native order 3753 *byteorder == 1: big endian 3754 3755 In native mode, the first two bytes of the stream are checked for a 3756 BOM mark. If found, the BOM mark is analysed, the byte order 3757 adjusted and the BOM skipped. In the other modes, no BOM mark 3758 interpretation is done. After completion, *byteorder is set to the 3759 current byte order at the end of input data. 3760 3761 If byteorder is NULL, the codec starts in native order mode. 3762 3763 */ 3764 PyObject* PyUnicodeUCS4_DecodeUTF16( 3765 const(char)* string, 3766 Py_ssize_t length, 3767 const(char)* errors, 3768 int* byteorder); 3769 /// ditto 3770 3771 alias PyUnicodeUCS4_DecodeUTF16 PyUnicode_DecodeUTF16; 3772 3773 /** 3774 Params: 3775 string = UTF-16 encoded string 3776 length = size of string 3777 errors = error handling 3778 byteorder = pointer to byteorder to use 0=native;-1=LE,1=BE; updated on exit 3779 consumed = bytes consumed 3780 */ 3781 PyObject* PyUnicodeUCS4_DecodeUTF16Stateful( 3782 const(char)* string, 3783 Py_ssize_t length, 3784 const(char)* errors, 3785 int* byteorder, 3786 Py_ssize_t* consumed 3787 ); 3788 /// ditto 3789 3790 alias PyUnicodeUCS4_DecodeUTF16Stateful PyUnicode_DecodeUTF16Stateful; 3791 3792 /** Returns a Python string using the UTF-16 encoding in native byte 3793 order. The string always starts with a BOM mark. */ 3794 PyObject* PyUnicodeUCS4_AsUTF16String(PyObject *unicode); 3795 /// ditto 3796 3797 alias PyUnicodeUCS4_AsUTF16String PyUnicode_AsUTF16String; 3798 3799 /** Returns a Python string object holding the UTF-16 encoded value of 3800 the Unicode data. 3801 3802 If byteorder is not 0, output is written according to the following 3803 byte order: 3804 3805 byteorder == -1: little endian 3806 byteorder == 0: native byte order (writes a BOM mark) 3807 byteorder == 1: big endian 3808 3809 If byteorder is 0, the output string will always start with the 3810 Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is 3811 prepended. 3812 3813 Note that Py_UNICODE data is being interpreted as UTF-16 reduced to 3814 UCS-2. This trick makes it possible to add full UTF-16 capabilities 3815 at a later point without compromising the APIs. 3816 3817 */ 3818 PyObject* PyUnicodeUCS4_EncodeUTF16( 3819 Py_UNICODE* data, 3820 Py_ssize_t length, 3821 const(char)* errors, 3822 int byteorder 3823 ); 3824 /// ditto 3825 3826 alias PyUnicodeUCS4_EncodeUTF16 PyUnicode_EncodeUTF16; 3827 3828 3829 /// _ 3830 PyObject* PyUnicodeUCS4_DecodeUnicodeEscape( 3831 const(char)* string, 3832 Py_ssize_t length, 3833 const(char)* errors); 3834 /// ditto 3835 3836 alias PyUnicodeUCS4_DecodeUnicodeEscape PyUnicode_DecodeUnicodeEscape; 3837 3838 /// _ 3839 PyObject* PyUnicodeUCS4_AsUnicodeEscapeString( 3840 PyObject* unicode); 3841 /// ditto 3842 3843 alias PyUnicodeUCS4_AsUnicodeEscapeString PyUnicode_AsUnicodeEscapeString; 3844 3845 /// _ 3846 PyObject* PyUnicodeUCS4_EncodeUnicodeEscape( 3847 Py_UNICODE* data, 3848 Py_ssize_t length); 3849 /// ditto 3850 3851 alias PyUnicodeUCS4_EncodeUnicodeEscape PyUnicode_EncodeUnicodeEscape; 3852 3853 /** 3854 Params: 3855 string = Raw-Unicode-Escape encoded string 3856 length = size of string 3857 errors = error handling 3858 */ 3859 PyObject* PyUnicodeUCS4_DecodeRawUnicodeEscape( 3860 const(char)* string, 3861 Py_ssize_t length, 3862 const(char)* errors); 3863 /// ditto 3864 3865 alias PyUnicodeUCS4_DecodeRawUnicodeEscape PyUnicode_DecodeRawUnicodeEscape; 3866 3867 /// _ 3868 PyObject* PyUnicodeUCS4_AsRawUnicodeEscapeString(PyObject* unicode); 3869 /// ditto 3870 3871 alias PyUnicodeUCS4_AsRawUnicodeEscapeString PyUnicode_AsRawUnicodeEscapeString; 3872 3873 /// _ 3874 PyObject* PyUnicodeUCS4_EncodeRawUnicodeEscape( 3875 Py_UNICODE* data, Py_ssize_t length); 3876 /// ditto 3877 3878 alias PyUnicodeUCS4_EncodeRawUnicodeEscape PyUnicode_EncodeRawUnicodeEscape; 3879 3880 3881 /// _ 3882 PyObject* _PyUnicodeUCS4_DecodeUnicodeInternal( 3883 const(char)* string, 3884 Py_ssize_t length, 3885 const(char)* errors); 3886 /// ditto 3887 3888 alias _PyUnicodeUCS4_DecodeUnicodeInternal _PyUnicode_DecodeUnicodeInternal; 3889 3890 3891 /** 3892 Params: 3893 string = Latin-1 encoded string 3894 length = size of string 3895 errors = error handling 3896 */ 3897 PyObject* PyUnicodeUCS4_DecodeLatin1( 3898 const(char)* string, 3899 Py_ssize_t length, 3900 const(char)* errors); 3901 /// ditto 3902 3903 alias PyUnicodeUCS4_DecodeLatin1 PyUnicode_DecodeLatin1; 3904 3905 /// _ 3906 PyObject* PyUnicodeUCS4_AsLatin1String(PyObject *unicode); 3907 /// ditto 3908 3909 alias PyUnicodeUCS4_AsLatin1String PyUnicode_AsLatin1String; 3910 3911 /** 3912 Params: 3913 data = Unicode char buffer 3914 length = Number of Py_UNICODE chars to encode 3915 errors = error handling 3916 */ 3917 PyObject* PyUnicodeUCS4_EncodeLatin1( 3918 Py_UNICODE* data, 3919 Py_ssize_t length, 3920 const(char)* errors); 3921 /// ditto 3922 3923 alias PyUnicodeUCS4_EncodeLatin1 PyUnicode_EncodeLatin1; 3924 3925 3926 /** 3927 Params: 3928 data = Unicode char buffer 3929 length = Number of Py_UNICODE chars to encode 3930 errors = error handling 3931 */ 3932 PyObject* PyUnicodeUCS4_DecodeASCII( 3933 const(char)* string, 3934 Py_ssize_t length, 3935 const(char)* errors); 3936 /// ditto 3937 3938 alias PyUnicodeUCS4_DecodeASCII PyUnicode_DecodeASCII; 3939 3940 /// _ 3941 PyObject* PyUnicodeUCS4_AsASCIIString(PyObject *unicode); 3942 /// ditto 3943 3944 alias PyUnicodeUCS4_AsASCIIString PyUnicode_AsASCIIString; 3945 3946 /** 3947 Params: 3948 data = Unicode char buffer 3949 length = Number of Py_UNICODE chars to encode 3950 errors = error handling 3951 */ 3952 PyObject* PyUnicodeUCS4_EncodeASCII( 3953 Py_UNICODE* data, 3954 Py_ssize_t length, 3955 const(char)* errors); 3956 /// ditto 3957 3958 alias PyUnicodeUCS4_EncodeASCII PyUnicode_EncodeASCII; 3959 3960 3961 /** 3962 Params: 3963 string = Encoded string 3964 length = size of string 3965 mapping = character mapping (char ordinal -> unicode ordinal) 3966 errors = error handling 3967 */ 3968 PyObject* PyUnicodeUCS4_DecodeCharmap( 3969 const(char)* string, 3970 Py_ssize_t length, 3971 PyObject* mapping, 3972 const(char)* errors 3973 ); 3974 /// ditto 3975 3976 alias PyUnicodeUCS4_DecodeCharmap PyUnicode_DecodeCharmap; 3977 3978 /** 3979 Params: 3980 unicode = Unicode object 3981 mapping = character mapping (unicode ordinal -> char ordinal) 3982 */ 3983 PyObject* PyUnicodeUCS4_AsCharmapString( 3984 PyObject* unicode, 3985 PyObject* mapping); 3986 /// ditto 3987 3988 alias PyUnicodeUCS4_AsCharmapString PyUnicode_AsCharmapString; 3989 3990 /** 3991 Params: 3992 data = Unicode char buffer 3993 length = Number of Py_UNICODE chars to encode 3994 mapping = character mapping (unicode ordinal -> char ordinal) 3995 errors = error handling 3996 */ 3997 PyObject* PyUnicodeUCS4_EncodeCharmap( 3998 Py_UNICODE* data, 3999 Py_ssize_t length, 4000 PyObject* mapping, 4001 const(char)* errors 4002 ); 4003 /// ditto 4004 4005 alias PyUnicodeUCS4_EncodeCharmap PyUnicode_EncodeCharmap; 4006 4007 /** Translate a Py_UNICODE buffer of the given length by applying a 4008 character mapping table to it and return the resulting Unicode 4009 object. 4010 4011 The mapping table must map Unicode ordinal integers to Unicode 4012 ordinal integers or None (causing deletion of the character). 4013 4014 Mapping tables may be dictionaries or sequences. Unmapped character 4015 ordinals (ones which cause a LookupError) are left untouched and 4016 are copied as-is. 4017 4018 */ 4019 PyObject* PyUnicodeUCS4_TranslateCharmap( 4020 Py_UNICODE* data, 4021 Py_ssize_t length, 4022 PyObject* table, 4023 const(char)* errors 4024 ); 4025 /// ditto 4026 4027 alias PyUnicodeUCS4_TranslateCharmap PyUnicode_TranslateCharmap; 4028 4029 4030 version (Windows) { 4031 /// Availability: Windows only 4032 PyObject* PyUnicodeUCS4_DecodeMBCS( 4033 const(char)* string, 4034 Py_ssize_t length, 4035 const(char)* errors); 4036 /// ditto 4037 4038 alias PyUnicodeUCS4_DecodeMBCS PyUnicode_DecodeMBCS; 4039 4040 /// Availability: Windows only 4041 PyObject* PyUnicodeUCS4_AsMBCSString(PyObject* unicode); 4042 /// ditto 4043 4044 alias PyUnicodeUCS4_AsMBCSString PyUnicode_AsMBCSString; 4045 4046 /// Availability: Windows only 4047 PyObject* PyUnicodeUCS4_EncodeMBCS( 4048 Py_UNICODE* data, 4049 Py_ssize_t length, 4050 const(char)* errors); 4051 /// ditto 4052 4053 alias PyUnicodeUCS4_EncodeMBCS PyUnicode_EncodeMBCS; 4054 4055 } 4056 /** Takes a Unicode string holding a decimal value and writes it into 4057 an output buffer using standard ASCII digit codes. 4058 4059 The output buffer has to provide at least length+1 bytes of storage 4060 area. The output string is 0-terminated. 4061 4062 The encoder converts whitespace to ' ', decimal characters to their 4063 corresponding ASCII digit and all other Latin-1 characters except 4064 \0 as-is. Characters outside this range (Unicode ordinals 1-256) 4065 are treated as errors. This includes embedded NULL bytes. 4066 4067 Error handling is defined by the errors argument: 4068 4069 NULL or "strict": raise a ValueError 4070 "ignore": ignore the wrong characters (these are not copied to the 4071 output buffer) 4072 "replace": replaces illegal characters with '?' 4073 4074 Returns 0 on success, -1 on failure. 4075 4076 */ 4077 int PyUnicodeUCS4_EncodeDecimal( 4078 Py_UNICODE* s, 4079 Py_ssize_t length, 4080 char* output, 4081 const(char)* errors); 4082 /// ditto 4083 4084 alias PyUnicodeUCS4_EncodeDecimal PyUnicode_EncodeDecimal; 4085 4086 4087 /** Concat two strings giving a new Unicode string. */ 4088 PyObject* PyUnicodeUCS4_Concat( 4089 PyObject* left, 4090 PyObject* right); 4091 /// ditto 4092 4093 alias PyUnicodeUCS4_Concat PyUnicode_Concat; 4094 4095 4096 version(Python_3_0_Or_Later) { 4097 /** Concat two strings and put the result in *pleft 4098 (sets *pleft to NULL on error) 4099 Params: 4100 pleft = Pointer to left string 4101 right = Right string 4102 */ 4103 /// Availability: 3.* 4104 4105 void PyUnicodeUCS4_Append( 4106 PyObject** pleft, 4107 PyObject* right 4108 ); 4109 /// ditto 4110 4111 alias PyUnicodeUCS4_Append PyUnicode_Append; 4112 4113 4114 /** Concat two strings, put the result in *pleft and drop the right object 4115 (sets *pleft to NULL on error) 4116 Params: 4117 pleft = Pointer to left string 4118 */ 4119 /// Availability: 3.* 4120 void PyUnicodeUCS4_AppendAndDel( 4121 PyObject** pleft, 4122 PyObject* right 4123 ); 4124 /// ditto 4125 4126 alias PyUnicodeUCS4_AppendAndDel PyUnicode_AppendAndDel; 4127 4128 } 4129 4130 /** Split a string giving a list of Unicode strings. 4131 4132 If sep is NULL, splitting will be done at all whitespace 4133 substrings. Otherwise, splits occur at the given separator. 4134 4135 At most maxsplit splits will be done. If negative, no limit is set. 4136 4137 Separators are not included in the resulting list. 4138 4139 */ 4140 PyObject* PyUnicodeUCS4_Split( 4141 PyObject* s, 4142 PyObject* sep, 4143 Py_ssize_t maxsplit); 4144 /// ditto 4145 4146 alias PyUnicodeUCS4_Split PyUnicode_Split; 4147 4148 4149 /** Ditto PyUnicode_Split, but split at line breaks. 4150 4151 CRLF is considered to be one line break. Line breaks are not 4152 included in the resulting list. */ 4153 PyObject* PyUnicodeUCS4_Splitlines( 4154 PyObject* s, 4155 int keepends); 4156 /// ditto 4157 4158 alias PyUnicodeUCS4_Splitlines PyUnicode_Splitlines; 4159 4160 4161 version(Python_2_5_Or_Later) { 4162 /** Partition a string using a given separator. */ 4163 /// Availability: >= 2.5 4164 PyObject* PyUnicodeUCS4_Partition( 4165 PyObject* s, 4166 PyObject* sep 4167 ); 4168 /// ditto 4169 4170 alias PyUnicodeUCS4_Partition PyUnicode_Partition; 4171 4172 4173 /** Partition a string using a given separator, searching from the end 4174 of the string. */ 4175 4176 PyObject* PyUnicodeUCS4_RPartition( 4177 PyObject* s, 4178 PyObject* sep 4179 ); 4180 /// ditto 4181 4182 alias PyUnicodeUCS4_RPartition PyUnicode_RPartition; 4183 4184 } 4185 4186 /** Split a string giving a list of Unicode strings. 4187 4188 If sep is NULL, splitting will be done at all whitespace 4189 substrings. Otherwise, splits occur at the given separator. 4190 4191 At most maxsplit splits will be done. But unlike PyUnicode_Split 4192 PyUnicode_RSplit splits from the end of the string. If negative, 4193 no limit is set. 4194 4195 Separators are not included in the resulting list. 4196 4197 */ 4198 PyObject* PyUnicodeUCS4_RSplit( 4199 PyObject* s, 4200 PyObject* sep, 4201 Py_ssize_t maxsplit); 4202 /// ditto 4203 4204 alias PyUnicodeUCS4_RSplit PyUnicode_RSplit; 4205 4206 4207 /** Translate a string by applying a character mapping table to it and 4208 return the resulting Unicode object. 4209 4210 The mapping table must map Unicode ordinal integers to Unicode 4211 ordinal integers or None (causing deletion of the character). 4212 4213 Mapping tables may be dictionaries or sequences. Unmapped character 4214 ordinals (ones which cause a LookupError) are left untouched and 4215 are copied as-is. 4216 4217 */ 4218 PyObject* PyUnicodeUCS4_Translate( 4219 PyObject* str, 4220 PyObject* table, 4221 const(char)* errors); 4222 /// ditto 4223 4224 alias PyUnicodeUCS4_Translate PyUnicode_Translate; 4225 4226 4227 /** Join a sequence of strings using the given separator and return 4228 the resulting Unicode string. */ 4229 PyObject* PyUnicodeUCS4_Join( 4230 PyObject* separator, 4231 PyObject* seq); 4232 /// ditto 4233 4234 alias PyUnicodeUCS4_Join PyUnicode_Join; 4235 4236 4237 /** Return 1 if substr matches str[start:end] at the given tail end, 0 4238 otherwise. */ 4239 Py_ssize_t PyUnicodeUCS4_Tailmatch( 4240 PyObject* str, 4241 PyObject* substr, 4242 Py_ssize_t start, 4243 Py_ssize_t end, 4244 int direction 4245 ); 4246 /// ditto 4247 4248 alias PyUnicodeUCS4_Tailmatch PyUnicode_Tailmatch; 4249 4250 4251 /** Return the first position of substr in str[start:end] using the 4252 given search direction or -1 if not found. -2 is returned in case 4253 an error occurred and an exception is set. */ 4254 Py_ssize_t PyUnicodeUCS4_Find( 4255 PyObject* str, 4256 PyObject* substr, 4257 Py_ssize_t start, 4258 Py_ssize_t end, 4259 int direction 4260 ); 4261 /// ditto 4262 4263 alias PyUnicodeUCS4_Find PyUnicode_Find; 4264 4265 4266 /** Count the number of occurrences of substr in str[start:end]. */ 4267 Py_ssize_t PyUnicodeUCS4_Count( 4268 PyObject* str, 4269 PyObject* substr, 4270 Py_ssize_t start, 4271 Py_ssize_t end); 4272 /// ditto 4273 4274 alias PyUnicodeUCS4_Count PyUnicode_Count; 4275 4276 4277 /** Replace at most maxcount occurrences of substr in str with replstr 4278 and return the resulting Unicode object. */ 4279 PyObject* PyUnicodeUCS4_Replace( 4280 PyObject* str, 4281 PyObject* substr, 4282 PyObject* replstr, 4283 Py_ssize_t maxcount 4284 ); 4285 /// ditto 4286 4287 alias PyUnicodeUCS4_Replace PyUnicode_Replace; 4288 4289 4290 /** Compare two strings and return -1, 0, 1 for less than, equal, 4291 greater than resp. */ 4292 int PyUnicodeUCS4_Compare(PyObject* left, PyObject* right); 4293 /// ditto 4294 4295 alias PyUnicodeUCS4_Compare PyUnicode_Compare; 4296 4297 version(Python_3_0_Or_Later) { 4298 /** Compare two strings and return -1, 0, 1 for less than, equal, 4299 greater than resp. 4300 Params: 4301 left = 4302 right = ASCII-encoded string 4303 */ 4304 /// Availability: 3.* 4305 int PyUnicodeUCS4_CompareWithASCIIString( 4306 PyObject* left, 4307 const(char)* right 4308 ); 4309 /// ditto 4310 4311 alias PyUnicodeUCS4_CompareWithASCIIString PyUnicode_CompareWithASCIIString; 4312 4313 } 4314 4315 version(Python_2_5_Or_Later) { 4316 /** Rich compare two strings and return one of the following: 4317 4318 - NULL in case an exception was raised 4319 - Py_True or Py_False for successfuly comparisons 4320 - Py_NotImplemented in case the type combination is unknown 4321 4322 Note that Py_EQ and Py_NE comparisons can cause a UnicodeWarning in 4323 case the conversion of the arguments to Unicode fails with a 4324 UnicodeDecodeError. 4325 4326 Possible values for op: 4327 4328 Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE 4329 4330 */ 4331 /// Availability: >= 2.5 4332 PyObject* PyUnicodeUCS4_RichCompare( 4333 PyObject* left, 4334 PyObject* right, 4335 int op 4336 ); 4337 /// ditto 4338 4339 alias PyUnicodeUCS4_RichCompare PyUnicode_RichCompare; 4340 4341 } 4342 4343 /** Apply a argument tuple or dictionary to a format string and return 4344 the resulting Unicode string. */ 4345 PyObject* PyUnicodeUCS4_Format(PyObject* format, PyObject* args); 4346 /// ditto 4347 4348 alias PyUnicodeUCS4_Format PyUnicode_Format; 4349 4350 4351 /** Checks whether element is contained in container and return 1/0 4352 accordingly. 4353 4354 element has to coerce to an one element Unicode string. -1 is 4355 returned in case of an error. */ 4356 int PyUnicodeUCS4_Contains(PyObject* container, PyObject* element); 4357 /// ditto 4358 4359 alias PyUnicodeUCS4_Contains PyUnicode_Contains; 4360 4361 4362 version(Python_3_0_Or_Later) { 4363 /** Checks whether argument is a valid identifier. */ 4364 /// Availability: 3.* 4365 int PyUnicodeUCS4_IsIdentifier(PyObject* s); 4366 /// ditto 4367 4368 alias PyUnicodeUCS4_IsIdentifier PyUnicode_IsIdentifier; 4369 4370 } 4371 4372 4373 /// _ 4374 int _PyUnicodeUCS4_IsLowercase(Py_UNICODE ch); 4375 /// ditto 4376 4377 alias _PyUnicodeUCS4_IsLowercase _PyUnicode_IsLowercase; 4378 4379 /// _ 4380 int _PyUnicodeUCS4_IsUppercase(Py_UNICODE ch); 4381 /// ditto 4382 4383 alias _PyUnicodeUCS4_IsUppercase _PyUnicode_IsUppercase; 4384 4385 /// _ 4386 int _PyUnicodeUCS4_IsTitlecase(Py_UNICODE ch); 4387 /// ditto 4388 4389 alias _PyUnicodeUCS4_IsTitlecase _PyUnicode_IsTitlecase; 4390 4391 /// _ 4392 int _PyUnicodeUCS4_IsWhitespace(Py_UNICODE ch); 4393 /// ditto 4394 4395 alias _PyUnicodeUCS4_IsWhitespace _PyUnicode_IsWhitespace; 4396 4397 /// _ 4398 int _PyUnicodeUCS4_IsLinebreak(Py_UNICODE ch); 4399 /// ditto 4400 4401 alias _PyUnicodeUCS4_IsLinebreak _PyUnicode_IsLinebreak; 4402 4403 /// _ 4404 Py_UNICODE _PyUnicodeUCS4_ToLowercase(Py_UNICODE ch); 4405 /// ditto 4406 4407 alias _PyUnicodeUCS4_ToLowercase _PyUnicode_ToLowercase; 4408 4409 /// _ 4410 Py_UNICODE _PyUnicodeUCS4_ToUppercase(Py_UNICODE ch); 4411 /// ditto 4412 4413 alias _PyUnicodeUCS4_ToUppercase _PyUnicode_ToUppercase; 4414 4415 /// _ 4416 Py_UNICODE _PyUnicodeUCS4_ToTitlecase(Py_UNICODE ch); 4417 /// ditto 4418 4419 alias _PyUnicodeUCS4_ToTitlecase _PyUnicode_ToTitlecase; 4420 4421 /// _ 4422 int _PyUnicodeUCS4_ToDecimalDigit(Py_UNICODE ch); 4423 /// ditto 4424 4425 alias _PyUnicodeUCS4_ToDecimalDigit _PyUnicode_ToDecimalDigit; 4426 4427 /// _ 4428 int _PyUnicodeUCS4_ToDigit(Py_UNICODE ch); 4429 /// ditto 4430 4431 alias _PyUnicodeUCS4_ToDigit _PyUnicode_ToDigit; 4432 4433 /// _ 4434 double _PyUnicodeUCS4_ToNumeric(Py_UNICODE ch); 4435 /// ditto 4436 4437 alias _PyUnicodeUCS4_ToNumeric _PyUnicode_ToNumeric; 4438 4439 /// _ 4440 int _PyUnicodeUCS4_IsDecimalDigit(Py_UNICODE ch); 4441 /// ditto 4442 4443 alias _PyUnicodeUCS4_IsDecimalDigit _PyUnicode_IsDecimalDigit; 4444 4445 /// _ 4446 int _PyUnicodeUCS4_IsDigit(Py_UNICODE ch); 4447 /// ditto 4448 4449 alias _PyUnicodeUCS4_IsDigit _PyUnicode_IsDigit; 4450 4451 /// _ 4452 int _PyUnicodeUCS4_IsNumeric(Py_UNICODE ch); 4453 /// ditto 4454 4455 alias _PyUnicodeUCS4_IsNumeric _PyUnicode_IsNumeric; 4456 4457 /// _ 4458 int _PyUnicodeUCS4_IsAlpha(Py_UNICODE ch); 4459 /// ditto 4460 4461 alias _PyUnicodeUCS4_IsAlpha _PyUnicode_IsAlpha; 4462 4463 } 4464 version(Python_3_0_Or_Later) { 4465 /// Availability: 3.* 4466 size_t Py_UNICODE_strlen(const(Py_UNICODE)* u); 4467 4468 /// Availability: 3.* 4469 Py_UNICODE* Py_UNICODE_strcpy(Py_UNICODE* s1, const(Py_UNICODE)* s2); 4470 4471 version(Python_3_2_Or_Later) { 4472 /// Availability: >= 3.2 4473 Py_UNICODE* Py_UNICODE_strcat(Py_UNICODE* s1, const(Py_UNICODE)* s2); 4474 } 4475 4476 /// Availability: 3.* 4477 Py_UNICODE* Py_UNICODE_strncpy( 4478 Py_UNICODE* s1, 4479 const(Py_UNICODE)* s2, 4480 size_t n); 4481 4482 /// Availability: 3.* 4483 int Py_UNICODE_strcmp( 4484 const(Py_UNICODE)* s1, 4485 const(Py_UNICODE)* s2 4486 ); 4487 4488 version(Python_3_2_Or_Later) { 4489 /// Availability: >= 3.2 4490 int Py_UNICODE_strncmp( 4491 const(Py_UNICODE)* s1, 4492 const(Py_UNICODE)* s2, 4493 size_t n 4494 ); 4495 } 4496 4497 /// Availability: 3.* 4498 Py_UNICODE* Py_UNICODE_strchr( 4499 const(Py_UNICODE)* s, 4500 Py_UNICODE c 4501 ); 4502 4503 version(Python_3_2_Or_Later) { 4504 /// Availability: >= 3.2 4505 Py_UNICODE* Py_UNICODE_strrchr( 4506 const(Py_UNICODE)* s, 4507 Py_UNICODE c 4508 ); 4509 } 4510 4511 version(Python_3_5_Or_Later) { 4512 /// Availability: >= 3.5 4513 PyObject* _PyUnicode_FormatLong(PyObject*, int, int, int); 4514 } 4515 4516 version(Python_3_2_Or_Later) { 4517 /** Create a copy of a unicode string ending with a nul character. Return NULL 4518 and raise a MemoryError exception on memory allocation failure, otherwise 4519 return a new allocated buffer (use PyMem_Free() to free the buffer). */ 4520 /// Availability: >= 3.2 4521 4522 Py_UNICODE* PyUnicode_AsUnicodeCopy( 4523 PyObject* unicode 4524 ); 4525 } 4526 } 4527 4528 4529 /// _ 4530 int _PyUnicode_IsTitlecase( 4531 Py_UCS4 ch /* Unicode character */ 4532 ); 4533 4534 /// _ 4535 int _PyUnicode_IsXidStart( 4536 Py_UCS4 ch /* Unicode character */ 4537 ); 4538 /** Externally visible for str.strip(unicode) */ 4539 PyObject* _PyUnicode_XStrip(PyUnicodeObject* self, int striptype, 4540 PyObject *sepobj 4541 ); 4542 version(Python_3_0_Or_Later) { 4543 version(Python_3_2_Or_Later) { 4544 /** Using the current locale, insert the thousands grouping 4545 into the string pointed to by buffer. For the argument descriptions, 4546 see Objects/stringlib/localeutil.h */ 4547 /// Availability: >= 3.2 4548 Py_ssize_t _PyUnicode_InsertThousandsGroupingLocale( 4549 Py_UNICODE* buffer, 4550 Py_ssize_t n_buffer, 4551 Py_UNICODE* digits, 4552 Py_ssize_t n_digits, 4553 Py_ssize_t min_width); 4554 } 4555 4556 /** Using explicit passed-in values, insert the thousands grouping 4557 into the string pointed to by buffer. For the argument descriptions, 4558 see Objects/stringlib/localeutil.h */ 4559 /// Availability: 3.* 4560 Py_ssize_t _PyUnicode_InsertThousandsGrouping( 4561 Py_UNICODE* buffer, 4562 Py_ssize_t n_buffer, 4563 Py_UNICODE* digits, 4564 Py_ssize_t n_digits, 4565 Py_ssize_t min_width, 4566 const(char)* grouping, 4567 const(char)* thousands_sep); 4568 } 4569 4570 version(Python_3_2_Or_Later) { 4571 /// Availability: >= 3.2 4572 PyObject* PyUnicode_TransformDecimalToASCII( 4573 Py_UNICODE *s, /* Unicode buffer */ 4574 Py_ssize_t length /* Number of Py_UNICODE chars to transform */ 4575 ); 4576 /* --- File system encoding ---------------------------------------------- */ 4577 4578 /** ParseTuple converter: encode str objects to bytes using 4579 PyUnicode_EncodeFSDefault(); bytes objects are output as-is. */ 4580 /// Availability: >= 3.2 4581 int PyUnicode_FSConverter(PyObject*, void*); 4582 4583 /** ParseTuple converter: decode bytes objects to unicode using 4584 PyUnicode_DecodeFSDefaultAndSize(); str objects are output as-is. */ 4585 /// Availability: >= 3.2 4586 int PyUnicode_FSDecoder(PyObject*, void*); 4587 4588 /** Decode a null-terminated string using Py_FileSystemDefaultEncoding 4589 and the "surrogateescape" error handler. 4590 4591 If Py_FileSystemDefaultEncoding is not set, fall back to the locale 4592 encoding. 4593 4594 Use PyUnicode_DecodeFSDefaultAndSize() if the string length is known. 4595 */ 4596 /// Availability: >= 3.2 4597 PyObject* PyUnicode_DecodeFSDefault( 4598 const(char)* s /* encoded string */ 4599 ); 4600 4601 /** Decode a string using Py_FileSystemDefaultEncoding 4602 and the "surrogateescape" error handler. 4603 4604 If Py_FileSystemDefaultEncoding is not set, fall back to the locale 4605 encoding. 4606 */ 4607 /// Availability: >= 3.2 4608 PyObject* PyUnicode_DecodeFSDefaultAndSize( 4609 const(char)* s, /* encoded string */ 4610 Py_ssize_t size /* size */ 4611 ); 4612 4613 /** Encode a Unicode object to Py_FileSystemDefaultEncoding with the 4614 "surrogateescape" error handler, and return bytes. 4615 4616 If Py_FileSystemDefaultEncoding is not set, fall back to the locale 4617 encoding. 4618 */ 4619 /// Availability: >= 3.2 4620 PyObject* PyUnicode_EncodeFSDefault( 4621 PyObject* unicode 4622 ); 4623 } 4624 4625 /* 4626 alias _PyUnicode_IsWhitespace Py_UNICODE_ISSPACE; 4627 alias _PyUnicode_IsLowercase Py_UNICODE_ISLOWER; 4628 alias _PyUnicode_IsUppercase Py_UNICODE_ISUPPER; 4629 alias _PyUnicode_IsTitlecase Py_UNICODE_ISTITLE; 4630 alias _PyUnicode_IsLinebreak Py_UNICODE_ISLINEBREAK; 4631 alias _PyUnicode_ToLowercase Py_UNICODE_TOLOWER; 4632 alias _PyUnicode_ToUppercase Py_UNICODE_TOUPPER; 4633 alias _PyUnicode_ToTitlecase Py_UNICODE_TOTITLE; 4634 alias _PyUnicode_IsDecimalDigit Py_UNICODE_ISDECIMAL; 4635 alias _PyUnicode_IsDigit Py_UNICODE_ISDIGIT; 4636 alias _PyUnicode_IsNumeric Py_UNICODE_ISNUMERIC; 4637 alias _PyUnicode_ToDecimalDigit Py_UNICODE_TODECIMAL; 4638 alias _PyUnicode_ToDigit Py_UNICODE_TODIGIT; 4639 alias _PyUnicode_ToNumeric Py_UNICODE_TONUMERIC; 4640 alias _PyUnicode_IsAlpha Py_UNICODE_ISALPHA; 4641 */ 4642 4643 /// _ 4644 int Py_UNICODE_ISALNUM()(Py_UNICODE ch) { 4645 return ( 4646 Py_UNICODE_ISALPHA(ch) 4647 || Py_UNICODE_ISDECIMAL(ch) 4648 || Py_UNICODE_ISDIGIT(ch) 4649 || Py_UNICODE_ISNUMERIC(ch) 4650 ); 4651 } 4652 4653 /// _ 4654 void Py_UNICODE_COPY()(void* target, void* source, size_t length) { 4655 memcpy(target, source, cast(uint)(length* Py_UNICODE.sizeof)); 4656 } 4657 4658 /// _ 4659 void Py_UNICODE_FILL()(Py_UNICODE* target, Py_UNICODE value, size_t length) { 4660 for (size_t i = 0; i < length; i++) { 4661 target[i] = value; 4662 } 4663 } 4664 4665 /// _ 4666 int Py_UNICODE_MATCH()(PyUnicodeObject* string, size_t offset, 4667 PyUnicodeObject* substring 4668 ) 4669 { 4670 return ( 4671 (*(string.str + offset) == *(substring.str)) 4672 && !memcmp(string.str + offset, substring.str, 4673 substring.length * Py_UNICODE.sizeof 4674 ) 4675 ); 4676 } 4677 4678