ts_locale.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*-------------------------------------------------------------------------
  2. *
  3. * ts_locale.h
  4. * locale compatibility layer for tsearch
  5. *
  6. * Copyright (c) 1998-2016, PostgreSQL Global Development Group
  7. *
  8. * src/include/tsearch/ts_locale.h
  9. *
  10. *-------------------------------------------------------------------------
  11. */
  12. #ifndef __TSLOCALE_H__
  13. #define __TSLOCALE_H__
  14. #include <ctype.h>
  15. #include <limits.h>
  16. #include "utils/pg_locale.h"
  17. #include "mb/pg_wchar.h"
  18. /*
  19. * towlower() and friends should be in <wctype.h>, but some pre-C99 systems
  20. * declare them in <wchar.h>.
  21. */
  22. #ifdef HAVE_WCHAR_H
  23. #include <wchar.h>
  24. #endif
  25. #ifdef HAVE_WCTYPE_H
  26. #include <wctype.h>
  27. #endif
  28. /* working state for tsearch_readline (should be a local var in caller) */
  29. typedef struct
  30. {
  31. FILE *fp;
  32. const char *filename;
  33. int lineno;
  34. char *curline;
  35. ErrorContextCallback cb;
  36. } tsearch_readline_state;
  37. #define TOUCHAR(x) (*((const unsigned char *) (x)))
  38. #ifdef USE_WIDE_UPPER_LOWER
  39. extern int t_isdigit(const char *ptr);
  40. extern int t_isspace(const char *ptr);
  41. extern int t_isalpha(const char *ptr);
  42. extern int t_isprint(const char *ptr);
  43. /* The second argument of t_iseq() must be a plain ASCII character */
  44. #define t_iseq(x,c) (TOUCHAR(x) == (unsigned char) (c))
  45. #define COPYCHAR(d,s) memcpy(d, s, pg_mblen(s))
  46. #else /* not USE_WIDE_UPPER_LOWER */
  47. #define t_isdigit(x) isdigit(TOUCHAR(x))
  48. #define t_isspace(x) isspace(TOUCHAR(x))
  49. #define t_isalpha(x) isalpha(TOUCHAR(x))
  50. #define t_isprint(x) isprint(TOUCHAR(x))
  51. #define t_iseq(x,c) (TOUCHAR(x) == (unsigned char) (c))
  52. #define COPYCHAR(d,s) (*((unsigned char *) (d)) = TOUCHAR(s))
  53. #endif /* USE_WIDE_UPPER_LOWER */
  54. extern char *lowerstr(const char *str);
  55. extern char *lowerstr_with_len(const char *str, int len);
  56. extern bool tsearch_readline_begin(tsearch_readline_state *stp,
  57. const char *filename);
  58. extern char *tsearch_readline(tsearch_readline_state *stp);
  59. extern void tsearch_readline_end(tsearch_readline_state *stp);
  60. extern char *t_readline(FILE *fp);
  61. #endif /* __TSLOCALE_H__ */