cregex.hpp 6.2 KB

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