cregex.hpp 6.2 KB

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