unicode.pxd 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. cdef extern from *:
  2. # Return true if the object o is a Unicode object or an instance
  3. # of a Unicode subtype. Changed in version 2.2: Allowed subtypes
  4. # to be accepted.
  5. bint PyUnicode_Check(object o)
  6. # Return true if the object o is a Unicode object, but not an
  7. # instance of a subtype. New in version 2.2.
  8. bint PyUnicode_CheckExact(object o)
  9. # Return the size of the object. o has to be a PyUnicodeObject
  10. # (not checked).
  11. Py_ssize_t PyUnicode_GET_SIZE(object o)
  12. # Return the size of the object's internal buffer in bytes. o has
  13. # to be a PyUnicodeObject (not checked).
  14. Py_ssize_t PyUnicode_GET_DATA_SIZE(object o)
  15. # Return a pointer to the internal Py_UNICODE buffer of the
  16. # object. o has to be a PyUnicodeObject (not checked).
  17. Py_UNICODE* PyUnicode_AS_UNICODE(object o)
  18. # Return a pointer to the internal buffer of the object. o has to
  19. # be a PyUnicodeObject (not checked).
  20. char* PyUnicode_AS_DATA(object o)
  21. # Return 1 or 0 depending on whether ch is a whitespace character.
  22. bint Py_UNICODE_ISSPACE(Py_UCS4 ch)
  23. # Return 1 or 0 depending on whether ch is a lowercase character.
  24. bint Py_UNICODE_ISLOWER(Py_UCS4 ch)
  25. # Return 1 or 0 depending on whether ch is an uppercase character.
  26. bint Py_UNICODE_ISUPPER(Py_UCS4 ch)
  27. # Return 1 or 0 depending on whether ch is a titlecase character.
  28. bint Py_UNICODE_ISTITLE(Py_UCS4 ch)
  29. # Return 1 or 0 depending on whether ch is a linebreak character.
  30. bint Py_UNICODE_ISLINEBREAK(Py_UCS4 ch)
  31. # Return 1 or 0 depending on whether ch is a decimal character.
  32. bint Py_UNICODE_ISDECIMAL(Py_UCS4 ch)
  33. # Return 1 or 0 depending on whether ch is a digit character.
  34. bint Py_UNICODE_ISDIGIT(Py_UCS4 ch)
  35. # Return 1 or 0 depending on whether ch is a numeric character.
  36. bint Py_UNICODE_ISNUMERIC(Py_UCS4 ch)
  37. # Return 1 or 0 depending on whether ch is an alphabetic character.
  38. bint Py_UNICODE_ISALPHA(Py_UCS4 ch)
  39. # Return 1 or 0 depending on whether ch is an alphanumeric character.
  40. bint Py_UNICODE_ISALNUM(Py_UCS4 ch)
  41. # Return the character ch converted to lower case.
  42. # Used to return a Py_UNICODE value before Py3.3.
  43. Py_UCS4 Py_UNICODE_TOLOWER(Py_UCS4 ch)
  44. # Return the character ch converted to upper case.
  45. # Used to return a Py_UNICODE value before Py3.3.
  46. Py_UCS4 Py_UNICODE_TOUPPER(Py_UCS4 ch)
  47. # Return the character ch converted to title case.
  48. # Used to return a Py_UNICODE value before Py3.3.
  49. Py_UCS4 Py_UNICODE_TOTITLE(Py_UCS4 ch)
  50. # Return the character ch converted to a decimal positive
  51. # integer. Return -1 if this is not possible. This macro does not
  52. # raise exceptions.
  53. int Py_UNICODE_TODECIMAL(Py_UCS4 ch)
  54. # Return the character ch converted to a single digit
  55. # integer. Return -1 if this is not possible. This macro does not
  56. # raise exceptions.
  57. int Py_UNICODE_TODIGIT(Py_UCS4 ch)
  58. # Return the character ch converted to a double. Return -1.0 if
  59. # this is not possible. This macro does not raise exceptions.
  60. double Py_UNICODE_TONUMERIC(Py_UCS4 ch)
  61. # To create Unicode objects and access their basic sequence
  62. # properties, use these APIs:
  63. # Create a Unicode Object from the Py_UNICODE buffer u of the
  64. # given size. u may be NULL which causes the contents to be
  65. # undefined. It is the user's responsibility to fill in the needed
  66. # data. The buffer is copied into the new object. If the buffer is
  67. # not NULL, the return value might be a shared object. Therefore,
  68. # modification of the resulting Unicode object is only allowed
  69. # when u is NULL.
  70. unicode PyUnicode_FromUnicode(Py_UNICODE *u, Py_ssize_t size)
  71. # Create a Unicode Object from the given Unicode code point ordinal.
  72. #
  73. # The ordinal must be in range(0x10000) on narrow Python builds
  74. # (UCS2), and range(0x110000) on wide builds (UCS4). A ValueError
  75. # is raised in case it is not.
  76. unicode PyUnicode_FromOrdinal(int ordinal)
  77. # Return a read-only pointer to the Unicode object's internal
  78. # Py_UNICODE buffer, NULL if unicode is not a Unicode object.
  79. Py_UNICODE* PyUnicode_AsUnicode(object o) except NULL
  80. # Return the length of the Unicode object.
  81. Py_ssize_t PyUnicode_GetSize(object o) except -1
  82. # Coerce an encoded object obj to an Unicode object and return a
  83. # reference with incremented refcount.
  84. # String and other char buffer compatible objects are decoded
  85. # according to the given encoding and using the error handling
  86. # defined by errors. Both can be NULL to have the interface use
  87. # the default values (see the next section for details).
  88. # All other objects, including Unicode objects, cause a TypeError
  89. # to be set.
  90. object PyUnicode_FromEncodedObject(object o, char *encoding, char *errors)
  91. # Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict")
  92. # which is used throughout the interpreter whenever coercion to
  93. # Unicode is needed.
  94. object PyUnicode_FromObject(object obj)
  95. # If the platform supports wchar_t and provides a header file
  96. # wchar.h, Python can interface directly to this type using the
  97. # following functions. Support is optimized if Python's own
  98. # Py_UNICODE type is identical to the system's wchar_t.
  99. #ctypedef int wchar_t
  100. # Create a Unicode object from the wchar_t buffer w of the given
  101. # size. Return NULL on failure.
  102. #PyObject* PyUnicode_FromWideChar(wchar_t *w, Py_ssize_t size)
  103. #Py_ssize_t PyUnicode_AsWideChar(object o, wchar_t *w, Py_ssize_t size)
  104. # Unicode Methods
  105. # Concat two strings giving a new Unicode string.
  106. # Return value: New reference.
  107. unicode PyUnicode_Concat(object left, object right)
  108. # Split a string giving a list of Unicode strings. If sep is NULL,
  109. # splitting will be done at all whitespace substrings. Otherwise,
  110. # splits occur at the given separator. At most maxsplit splits will
  111. # be done. If negative, no limit is set. Separators are not included
  112. # in the resulting list.
  113. # Return value: New reference.
  114. list PyUnicode_Split(object s, object sep, Py_ssize_t maxsplit)
  115. # Split a Unicode string at line breaks, returning a list of Unicode
  116. # strings. CRLF is considered to be one line break. If keepend is 0,
  117. # the Line break characters are not included in the resulting strings.
  118. # Return value: New reference.
  119. list PyUnicode_Splitlines(object s, bint keepend)
  120. # Translate a string by applying a character mapping table to it and
  121. # return the resulting Unicode object.
  122. #
  123. # The mapping table must map Unicode ordinal integers to Unicode ordinal
  124. # integers or None (causing deletion of the character).
  125. #
  126. # Mapping tables need only provide the __getitem__() interface;
  127. # dictionaries and sequences work well. Unmapped character ordinals (ones
  128. # which cause a LookupError) are left untouched and are copied as-is.
  129. #
  130. # errors has the usual meaning for codecs. It may be NULL which indicates
  131. # to use the default error handling.
  132. # Return value: New reference.
  133. unicode PyUnicode_Translate(object str, object table, const char *errors)
  134. # Join a sequence of strings using the given separator and return the
  135. # resulting Unicode string.
  136. # Return value: New reference.
  137. unicode PyUnicode_Join(object separator, object seq)
  138. # Return 1 if substr matches str[start:end] at the given tail end
  139. # (direction == -1 means to do a prefix match, direction == 1 a
  140. # suffix match), 0 otherwise.
  141. # Return -1 if an error occurred.
  142. Py_ssize_t PyUnicode_Tailmatch(object str, object substr,
  143. Py_ssize_t start, Py_ssize_t end, int direction) except -1
  144. # Return the first position of substr in str[start:end] using the given
  145. # direction (direction == 1 means to do a forward search, direction == -1
  146. # a backward search). The return value is the index of the first match;
  147. # a value of -1 indicates that no match was found, and -2 indicates that an
  148. # error occurred and an exception has been set.
  149. Py_ssize_t PyUnicode_Find(object str, object substr, Py_ssize_t start, Py_ssize_t end, int direction) except -2
  150. # Return the first position of the character ch in str[start:end] using
  151. # the given direction (direction == 1 means to do a forward search,
  152. # direction == -1 a backward search). The return value is the index of
  153. # the first match; a value of -1 indicates that no match was found, and
  154. # -2 indicates that an error occurred and an exception has been set.
  155. # New in version 3.3.
  156. Py_ssize_t PyUnicode_FindChar(object str, Py_UCS4 ch, Py_ssize_t start, Py_ssize_t end, int direction) except -2
  157. # Return the number of non-overlapping occurrences of substr in
  158. # str[start:end]. Return -1 if an error occurred.
  159. Py_ssize_t PyUnicode_Count(object str, object substr, Py_ssize_t start, Py_ssize_t end) except -1
  160. # Replace at most maxcount occurrences of substr in str with replstr and
  161. # return the resulting Unicode object. maxcount == -1 means replace all
  162. # occurrences.
  163. # Return value: New reference.
  164. unicode PyUnicode_Replace(object str, object substr, object replstr, Py_ssize_t maxcount)
  165. # Compare two strings and return -1, 0, 1 for less than,
  166. # equal, and greater than, respectively.
  167. int PyUnicode_Compare(object left, object right) except? -1
  168. # Compare a unicode object, uni, with string and return -1, 0, 1 for less than,
  169. # equal, and greater than, respectively. It is best to pass only ASCII-encoded
  170. # strings, but the function interprets the input string as ISO-8859-1 if it
  171. # contains non-ASCII characters.
  172. int PyUnicode_CompareWithASCIIString(object uni, char *string) except? -1
  173. # Rich compare two unicode strings and return one of the following:
  174. #
  175. # NULL in case an exception was raised
  176. # Py_True or Py_False for successful comparisons
  177. # Py_NotImplemented in case the type combination is unknown
  178. #
  179. # Note that Py_EQ and Py_NE comparisons can cause a UnicodeWarning in case
  180. # the conversion of the arguments to Unicode fails with a UnicodeDecodeError.
  181. #
  182. # Possible values for op are Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, and Py_LE.
  183. object PyUnicode_RichCompare(object left, object right, int op)
  184. # Return a new string object from format and args; this is analogous to
  185. # format % args.
  186. # Return value: New reference.
  187. unicode PyUnicode_Format(object format, object args)
  188. # Check whether element is contained in container and return true or false
  189. # accordingly.
  190. #
  191. # element has to coerce to a one element Unicode string. -1 is returned
  192. # if there was an error.
  193. int PyUnicode_Contains(object container, object element) except -1
  194. # Intern the argument *string in place. The argument must be the address
  195. # of a pointer variable pointing to a Python unicode string object. If
  196. # there is an existing interned string that is the same as *string, it sets
  197. # *string to it (decrementing the reference count of the old string object
  198. # and incrementing the reference count of the interned string object),
  199. # otherwise it leaves *string alone and interns it (incrementing its reference
  200. # count). (Clarification: even though there is a lot of talk about reference
  201. # counts, think of this function as reference-count-neutral; you own the object
  202. # after the call if and only if you owned it before the call.)
  203. #void PyUnicode_InternInPlace(PyObject **string)
  204. # A combination of PyUnicode_FromString() and PyUnicode_InternInPlace(),
  205. # returning either a new unicode string object that has been interned, or
  206. # a new ("owned") reference to an earlier interned string object with the
  207. # same value.
  208. unicode PyUnicode_InternFromString(const char *v)
  209. # Codecs
  210. # Create a Unicode object by decoding size bytes of the encoded
  211. # string s. encoding and errors have the same meaning as the
  212. # parameters of the same name in the unicode() builtin
  213. # function. The codec to be used is looked up using the Python
  214. # codec registry. Return NULL if an exception was raised by the
  215. # codec.
  216. object PyUnicode_Decode(char *s, Py_ssize_t size, char *encoding, char *errors)
  217. # Encode the Py_UNICODE buffer of the given size and return a
  218. # Python string object. encoding and errors have the same meaning
  219. # as the parameters of the same name in the Unicode encode()
  220. # method. The codec to be used is looked up using the Python codec
  221. # registry. Return NULL if an exception was raised by the codec.
  222. object PyUnicode_Encode(Py_UNICODE *s, Py_ssize_t size,
  223. char *encoding, char *errors)
  224. # Encode a Unicode object and return the result as Python string
  225. # object. encoding and errors have the same meaning as the
  226. # parameters of the same name in the Unicode encode() method. The
  227. # codec to be used is looked up using the Python codec
  228. # registry. Return NULL if an exception was raised by the codec.
  229. object PyUnicode_AsEncodedString(object unicode, char *encoding, char *errors)
  230. # These are the UTF-8 codec APIs:
  231. # Create a Unicode object by decoding size bytes of the UTF-8
  232. # encoded string s. Return NULL if an exception was raised by the
  233. # codec.
  234. unicode PyUnicode_DecodeUTF8(char *s, Py_ssize_t size, char *errors)
  235. # If consumed is NULL, behave like PyUnicode_DecodeUTF8(). If
  236. # consumed is not NULL, trailing incomplete UTF-8 byte sequences
  237. # will not be treated as an error. Those bytes will not be decoded
  238. # and the number of bytes that have been decoded will be stored in
  239. # consumed. New in version 2.4.
  240. unicode PyUnicode_DecodeUTF8Stateful(char *s, Py_ssize_t size, char *errors, Py_ssize_t *consumed)
  241. # Encode the Py_UNICODE buffer of the given size using UTF-8 and
  242. # return a Python string object. Return NULL if an exception was
  243. # raised by the codec.
  244. bytes PyUnicode_EncodeUTF8(Py_UNICODE *s, Py_ssize_t size, char *errors)
  245. # Encode a Unicode objects using UTF-8 and return the result as Python string object. Error handling is ``strict''. Return NULL if an exception was raised by the codec.
  246. bytes PyUnicode_AsUTF8String(object unicode)
  247. # These are the UTF-16 codec APIs:
  248. # Decode length bytes from a UTF-16 encoded buffer string and
  249. # return the corresponding Unicode object. errors (if non-NULL)
  250. # defines the error handling. It defaults to ``strict''.
  251. #
  252. # If byteorder is non-NULL, the decoder starts decoding using the
  253. # given byte order:
  254. #
  255. # *byteorder == -1: little endian
  256. # *byteorder == 0: native order
  257. # *byteorder == 1: big endian
  258. #
  259. # and then switches if the first two bytes of the input data are a
  260. # byte order mark (BOM) and the specified byte order is native
  261. # order. This BOM is not copied into the resulting Unicode
  262. # string. After completion, *byteorder is set to the current byte
  263. # order at the.
  264. #
  265. # If byteorder is NULL, the codec starts in native order mode.
  266. unicode PyUnicode_DecodeUTF16(char *s, Py_ssize_t size, char *errors, int *byteorder)
  267. # If consumed is NULL, behave like PyUnicode_DecodeUTF16(). If
  268. # consumed is not NULL, PyUnicode_DecodeUTF16Stateful() will not
  269. # treat trailing incomplete UTF-16 byte sequences (such as an odd
  270. # number of bytes or a split surrogate pair) as an error. Those
  271. # bytes will not be decoded and the number of bytes that have been
  272. # decoded will be stored in consumed. New in version 2.4.
  273. unicode PyUnicode_DecodeUTF16Stateful(char *s, Py_ssize_t size, char *errors, int *byteorder, Py_ssize_t *consumed)
  274. # Return a Python string object holding the UTF-16 encoded value
  275. # of the Unicode data in s. If byteorder is not 0, output is
  276. # written according to the following byte order:
  277. #
  278. # byteorder == -1: little endian
  279. # byteorder == 0: native byte order (writes a BOM mark)
  280. # byteorder == 1: big endian
  281. #
  282. # If byteorder is 0, the output string will always start with the
  283. # Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark
  284. # is prepended.
  285. #
  286. # If Py_UNICODE_WIDE is defined, a single Py_UNICODE value may get
  287. # represented as a surrogate pair. If it is not defined, each
  288. # Py_UNICODE values is interpreted as an UCS-2 character.
  289. bytes PyUnicode_EncodeUTF16(Py_UNICODE *s, Py_ssize_t size, char *errors, int byteorder)
  290. # Return a Python string using the UTF-16 encoding in native byte
  291. # order. The string always starts with a BOM mark. Error handling
  292. # is ``strict''. Return NULL if an exception was raised by the
  293. # codec.
  294. bytes PyUnicode_AsUTF16String(object unicode)
  295. # These are the ``Unicode Escape'' codec APIs:
  296. # Create a Unicode object by decoding size bytes of the
  297. # Unicode-Escape encoded string s. Return NULL if an exception was
  298. # raised by the codec.
  299. object PyUnicode_DecodeUnicodeEscape(char *s, Py_ssize_t size, char *errors)
  300. # Encode the Py_UNICODE buffer of the given size using
  301. # Unicode-Escape and return a Python string object. Return NULL if
  302. # an exception was raised by the codec.
  303. object PyUnicode_EncodeUnicodeEscape(Py_UNICODE *s, Py_ssize_t size)
  304. # Encode a Unicode objects using Unicode-Escape and return the
  305. # result as Python string object. Error handling is
  306. # ``strict''. Return NULL if an exception was raised by the codec.
  307. object PyUnicode_AsUnicodeEscapeString(object unicode)
  308. # These are the ``Raw Unicode Escape'' codec APIs:
  309. # Create a Unicode object by decoding size bytes of the
  310. # Raw-Unicode-Escape encoded string s. Return NULL if an exception
  311. # was raised by the codec.
  312. object PyUnicode_DecodeRawUnicodeEscape(char *s, Py_ssize_t size, char *errors)
  313. # Encode the Py_UNICODE buffer of the given size using
  314. # Raw-Unicode-Escape and return a Python string object. Return
  315. # NULL if an exception was raised by the codec.
  316. object PyUnicode_EncodeRawUnicodeEscape(Py_UNICODE *s, Py_ssize_t size, char *errors)
  317. # Encode a Unicode objects using Raw-Unicode-Escape and return the
  318. # result as Python string object. Error handling is
  319. # ``strict''. Return NULL if an exception was raised by the codec.
  320. object PyUnicode_AsRawUnicodeEscapeString(object unicode)
  321. # These are the Latin-1 codec APIs: Latin-1 corresponds to the first 256 Unicode ordinals and only these are accepted by the codecs during encoding.
  322. # Create a Unicode object by decoding size bytes of the Latin-1
  323. # encoded string s. Return NULL if an exception was raised by the
  324. # codec.
  325. unicode PyUnicode_DecodeLatin1(char *s, Py_ssize_t size, char *errors)
  326. # Encode the Py_UNICODE buffer of the given size using Latin-1 and
  327. # return a Python bytes object. Return NULL if an exception was
  328. # raised by the codec.
  329. bytes PyUnicode_EncodeLatin1(Py_UNICODE *s, Py_ssize_t size, char *errors)
  330. # Encode a Unicode objects using Latin-1 and return the result as
  331. # Python bytes object. Error handling is ``strict''. Return NULL
  332. # if an exception was raised by the codec.
  333. bytes PyUnicode_AsLatin1String(object unicode)
  334. # These are the ASCII codec APIs. Only 7-bit ASCII data is
  335. # accepted. All other codes generate errors.
  336. # Create a Unicode object by decoding size bytes of the ASCII
  337. # encoded string s. Return NULL if an exception was raised by the
  338. # codec.
  339. unicode PyUnicode_DecodeASCII(char *s, Py_ssize_t size, char *errors)
  340. # Encode the Py_UNICODE buffer of the given size using ASCII and
  341. # return a Python bytes object. Return NULL if an exception was
  342. # raised by the codec.
  343. bytes PyUnicode_EncodeASCII(Py_UNICODE *s, Py_ssize_t size, char *errors)
  344. # Encode a Unicode objects using ASCII and return the result as
  345. # Python bytes object. Error handling is ``strict''. Return NULL
  346. # if an exception was raised by the codec.
  347. bytes PyUnicode_AsASCIIString(object o)
  348. # These are the mapping codec APIs:
  349. #
  350. # This codec is special in that it can be used to implement many
  351. # different codecs (and this is in fact what was done to obtain most
  352. # of the standard codecs included in the encodings package). The codec
  353. # uses mapping to encode and decode characters.
  354. #
  355. # Decoding mappings must map single string characters to single
  356. # Unicode characters, integers (which are then interpreted as Unicode
  357. # ordinals) or None (meaning "undefined mapping" and causing an
  358. # error).
  359. #
  360. # Encoding mappings must map single Unicode characters to single
  361. # string characters, integers (which are then interpreted as Latin-1
  362. # ordinals) or None (meaning "undefined mapping" and causing an
  363. # error).
  364. #
  365. # The mapping objects provided must only support the __getitem__
  366. # mapping interface.
  367. #
  368. # If a character lookup fails with a LookupError, the character is
  369. # copied as-is meaning that its ordinal value will be interpreted as
  370. # Unicode or Latin-1 ordinal resp. Because of this, mappings only need
  371. # to contain those mappings which map characters to different code
  372. # points.
  373. # Create a Unicode object by decoding size bytes of the encoded
  374. # string s using the given mapping object. Return NULL if an
  375. # exception was raised by the codec. If mapping is NULL latin-1
  376. # decoding will be done. Else it can be a dictionary mapping byte
  377. # or a unicode string, which is treated as a lookup table. Byte
  378. # values greater that the length of the string and U+FFFE
  379. # "characters" are treated as "undefined mapping". Changed in
  380. # version 2.4: Allowed unicode string as mapping argument.
  381. object PyUnicode_DecodeCharmap(char *s, Py_ssize_t size, object mapping, char *errors)
  382. # Encode the Py_UNICODE buffer of the given size using the given
  383. # mapping object and return a Python string object. Return NULL if
  384. # an exception was raised by the codec.
  385. #
  386. # Deprecated since version 3.3, will be removed in version 4.0.
  387. object PyUnicode_EncodeCharmap(Py_UNICODE *s, Py_ssize_t size, object mapping, char *errors)
  388. # Encode a Unicode objects using the given mapping object and
  389. # return the result as Python string object. Error handling is
  390. # ``strict''. Return NULL if an exception was raised by the codec.
  391. object PyUnicode_AsCharmapString(object o, object mapping)
  392. # The following codec API is special in that maps Unicode to Unicode.
  393. # Translate a Py_UNICODE buffer of the given length by applying a
  394. # character mapping table to it and return the resulting Unicode
  395. # object. Return NULL when an exception was raised by the codec.
  396. #
  397. # The mapping table must map Unicode ordinal integers to Unicode
  398. # ordinal integers or None (causing deletion of the character).
  399. #
  400. # Mapping tables need only provide the __getitem__() interface;
  401. # dictionaries and sequences work well. Unmapped character
  402. # ordinals (ones which cause a LookupError) are left untouched and
  403. # are copied as-is.
  404. #
  405. # Deprecated since version 3.3, will be removed in version 4.0.
  406. object PyUnicode_TranslateCharmap(Py_UNICODE *s, Py_ssize_t size,
  407. object table, char *errors)
  408. # These are the MBCS codec APIs. They are currently only available on
  409. # Windows and use the Win32 MBCS converters to implement the
  410. # conversions. Note that MBCS (or DBCS) is a class of encodings, not
  411. # just one. The target encoding is defined by the user settings on the
  412. # machine running the codec.
  413. # Create a Unicode object by decoding size bytes of the MBCS
  414. # encoded string s. Return NULL if an exception was raised by the
  415. # codec.
  416. unicode PyUnicode_DecodeMBCS(char *s, Py_ssize_t size, char *errors)
  417. # If consumed is NULL, behave like PyUnicode_DecodeMBCS(). If
  418. # consumed is not NULL, PyUnicode_DecodeMBCSStateful() will not
  419. # decode trailing lead byte and the number of bytes that have been
  420. # decoded will be stored in consumed. New in version 2.5.
  421. # NOTE: Python 2.x uses 'int' values for 'size' and 'consumed' (changed in 3.0)
  422. unicode PyUnicode_DecodeMBCSStateful(char *s, Py_ssize_t size, char *errors, Py_ssize_t *consumed)
  423. # Encode the Py_UNICODE buffer of the given size using MBCS and
  424. # return a Python string object. Return NULL if an exception was
  425. # raised by the codec.
  426. bytes PyUnicode_EncodeMBCS(Py_UNICODE *s, Py_ssize_t size, char *errors)
  427. # Encode a Unicode objects using MBCS and return the result as
  428. # Python string object. Error handling is ``strict''. Return NULL
  429. # if an exception was raised by the codec.
  430. bytes PyUnicode_AsMBCSString(object o)
  431. # Encode the Unicode object using the specified code page and return
  432. # a Python bytes object. Return NULL if an exception was raised by the
  433. # codec. Use CP_ACP code page to get the MBCS encoder.
  434. #
  435. # New in version 3.3.
  436. bytes PyUnicode_EncodeCodePage(int code_page, object unicode, const char *errors)
  437. # Py_UCS4 helpers (new in CPython 3.3)
  438. # These utility functions work on strings of Py_UCS4 characters and
  439. # otherwise behave like the C standard library functions with the same name.
  440. size_t Py_UCS4_strlen(const Py_UCS4 *u)
  441. Py_UCS4* Py_UCS4_strcpy(Py_UCS4 *s1, const Py_UCS4 *s2)
  442. Py_UCS4* Py_UCS4_strncpy(Py_UCS4 *s1, const Py_UCS4 *s2, size_t n)
  443. Py_UCS4* Py_UCS4_strcat(Py_UCS4 *s1, const Py_UCS4 *s2)
  444. int Py_UCS4_strcmp(const Py_UCS4 *s1, const Py_UCS4 *s2)
  445. int Py_UCS4_strncmp(const Py_UCS4 *s1, const Py_UCS4 *s2, size_t n)
  446. Py_UCS4* Py_UCS4_strchr(const Py_UCS4 *s, Py_UCS4 c)
  447. Py_UCS4* Py_UCS4_strrchr(const Py_UCS4 *s, Py_UCS4 c)