Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1265 lines
44 KiB

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