/Objects/stringlib/unicodedefs.h

http://unladen-swallow.googlecode.com/ · C Header · 53 lines · 30 code · 8 blank · 15 comment · 1 complexity · fc8ee38ced09f51a8516dd1e16a9f973 MD5 · raw file

  1. #ifndef STRINGLIB_UNICODEDEFS_H
  2. #define STRINGLIB_UNICODEDEFS_H
  3. /* this is sort of a hack. there's at least one place (formatting
  4. floats) where some stringlib code takes a different path if it's
  5. compiled as unicode. */
  6. #define STRINGLIB_IS_UNICODE 1
  7. #define STRINGLIB_OBJECT PyUnicodeObject
  8. #define STRINGLIB_CHAR Py_UNICODE
  9. #define STRINGLIB_TYPE_NAME "unicode"
  10. #define STRINGLIB_PARSE_CODE "U"
  11. #define STRINGLIB_EMPTY unicode_empty
  12. #define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL
  13. #define STRINGLIB_TODECIMAL Py_UNICODE_TODECIMAL
  14. #define STRINGLIB_TOUPPER Py_UNICODE_TOUPPER
  15. #define STRINGLIB_TOLOWER Py_UNICODE_TOLOWER
  16. #define STRINGLIB_FILL Py_UNICODE_FILL
  17. #define STRINGLIB_STR PyUnicode_AS_UNICODE
  18. #define STRINGLIB_LEN PyUnicode_GET_SIZE
  19. #define STRINGLIB_NEW PyUnicode_FromUnicode
  20. #define STRINGLIB_RESIZE PyUnicode_Resize
  21. #define STRINGLIB_CHECK PyUnicode_Check
  22. #define STRINGLIB_GROUPING _PyUnicode_InsertThousandsGrouping
  23. #if PY_VERSION_HEX < 0x03000000
  24. #define STRINGLIB_TOSTR PyObject_Unicode
  25. #else
  26. #define STRINGLIB_TOSTR PyObject_Str
  27. #endif
  28. #define STRINGLIB_WANT_CONTAINS_OBJ 1
  29. /* STRINGLIB_CMP was defined as:
  30. Py_LOCAL_INLINE(int)
  31. STRINGLIB_CMP(const Py_UNICODE* str, const Py_UNICODE* other, Py_ssize_t len)
  32. {
  33. if (str[0] != other[0])
  34. return 1;
  35. return memcmp((void*) str, (void*) other, len * sizeof(Py_UNICODE));
  36. }
  37. but unfortunately that gives a error if the function isn't used in a file that
  38. includes this file. So, reluctantly convert it to a macro instead. */
  39. #define STRINGLIB_CMP(str, other, len) \
  40. (((str)[0] != (other)[0]) ? \
  41. 1 : \
  42. memcmp((void*) (str), (void*) (other), (len) * sizeof(Py_UNICODE)))
  43. #endif /* !STRINGLIB_UNICODEDEFS_H */