cregex.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. *
  3. * Copyright (c) 1998-2002
  4. * John Maddock
  5. *
  6. * Use, modification and distribution are subject to the
  7. * Boost Software License, Version 1.0. (See accompanying file
  8. * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. *
  10. */
  11. /*
  12. * LOCATION: see http://www.boost.org for most recent version.
  13. * FILE cregex.cpp
  14. * VERSION see <boost/version.hpp>
  15. * DESCRIPTION: Declares POSIX API functions
  16. * + boost::RegEx high level wrapper.
  17. */
  18. #ifndef BOOST_RE_CREGEX_HPP_INCLUDED
  19. #define BOOST_RE_CREGEX_HPP_INCLUDED
  20. #ifndef BOOST_REGEX_CONFIG_HPP
  21. #include <boost/regex/config.hpp>
  22. #endif
  23. #include <boost/regex/v4/match_flags.hpp>
  24. #include <boost/regex/v4/error_type.hpp>
  25. #ifdef __cplusplus
  26. #include <cstddef>
  27. #else
  28. #include <stddef.h>
  29. #endif
  30. #ifdef BOOST_MSVC
  31. #pragma warning(push)
  32. #pragma warning(disable: 4103)
  33. #endif
  34. #ifdef BOOST_HAS_ABI_HEADERS
  35. # include BOOST_ABI_PREFIX
  36. #endif
  37. #ifdef BOOST_MSVC
  38. #pragma warning(pop)
  39. #endif
  40. /* include these defs only for POSIX compatablity */
  41. #ifdef __cplusplus
  42. namespace boost{
  43. extern "C" {
  44. #endif
  45. #if defined(__cplusplus) && !defined(BOOST_NO_STDC_NAMESPACE)
  46. typedef std::ptrdiff_t regoff_t;
  47. typedef std::size_t regsize_t;
  48. #else
  49. typedef ptrdiff_t regoff_t;
  50. typedef size_t regsize_t;
  51. #endif
  52. typedef struct
  53. {
  54. unsigned int re_magic;
  55. #ifdef __cplusplus
  56. std::size_t re_nsub; /* number of parenthesized subexpressions */
  57. #else
  58. size_t re_nsub;
  59. #endif
  60. const char* re_endp; /* end pointer for REG_PEND */
  61. void* guts; /* none of your business :-) */
  62. match_flag_type eflags; /* none of your business :-) */
  63. } regex_tA;
  64. #ifndef BOOST_NO_WREGEX
  65. typedef struct
  66. {
  67. unsigned int re_magic;
  68. #ifdef __cplusplus
  69. std::size_t re_nsub; /* number of parenthesized subexpressions */
  70. #else
  71. size_t re_nsub;
  72. #endif
  73. const wchar_t* re_endp; /* end pointer for REG_PEND */
  74. void* guts; /* none of your business :-) */
  75. match_flag_type eflags; /* none of your business :-) */
  76. } regex_tW;
  77. #endif
  78. typedef struct
  79. {
  80. regoff_t rm_so; /* start of match */
  81. regoff_t rm_eo; /* end of match */
  82. } regmatch_t;
  83. /* regcomp() flags */
  84. typedef enum{
  85. REG_BASIC = 0000,
  86. REG_EXTENDED = 0001,
  87. REG_ICASE = 0002,
  88. REG_NOSUB = 0004,
  89. REG_NEWLINE = 0010,
  90. REG_NOSPEC = 0020,
  91. REG_PEND = 0040,
  92. REG_DUMP = 0200,
  93. REG_NOCOLLATE = 0400,
  94. REG_ESCAPE_IN_LISTS = 01000,
  95. REG_NEWLINE_ALT = 02000,
  96. REG_PERLEX = 04000,
  97. REG_PERL = REG_EXTENDED | REG_NOCOLLATE | REG_ESCAPE_IN_LISTS | REG_PERLEX,
  98. REG_AWK = REG_EXTENDED | REG_ESCAPE_IN_LISTS,
  99. REG_GREP = REG_BASIC | REG_NEWLINE_ALT,
  100. REG_EGREP = REG_EXTENDED | REG_NEWLINE_ALT,
  101. REG_ASSERT = 15,
  102. REG_INVARG = 16,
  103. REG_ATOI = 255, /* convert name to number (!) */
  104. REG_ITOA = 0400 /* convert number to name (!) */
  105. } reg_comp_flags;
  106. /* regexec() flags */
  107. typedef enum{
  108. REG_NOTBOL = 00001,
  109. REG_NOTEOL = 00002,
  110. REG_STARTEND = 00004
  111. } reg_exec_flags;
  112. /*
  113. * POSIX error codes:
  114. */
  115. typedef unsigned reg_error_t;
  116. typedef reg_error_t reg_errcode_t; /* backwards compatibility */
  117. static const reg_error_t REG_NOERROR = 0; /* Success. */
  118. static const reg_error_t REG_NOMATCH = 1; /* Didn't find a match (for regexec). */
  119. /* POSIX regcomp return error codes. (In the order listed in the
  120. standard.) */
  121. static const reg_error_t REG_BADPAT = 2; /* Invalid pattern. */
  122. static const reg_error_t REG_ECOLLATE = 3; /* Undefined collating element. */
  123. static const reg_error_t REG_ECTYPE = 4; /* Invalid character class name. */
  124. static const reg_error_t REG_EESCAPE = 5; /* Trailing backslash. */
  125. static const reg_error_t REG_ESUBREG = 6; /* Invalid back reference. */
  126. static const reg_error_t REG_EBRACK = 7; /* Unmatched left bracket. */
  127. static const reg_error_t REG_EPAREN = 8; /* Parenthesis imbalance. */
  128. static const reg_error_t REG_EBRACE = 9; /* Unmatched \{. */
  129. static const reg_error_t REG_BADBR = 10; /* Invalid contents of \{\}. */
  130. static const reg_error_t REG_ERANGE = 11; /* Invalid range end. */
  131. static const reg_error_t REG_ESPACE = 12; /* Ran out of memory. */
  132. static const reg_error_t REG_BADRPT = 13; /* No preceding re for repetition op. */
  133. static const reg_error_t REG_EEND = 14; /* unexpected end of expression */
  134. static const reg_error_t REG_ESIZE = 15; /* expression too big */
  135. static const reg_error_t REG_ERPAREN = 8; /* = REG_EPAREN : unmatched right parenthesis */
  136. static const reg_error_t REG_EMPTY = 17; /* empty expression */
  137. static const reg_error_t REG_E_MEMORY = 15; /* = REG_ESIZE : out of memory */
  138. static const reg_error_t REG_ECOMPLEXITY = 18; /* complexity too high */
  139. static const reg_error_t REG_ESTACK = 19; /* out of stack space */
  140. static const reg_error_t REG_E_PERL = 20; /* Perl (?...) error */
  141. static const reg_error_t REG_E_UNKNOWN = 21; /* unknown error */
  142. static const reg_error_t REG_ENOSYS = 21; /* = REG_E_UNKNOWN : Reserved. */
  143. BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA*, const char*, int);
  144. BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int, const regex_tA*, char*, regsize_t);
  145. BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecA(const regex_tA*, const char*, regsize_t, regmatch_t*, int);
  146. BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeA(regex_tA*);
  147. #ifndef BOOST_NO_WREGEX
  148. BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW*, const wchar_t*, int);
  149. BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int, const regex_tW*, wchar_t*, regsize_t);
  150. BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecW(const regex_tW*, const wchar_t*, regsize_t, regmatch_t*, int);
  151. BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeW(regex_tW*);
  152. #endif
  153. #ifdef UNICODE
  154. #define regcomp regcompW
  155. #define regerror regerrorW
  156. #define regexec regexecW
  157. #define regfree regfreeW
  158. #define regex_t regex_tW
  159. #else
  160. #define regcomp regcompA
  161. #define regerror regerrorA
  162. #define regexec regexecA
  163. #define regfree regfreeA
  164. #define regex_t regex_tA
  165. #endif
  166. #ifdef BOOST_MSVC
  167. #pragma warning(push)
  168. #pragma warning(disable: 4103)
  169. #endif
  170. #ifdef BOOST_HAS_ABI_HEADERS
  171. # include BOOST_ABI_SUFFIX
  172. #endif
  173. #ifdef BOOST_MSVC
  174. #pragma warning(pop)
  175. #endif
  176. #ifdef __cplusplus
  177. } /* extern "C" */
  178. } /* namespace */
  179. #endif
  180. #endif /* include guard */