blob: 366acfe001775da46bd9318004e6660e21aaa921 [file] [log] [blame]
Eric Smith8c663262007-08-25 02:26:07 +00001#ifndef STRINGLIB_UNICODEDEFS_H
2#define STRINGLIB_UNICODEDEFS_H
3
4/* this is sort of a hack. there's at least one place (formatting
5 floats) where some stringlib code takes a different path if it's
6 compiled as unicode. */
7#define STRINGLIB_IS_UNICODE 1
8
Eric Smith8fd3eba2008-02-17 19:48:00 +00009#define STRINGLIB_OBJECT PyUnicodeObject
Eric Smith8c663262007-08-25 02:26:07 +000010#define STRINGLIB_CHAR Py_UNICODE
11#define STRINGLIB_TYPE_NAME "unicode"
Eric Smith37f10382007-09-01 10:56:01 +000012#define STRINGLIB_PARSE_CODE "U"
Eric Smith8c663262007-08-25 02:26:07 +000013#define STRINGLIB_EMPTY unicode_empty
14#define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL
15#define STRINGLIB_TODECIMAL Py_UNICODE_TODECIMAL
16#define STRINGLIB_TOUPPER Py_UNICODE_TOUPPER
17#define STRINGLIB_TOLOWER Py_UNICODE_TOLOWER
18#define STRINGLIB_FILL Py_UNICODE_FILL
19#define STRINGLIB_STR PyUnicode_AS_UNICODE
20#define STRINGLIB_LEN PyUnicode_GET_SIZE
21#define STRINGLIB_NEW PyUnicode_FromUnicode
22#define STRINGLIB_RESIZE PyUnicode_Resize
23#define STRINGLIB_CHECK PyUnicode_Check
Eric Smith5807c412008-05-11 21:00:57 +000024#define STRINGLIB_GROUPING _PyUnicode_InsertThousandsGrouping
Eric Smitha3b1ac82009-04-03 14:45:06 +000025#define STRINGLIB_GROUPING_LOCALE _PyUnicode_InsertThousandsGroupingLocale
Eric Smith8fd3eba2008-02-17 19:48:00 +000026
27#if PY_VERSION_HEX < 0x03000000
28#define STRINGLIB_TOSTR PyObject_Unicode
Georg Brandl559e5d72008-06-11 18:37:52 +000029#define STRINGLIB_TOASCII PyObject_Repr
Eric Smith8fd3eba2008-02-17 19:48:00 +000030#else
Thomas Heller519a0422007-11-15 20:48:54 +000031#define STRINGLIB_TOSTR PyObject_Str
Georg Brandl559e5d72008-06-11 18:37:52 +000032#define STRINGLIB_TOASCII PyObject_ASCII
Eric Smith8fd3eba2008-02-17 19:48:00 +000033#endif
Eric Smith8c663262007-08-25 02:26:07 +000034
Gregory P. Smith60d241f2007-10-16 06:31:30 +000035#define STRINGLIB_WANT_CONTAINS_OBJ 1
36
Eric Smith79710cd2007-08-28 09:45:15 +000037/* STRINGLIB_CMP was defined as:
38
Eric Smith8c663262007-08-25 02:26:07 +000039Py_LOCAL_INLINE(int)
40STRINGLIB_CMP(const Py_UNICODE* str, const Py_UNICODE* other, Py_ssize_t len)
41{
42 if (str[0] != other[0])
43 return 1;
44 return memcmp((void*) str, (void*) other, len * sizeof(Py_UNICODE));
45}
46
Eric Smith79710cd2007-08-28 09:45:15 +000047but unfortunately that gives a error if the function isn't used in a file that
48includes this file. So, reluctantly convert it to a macro instead. */
49
50#define STRINGLIB_CMP(str, other, len) \
51 (((str)[0] != (other)[0]) ? \
52 1 : \
53 memcmp((void*) (str), (void*) (other), (len) * sizeof(Py_UNICODE)))
54
55
Eric Smith8c663262007-08-25 02:26:07 +000056#endif /* !STRINGLIB_UNICODEDEFS_H */