From cf285ed3e5a76fa573620b2a2c550fb58b53cec3 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Thu, 7 Nov 2002 12:50:29 +0000 Subject: [PATCH] Changes made in preparation for new regex version. [SVN r16141] --- include/boost/cregex.hpp | 279 +-- include/boost/regex.hpp | 1577 +--------------- include/boost/regex/regex_traits.hpp | 781 +------- include/boost/regex/v3/cregex.hpp | 316 ++++ .../boost/regex/{detail => v3}/fileiter.hpp | 7 +- .../boost/regex/{detail => v3}/instances.hpp | 4 + include/boost/regex/v3/regex.hpp | 1636 +++++++++++++++++ .../regex/{detail => v3}/regex_compile.hpp | 0 .../regex/{detail => v3}/regex_cstring.hpp | 0 .../regex/{detail => v3}/regex_format.hpp | 0 include/boost/regex/v3/regex_fwd.hpp | 70 + .../boost/regex/{detail => v3}/regex_kmp.hpp | 0 .../{detail => v3}/regex_library_include.hpp | 0 .../regex/{detail => v3}/regex_match.hpp | 0 .../regex/{detail => v3}/regex_raw_buffer.hpp | 0 .../regex/{detail => v3}/regex_split.hpp | 0 .../regex/{detail => v3}/regex_stack.hpp | 3 +- .../regex/{detail => v3}/regex_synch.hpp | 0 include/boost/regex/v3/regex_traits.hpp | 815 ++++++++ include/boost/regex_fwd.hpp | 39 +- 20 files changed, 2856 insertions(+), 2671 deletions(-) create mode 100644 include/boost/regex/v3/cregex.hpp rename include/boost/regex/{detail => v3}/fileiter.hpp (98%) rename include/boost/regex/{detail => v3}/instances.hpp (99%) create mode 100644 include/boost/regex/v3/regex.hpp rename include/boost/regex/{detail => v3}/regex_compile.hpp (100%) rename include/boost/regex/{detail => v3}/regex_cstring.hpp (100%) rename include/boost/regex/{detail => v3}/regex_format.hpp (100%) create mode 100644 include/boost/regex/v3/regex_fwd.hpp rename include/boost/regex/{detail => v3}/regex_kmp.hpp (100%) rename include/boost/regex/{detail => v3}/regex_library_include.hpp (100%) rename include/boost/regex/{detail => v3}/regex_match.hpp (100%) rename include/boost/regex/{detail => v3}/regex_raw_buffer.hpp (100%) rename include/boost/regex/{detail => v3}/regex_split.hpp (100%) rename include/boost/regex/{detail => v3}/regex_stack.hpp (99%) rename include/boost/regex/{detail => v3}/regex_synch.hpp (100%) create mode 100644 include/boost/regex/v3/regex_traits.hpp diff --git a/include/boost/cregex.hpp b/include/boost/cregex.hpp index 5c11e09b..60385a99 100644 --- a/include/boost/cregex.hpp +++ b/include/boost/cregex.hpp @@ -24,283 +24,7 @@ #ifndef BOOST_RE_CREGEX_HPP #define BOOST_RE_CREGEX_HPP -#include - -#ifdef __BORLANDC__ - #pragma option push -a8 -b -Vx -Ve -pc -#endif - -/* include these defs only for POSIX compatablity */ -#ifdef __cplusplus -namespace boost{ -extern "C" { -#endif - -#if defined(__cplusplus) && !defined(BOOST_NO_STDC_NAMESPACE) -typedef std::ptrdiff_t regoff_t; -typedef std::size_t regsize_t; -#else -typedef ptrdiff_t regoff_t; -typedef size_t regsize_t; -#endif - -typedef struct -{ - unsigned int re_magic; - unsigned int re_nsub; /* number of parenthesized subexpressions */ - const char* re_endp; /* end pointer for REG_PEND */ - void* guts; /* none of your business :-) */ - unsigned int eflags; /* none of your business :-) */ -} regex_tA; - -#ifndef BOOST_NO_WREGEX -typedef struct -{ - unsigned int re_magic; - unsigned int re_nsub; /* number of parenthesized subexpressions */ - const wchar_t* re_endp; /* end pointer for REG_PEND */ - void* guts; /* none of your business :-) */ - unsigned int eflags; /* none of your business :-) */ -} regex_tW; -#endif - -typedef struct -{ - regoff_t rm_so; /* start of match */ - regoff_t rm_eo; /* end of match */ -} regmatch_t; - -/* regcomp() flags */ -typedef enum{ - REG_BASIC = 0000, - REG_EXTENDED = 0001, - REG_ICASE = 0002, - REG_NOSUB = 0004, - REG_NEWLINE = 0010, - REG_NOSPEC = 0020, - REG_PEND = 0040, - REG_DUMP = 0200, - REG_NOCOLLATE = 0400, - REG_ESCAPE_IN_LISTS = 01000, - REG_NEWLINE_ALT = 02000, - - REG_PERL = REG_EXTENDED | REG_NOCOLLATE | REG_ESCAPE_IN_LISTS, - REG_AWK = REG_EXTENDED | REG_ESCAPE_IN_LISTS, - REG_GREP = REG_BASIC | REG_NEWLINE_ALT, - REG_EGREP = REG_EXTENDED | REG_NEWLINE_ALT, - - REG_ASSERT = 15, - REG_INVARG = 16, - REG_ATOI = 255, /* convert name to number (!) */ - REG_ITOA = 0400 /* convert number to name (!) */ -} reg_comp_flags; - -/* regexec() flags */ -typedef enum{ - REG_NOTBOL = 00001, - REG_NOTEOL = 00002, - REG_STARTEND = 00004 -} reg_exec_flags; - -BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA*, const char*, int); -BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int, const regex_tA*, char*, regsize_t); -BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecA(const regex_tA*, const char*, regsize_t, regmatch_t*, int); -BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeA(regex_tA*); - -#ifndef BOOST_NO_WREGEX -BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW*, const wchar_t*, int); -BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int, const regex_tW*, wchar_t*, regsize_t); -BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecW(const regex_tW*, const wchar_t*, regsize_t, regmatch_t*, int); -BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeW(regex_tW*); -#endif - -#ifdef UNICODE -#define regcomp regcompW -#define regerror regerrorW -#define regexec regexecW -#define regfree regfreeW -#define regex_t regex_tW -#else -#define regcomp regcompA -#define regerror regerrorA -#define regexec regexecA -#define regfree regfreeA -#define regex_t regex_tA -#endif - -/* regerror() flags */ -typedef enum -{ - REG_NOERROR = 0, /* Success. */ - REG_NOMATCH = 1, /* Didn't find a match (for regexec). */ - - /* POSIX regcomp return error codes. (In the order listed in the - standard.) */ - REG_BADPAT = 2, /* Invalid pattern. */ - REG_ECOLLATE = 3, /* Undefined collating element. */ - REG_ECTYPE = 4, /* Invalid character class name. */ - REG_EESCAPE = 5, /* Trailing backslash. */ - REG_ESUBREG = 6, /* Invalid back reference. */ - REG_EBRACK = 7, /* Unmatched left bracket. */ - REG_EPAREN = 8, /* Parenthesis imbalance. */ - REG_EBRACE = 9, /* Unmatched \{. */ - REG_BADBR = 10, /* Invalid contents of \{\}. */ - REG_ERANGE = 11, /* Invalid range end. */ - REG_ESPACE = 12, /* Ran out of memory. */ - REG_BADRPT = 13, /* No preceding re for repetition op. */ - REG_EEND = 14, /* unexpected end of expression */ - REG_ESIZE = 15, /* expression too big */ - REG_ERPAREN = 16, /* unmatched right parenthesis */ - REG_EMPTY = 17, /* empty expression */ - REG_E_MEMORY = REG_ESIZE, /* out of memory */ - REG_E_UNKNOWN = 18 /* unknown error */ -} reg_errcode_t; - -enum match_flags -{ - match_default = 0, - match_not_bol = 1, // first is not start of line - match_not_eol = match_not_bol << 1, // last is not end of line - match_not_bob = match_not_eol << 1, // first is not start of buffer - match_not_eob = match_not_bob << 1, // last is not end of buffer - match_not_bow = match_not_eob << 1, // first is not start of word - match_not_eow = match_not_bow << 1, // last is not end of word - match_not_dot_newline = match_not_eow << 1, // \n is not matched by '.' - match_not_dot_null = match_not_dot_newline << 1, // '\0' is not matched by '.' - match_prev_avail = match_not_dot_null << 1, // *--first is a valid expression - match_init = match_prev_avail << 1, // internal use - match_any = match_init << 1, // don't care what we match - match_not_null = match_any << 1, // string can't be null - match_continuous = match_not_null << 1, // each grep match must continue from - // uninterupted from the previous one - match_partial = match_continuous << 1, // find partial matches - - match_stop = match_partial << 1, // stop after first match (grep) - match_all = match_stop << 1, // must find the whole of input even if match_any is set - match_max = match_all -}; - - -#ifdef __cplusplus -} // extern "C" -} // namespace -#endif - - -#ifdef __BORLANDC__ - #if __BORLANDC__ > 0x520 - #pragma option pop - #endif -#endif - - -// -// C++ high level wrapper goes here: -// -#if defined(__cplusplus) -#include -#include -namespace boost{ - -#ifdef __BORLANDC__ - #if __BORLANDC__ == 0x530 - #pragma option push -a4 -b - #elif __BORLANDC__ > 0x530 - #pragma option push -a8 -b - #endif -#endif - -class RegEx; - -namespace re_detail{ - -class RegExData; -struct pred1; -struct pred2; -struct pred3; -struct pred4; - -} // namespace re_detail - -#if defined(BOOST_MSVC) || defined(__BORLANDC__) -typedef bool (__cdecl *GrepCallback)(const RegEx& expression); -typedef bool (__cdecl *GrepFileCallback)(const char* file, const RegEx& expression); -typedef bool (__cdecl *FindFilesCallback)(const char* file); -#else -typedef bool (*GrepCallback)(const RegEx& expression); -typedef bool (*GrepFileCallback)(const char* file, const RegEx& expression); -typedef bool (*FindFilesCallback)(const char* file); -#endif - -class BOOST_REGEX_DECL RegEx -{ -private: - re_detail::RegExData* pdata; -public: - RegEx(); - RegEx(const RegEx& o); - ~RegEx(); - explicit RegEx(const char* c, bool icase = false); - explicit RegEx(const std::string& s, bool icase = false); - RegEx& operator=(const RegEx& o); - RegEx& operator=(const char* p); - RegEx& operator=(const std::string& s){ return this->operator=(s.c_str()); } - unsigned int SetExpression(const char* p, bool icase = false); - unsigned int SetExpression(const std::string& s, bool icase = false){ return SetExpression(s.c_str(), icase); } - std::string Expression()const; - unsigned int error_code()const; - // - // now matching operators: - // - bool Match(const char* p, unsigned int flags = match_default); - bool Match(const std::string& s, unsigned int flags = match_default) { return Match(s.c_str(), flags); } - bool Search(const char* p, unsigned int flags = match_default); - bool Search(const std::string& s, unsigned int flags = match_default) { return Search(s.c_str(), flags); } - unsigned int Grep(GrepCallback cb, const char* p, unsigned int flags = match_default); - unsigned int Grep(GrepCallback cb, const std::string& s, unsigned int flags = match_default) { return Grep(cb, s.c_str(), flags); } - unsigned int Grep(std::vector& v, const char* p, unsigned int flags = match_default); - unsigned int Grep(std::vector& v, const std::string& s, unsigned int flags = match_default) { return Grep(v, s.c_str(), flags); } - unsigned int Grep(std::vector& v, const char* p, unsigned int flags = match_default); - unsigned int Grep(std::vector& v, const std::string& s, unsigned int flags = match_default) { return Grep(v, s.c_str(), flags); } -#ifndef BOOST_REGEX_NO_FILEITER - unsigned int GrepFiles(GrepFileCallback cb, const char* files, bool recurse = false, unsigned int flags = match_default); - unsigned int GrepFiles(GrepFileCallback cb, const std::string& files, bool recurse = false, unsigned int flags = match_default) { return GrepFiles(cb, files.c_str(), recurse, flags); } - unsigned int FindFiles(FindFilesCallback cb, const char* files, bool recurse = false, unsigned int flags = match_default); - unsigned int FindFiles(FindFilesCallback cb, const std::string& files, bool recurse = false, unsigned int flags = match_default) { return FindFiles(cb, files.c_str(), recurse, flags); } -#endif - - std::string Merge(const std::string& in, const std::string& fmt, - bool copy = true, unsigned int flags = match_default); - std::string Merge(const char* in, const char* fmt, - bool copy = true, unsigned int flags = match_default); - - std::size_t Split(std::vector& v, std::string& s, unsigned flags = match_default, unsigned max_count = ~0); - // - // now operators for returning what matched in more detail: - // - std::size_t Position(int i = 0)const; - std::size_t Length(int i = 0)const; - bool Matched(int i = 0)const; - unsigned int Line()const; - unsigned int Marks()const; - std::string What(int i = 0)const; - std::string operator[](int i)const { return What(i); } - - static const unsigned int npos; - - friend struct re_detail::pred1; - friend struct re_detail::pred2; - friend struct re_detail::pred3; - friend struct re_detail::pred4; -}; - -#ifdef __BORLANDC__ - #pragma option pop -#endif - -} // namespace boost - -#endif +#include #endif // include guard @@ -310,3 +34,4 @@ public: + diff --git a/include/boost/regex.hpp b/include/boost/regex.hpp index c1313958..44a238ac 100644 --- a/include/boost/regex.hpp +++ b/include/boost/regex.hpp @@ -28,1583 +28,8 @@ #ifndef BOOST_RE_REGEX_HPP #define BOOST_RE_REGEX_HPP -#include - -#ifdef __cplusplus - -// what follows is all C++ don't include in C builds!! - -#ifdef BOOST_REGEX_DEBUG -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace boost{ - -#ifdef __BORLANDC__ - #pragma option push -a8 -b -Vx -Ve -pc -w-8027 -#endif - -namespace re_detail{ - -struct re_set_long; -struct re_syntax_base; - -} // namespace re_detail - -namespace deprecated{ -// -// class char_regex_traits_i -// provides case insensitive traits classes (deprecated): -template -class char_regex_traits_i : public regex_traits {}; - -template<> -class char_regex_traits_i : public regex_traits -{ -public: - typedef char char_type; - typedef unsigned char uchar_type; - typedef unsigned int size_type; - typedef regex_traits base_type; - - char BOOST_REGEX_CALL translate(char c, bool)const - { - return static_cast*>(this)->translate(c, true); - } -}; - -#ifndef BOOST_NO_WREGEX -template<> -class char_regex_traits_i : public regex_traits -{ -public: - typedef wchar_t char_type; - typedef unsigned short uchar_type; - typedef unsigned int size_type; - typedef regex_traits base_type; - - wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool)const - { - return static_cast*>(this)->translate(c, true); - } - boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last)const - { - boost::uint_fast32_t result = static_cast*>(this)->lookup_classname(first, last); - if((result & base_type::char_class_upper) == base_type::char_class_upper) - result |= base_type::char_class_alpha; - return result; - } -}; -#endif -} // namespace deprecated - - -namespace re_detail{ - -enum mask_type -{ - mask_take = 1, - mask_skip = 2, - mask_any = mask_skip | mask_take, - mask_all = mask_any -}; - -struct _narrow_type{}; -struct _wide_type{}; - -template -class is_byte; - -template<> -class is_byte -{ -public: - typedef _narrow_type width_type; -}; - -template<> -class is_byte -{ -public: - typedef _narrow_type width_type; -}; - -template<> -class is_byte -{ -public: - typedef _narrow_type width_type; -}; - -template -class is_byte -{ -public: - typedef _wide_type width_type; -}; - - -// -// compiled structures -// -// the following defs describe the format of the compiled string -// - -// -// enum syntax_element_type -// describes the type of a record -enum syntax_element_type -{ - syntax_element_startmark = 0, - syntax_element_endmark = syntax_element_startmark + 1, - syntax_element_literal = syntax_element_endmark + 1, - syntax_element_start_line = syntax_element_literal + 1, - syntax_element_end_line = syntax_element_start_line + 1, - syntax_element_wild = syntax_element_end_line + 1, - syntax_element_match = syntax_element_wild + 1, - syntax_element_word_boundary = syntax_element_match + 1, - syntax_element_within_word = syntax_element_word_boundary + 1, - syntax_element_word_start = syntax_element_within_word + 1, - syntax_element_word_end = syntax_element_word_start + 1, - syntax_element_buffer_start = syntax_element_word_end + 1, - syntax_element_buffer_end = syntax_element_buffer_start + 1, - syntax_element_backref = syntax_element_buffer_end + 1, - syntax_element_long_set = syntax_element_backref + 1, - syntax_element_set = syntax_element_long_set + 1, - syntax_element_jump = syntax_element_set + 1, - syntax_element_alt = syntax_element_jump + 1, - syntax_element_rep = syntax_element_alt + 1, - syntax_element_combining = syntax_element_rep + 1, - syntax_element_soft_buffer_end = syntax_element_combining + 1, - syntax_element_restart_continue = syntax_element_soft_buffer_end + 1 -}; - -#ifdef BOOST_REGEX_DEBUG -// dwa 09/26/00 - This is needed to suppress warnings about an ambiguous conversion -std::ostream& operator<<(std::ostream&, syntax_element_type); -#endif - -union offset_type -{ - re_syntax_base* p; - std::size_t i; -}; - -// -// struct re_syntax_base -// base class for all syntax types: -struct re_syntax_base -{ - syntax_element_type type; - offset_type next; - unsigned int can_be_null; -}; - -// -// struct re_brace -// marks start or end of (...) -struct re_brace : public re_syntax_base -{ - int index; -}; - -// -// struct re_literal -// marks a literal string and -// is followed by an array of charT[length]: -struct re_literal : public re_syntax_base -{ - unsigned int length; -}; - -// -// struct re_long_set -// provides data for sets [...] containing -// wide characters -struct re_set_long : public re_syntax_base -{ - unsigned int csingles, cranges, cequivalents; - boost::uint_fast32_t cclasses; - bool isnot; -}; - -// -// struct re_set -// provides a map of bools for sets containing -// narrow, single byte characters. -struct re_set : public re_syntax_base -{ - unsigned char _map[256]; -}; - -// -// struct re_jump -// provides alternative next destination -struct re_jump : public re_syntax_base -{ - offset_type alt; - unsigned char _map[256]; -}; - -// -// struct re_repeat -// provides repeat expressions -struct re_repeat : public re_jump -{ - unsigned min, max; - int id; - bool leading; - bool greedy; - bool singleton; -}; - - -// -// enum re_jump_size_type -// provides compiled size of re_jump -// allowing for trailing alignment -// provide this so we know how many -// bytes to insert -enum re_jump_size_type -{ - re_jump_size = (sizeof(re_jump) + padding_mask) & ~(padding_mask), - re_repeater_size = (sizeof(re_repeat) + padding_mask) & ~(padding_mask) -}; - -} // namespace re_detail - -// -// class basic_regex -// handles error codes and flags - -class BOOST_REGEX_DECL regbase -{ -public: - enum flag_type_ - { - escape_in_lists = 1, // '\' special inside [...] - char_classes = escape_in_lists << 1, // [[:CLASS:]] allowed - intervals = char_classes << 1, // {x,y} allowed - limited_ops = intervals << 1, // all of + ? and | are normal characters - newline_alt = limited_ops << 1, // \n is the same as | - bk_plus_qm = newline_alt << 1, // uses \+ and \? - bk_braces = bk_plus_qm << 1, // uses \{ and \} - bk_parens = bk_braces << 1, // uses \( and \) - bk_refs = bk_parens << 1, // \d allowed - bk_vbar = bk_refs << 1, // uses \| - - use_except = bk_vbar << 1, // exception on error - failbit = use_except << 1, // error flag - literal = failbit << 1, // all characters are literals - icase = literal << 1, // characters are matched regardless of case - nocollate = icase << 1, // don't use locale specific collation - - basic = char_classes | intervals | limited_ops | bk_braces | bk_parens | bk_refs, - extended = char_classes | intervals | bk_refs, - normal = escape_in_lists | char_classes | intervals | bk_refs | nocollate, - emacs = bk_braces | bk_parens | bk_refs | bk_vbar, - awk = extended | escape_in_lists, - grep = basic | newline_alt, - egrep = extended | newline_alt, - sed = basic, - perl = normal - }; - typedef unsigned int flag_type; - - enum restart_info - { - restart_any = 0, - restart_word = 1, - restart_line = 2, - restart_buf = 3, - restart_continue = 4, - restart_lit = 5, - restart_fixed_lit = 6 - }; - - flag_type BOOST_REGEX_CALL flags()const - { - return _flags; - } - - regbase(); - regbase(const regbase& b); -protected: - flag_type _flags; -}; - -// -// some forward declarations: -namespace re_detail{ -template -class _priv_match_data; - -#if defined(BOOST_NO_STD_ITERATOR_TRAITS) || defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - -template -struct regex_iterator_traits -{ - typedef typename T::iterator_category iterator_category; - typedef typename T::value_type value_type; -#if !defined(BOOST_NO_STD_ITERATOR) - typedef typename T::difference_type difference_type; - typedef typename T::pointer pointer; - typedef typename T::reference reference; -#else - typedef std::ptrdiff_t difference_type; - typedef value_type* pointer; - typedef value_type& reference; -#endif -}; - -template -struct pointer_iterator_traits -{ - typedef std::ptrdiff_t difference_type; - typedef T value_type; - typedef T* pointer; - typedef T& reference; - typedef std::random_access_iterator_tag iterator_category; -}; -template -struct const_pointer_iterator_traits -{ - typedef std::ptrdiff_t difference_type; - typedef T value_type; - typedef const T* pointer; - typedef const T& reference; - typedef std::random_access_iterator_tag iterator_category; -}; - -template<> -struct regex_iterator_traits : pointer_iterator_traits{}; -template<> -struct regex_iterator_traits : const_pointer_iterator_traits{}; -template<> -struct regex_iterator_traits : pointer_iterator_traits{}; -template<> -struct regex_iterator_traits : const_pointer_iterator_traits{}; - -#if defined(__SGI_STL_PORT) && defined(__STL_DEBUG) -template<> -struct regex_iterator_traits : pointer_iterator_traits{}; -template<> -struct regex_iterator_traits : const_pointer_iterator_traits{}; -#ifndef BOOST_NO_STD_WSTRING -template<> -struct regex_iterator_traits : pointer_iterator_traits{}; -template<> -struct regex_iterator_traits : const_pointer_iterator_traits{}; -#endif // BOOST_NO_WSTRING -#endif // stport - -#else - -template -struct regex_iterator_traits : public std::iterator_traits {}; - -#endif - -template -struct def_alloc_param_traits -{ - typedef typename regex_iterator_traits::value_type const_value_type; - typedef typename remove_cv::type type; -}; -template <> -struct def_alloc_param_traits -{ - typedef char type; -}; -template <> -struct def_alloc_param_traits -{ - typedef wchar_t type; -}; - -} - -template ::type) > -#else -BOOST_DEFAULT_ALLOCATOR(re_detail::def_alloc_param_traits::type) > -#endif -class match_results; - -// -// class reg_expression -// represents the compiled -// regular expression: -// - -#ifdef BOOST_MSVC -#pragma warning(push) -#pragma warning(disable : 4251 4231 4660) -#endif - -#ifdef BOOST_REGEX_NO_FWD -template , class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) > -#else -template -#endif -class reg_expression : public regbase -{ -public: - typedef typename traits::size_type traits_size_type; - typedef typename traits::uchar_type traits_uchar_type; - typedef typename traits::string_type traits_string_type; - // typedefs: - typedef charT char_type; - typedef traits traits_type; - - // locale_type - // placeholder for actual locale type used by the - // traits class to localise *this. - typedef typename traits::locale_type locale_type; - // value_type - typedef charT value_type; - // reference, const_reference - typedef charT& reference; - typedef const charT& const_reference; - // iterator, const_iterator - typedef const charT* const_iterator; - typedef const_iterator iterator; - // difference_type - typedef typename Allocator::difference_type difference_type; - // size_type - typedef typename Allocator::size_type size_type; - // allocator_type - typedef Allocator allocator_type; - typedef Allocator alloc_type; - // flag_type - typedef regbase::flag_type flag_type; - -public: - explicit reg_expression(const Allocator& a = Allocator()); - explicit reg_expression(const charT* p, flag_type f = regbase::normal, const Allocator& a = Allocator()); - reg_expression(const charT* p1, const charT* p2, flag_type f = regbase::normal, const Allocator& a = Allocator()); - reg_expression(const charT* p, size_type len, flag_type f, const Allocator& a = Allocator()); - reg_expression(const reg_expression&); - ~reg_expression(); - reg_expression& BOOST_REGEX_CALL operator=(const reg_expression&); - reg_expression& BOOST_REGEX_CALL operator=(const charT* ptr) - { - set_expression(ptr, regbase::normal | regbase::use_except); - return *this; - } - - // - // assign: - reg_expression& assign(const reg_expression& that) - { return *this = that; } - reg_expression& assign(const charT* ptr, flag_type f = regbase::normal) - { - set_expression(ptr, f | regbase::use_except); - return *this; - } - - reg_expression& assign(const charT* first, - const charT* last, - flag_type f = regbase::normal) - { - set_expression(first, last, f | regbase::use_except); - return *this; - } -#if !defined(BOOST_NO_MEMBER_TEMPLATES) && !(defined(__IBMCPP__) && (__IBMCPP__ <= 502)) - - template - unsigned int BOOST_REGEX_CALL set_expression(const std::basic_string& p, flag_type f = regbase::normal) - { return set_expression(p.data(), p.data() + p.size(), f); } - - template - explicit reg_expression(const std::basic_string& p, flag_type f = regbase::normal, const Allocator& a = Allocator()) - : data(a), pkmp(0), error_code_(REG_EMPTY), _expression(0) { set_expression(p, f | regbase::use_except); } - - template - reg_expression(I first, I last, flag_type f = regbase::normal, const Allocator& al = Allocator()) - : data(al), pkmp(0), error_code_(REG_EMPTY), _expression(0) - { - size_type len = last-first; - scoped_array a(new charT[len]); - std::copy(first, last, a.get()); - set_expression(a.get(), a.get() + len, f | regbase::use_except); - } - - template - reg_expression& BOOST_REGEX_CALL operator=(const std::basic_string& p) - { - set_expression(p.c_str(), p.c_str() + p.size(), regbase::normal | regbase::use_except); - return *this; - } - - template - reg_expression& BOOST_REGEX_CALL assign( - const std::basic_string& s, - flag_type f = regbase::normal) - { - set_expression(s.c_str(), s.c_str() + s.size(), f | regbase::use_except); - return *this; - } - - template - reg_expression& BOOST_REGEX_CALL assign(fwd_iterator first, - fwd_iterator last, - flag_type f = regbase::normal) - { - size_type len = last-first; - scoped_array a(new charT[len]); - std::copy(first, last, a.get()); - set_expression(a.get(), a.get() + len, f | regbase::use_except); - return *this; - } -#else - unsigned int BOOST_REGEX_CALL set_expression(const std::basic_string& p, flag_type f = regbase::normal) - { return set_expression(p.data(), p.data() + p.size(), f | regbase::use_except); } - - reg_expression(const std::basic_string& p, flag_type f = regbase::normal, const Allocator& a = Allocator()) - : data(a), pkmp(0) { set_expression(p, f | regbase::use_except); } - - reg_expression& BOOST_REGEX_CALL operator=(const std::basic_string& p) - { - set_expression(p.c_str(), p.c_str() + p.size(), regbase::normal | regbase::use_except); - return *this; - } - - reg_expression& BOOST_REGEX_CALL assign( - const std::basic_string& s, - flag_type f = regbase::normal) - { - set_expression(s.c_str(), s.c_str() + s.size(), f | regbase::use_except); - return *this; - } - -#endif - - - // - // allocator access: - Allocator BOOST_REGEX_CALL get_allocator()const; - // - // locale: - locale_type BOOST_REGEX_CALL imbue(locale_type l){ return traits_inst.imbue(l); } - locale_type BOOST_REGEX_CALL getloc()const{ return traits_inst.getloc(); } - // - // flags: - flag_type BOOST_REGEX_CALL getflags()const - { return flags(); } - // - // str: - std::basic_string BOOST_REGEX_CALL str()const - { - std::basic_string result; - if(this->error_code() == 0) - result = std::basic_string(_expression, _expression_len); - return result; - } - // - // begin, end: - const_iterator BOOST_REGEX_CALL begin()const - { return (this->error_code() ? 0 : _expression); } - const_iterator BOOST_REGEX_CALL end()const - { return (this->error_code() ? 0 : _expression + _expression_len); } - // - // swap: - void BOOST_REGEX_CALL swap(reg_expression&)throw(); - // - // size: - size_type BOOST_REGEX_CALL size()const - { return (this->error_code() ? 0 : _expression_len); } - // - // max_size: - size_type BOOST_REGEX_CALL max_size()const - { return UINT_MAX; } - // - // empty: - bool BOOST_REGEX_CALL empty()const - { return 0 != this->error_code(); } - - unsigned BOOST_REGEX_CALL mark_count()const { return (this->error_code() ? 0 : marks); } - bool BOOST_REGEX_CALL operator==(const reg_expression&)const; - bool BOOST_REGEX_CALL operator<(const reg_expression&)const; - // - // The following are deprecated as public interfaces - // but are available for compatibility with earlier versions. - allocator_type BOOST_REGEX_CALL allocator()const; - const charT* BOOST_REGEX_CALL expression()const { return (this->error_code() ? 0 : _expression); } - unsigned int BOOST_REGEX_CALL set_expression(const charT* p, const charT* end, flag_type f = regbase::normal); - unsigned int BOOST_REGEX_CALL set_expression(const charT* p, flag_type f = regbase::normal) { return set_expression(p, p + traits_type::length(p), f); } - // - // this should be private but template friends don't work: - const traits_type& get_traits()const { return traits_inst; } - unsigned int BOOST_REGEX_CALL error_code()const - { - return error_code_; - } - -private: - traits_type traits_inst; - re_detail::raw_storage data; - unsigned _restart_type; - unsigned marks; - int repeats; - unsigned char* startmap; - std::size_t _expression_len; - std::size_t _leading_len; - const charT* _leading_string; - std::size_t _leading_string_len; - re_detail::kmp_info* pkmp; - unsigned error_code_; - charT* _expression; - - void BOOST_REGEX_CALL compile_maps(); - void BOOST_REGEX_CALL compile_map(re_detail::re_syntax_base* node, unsigned char* _map, unsigned int* pnull, unsigned char mask, re_detail::re_syntax_base* terminal = 0)const; - bool BOOST_REGEX_CALL probe_start(re_detail::re_syntax_base* node, charT c, re_detail::re_syntax_base* terminal)const; - bool BOOST_REGEX_CALL probe_start_null(re_detail::re_syntax_base* node, re_detail::re_syntax_base* terminal)const; - void BOOST_REGEX_CALL fixup_apply(re_detail::re_syntax_base* b, unsigned cbraces); - void BOOST_REGEX_CALL move_offsets(re_detail::re_syntax_base* j, unsigned size); - re_detail::re_syntax_base* BOOST_REGEX_CALL compile_set(const charT*& first, const charT* last); - re_detail::re_syntax_base* BOOST_REGEX_CALL compile_set_aux(re_detail::jstack& singles, re_detail::jstack& ranges, re_detail::jstack& classes, re_detail::jstack& equivalents, bool isnot, const re_detail::_narrow_type&); - re_detail::re_syntax_base* BOOST_REGEX_CALL compile_set_aux(re_detail::jstack& singles, re_detail::jstack& ranges, re_detail::jstack& classes, re_detail::jstack& equivalents, bool isnot, const re_detail::_wide_type&); - re_detail::re_syntax_base* BOOST_REGEX_CALL compile_set_simple(re_detail::re_syntax_base* dat, unsigned long cls, bool isnot = false); - unsigned int BOOST_REGEX_CALL parse_inner_set(const charT*& first, const charT* last); - - re_detail::re_syntax_base* BOOST_REGEX_CALL add_simple(re_detail::re_syntax_base* dat, re_detail::syntax_element_type type, unsigned int size = sizeof(re_detail::re_syntax_base)); - re_detail::re_syntax_base* BOOST_REGEX_CALL add_literal(re_detail::re_syntax_base* dat, charT c); - charT BOOST_REGEX_CALL parse_escape(const charT*& first, const charT* last); - void BOOST_REGEX_CALL parse_range(const charT*& first, const charT* last, unsigned& min, unsigned& max); - bool BOOST_REGEX_CALL skip_space(const charT*& first, const charT* last); - unsigned int BOOST_REGEX_CALL probe_restart(re_detail::re_syntax_base* dat); - unsigned int BOOST_REGEX_CALL fixup_leading_rep(re_detail::re_syntax_base* dat, re_detail::re_syntax_base* end); - void BOOST_REGEX_CALL fail(unsigned int err); - -protected: - static int BOOST_REGEX_CALL repeat_count(const reg_expression& e) - { return e.repeats; } - static unsigned int BOOST_REGEX_CALL restart_type(const reg_expression& e) - { return e._restart_type; } - static const re_detail::re_syntax_base* BOOST_REGEX_CALL first(const reg_expression& e) - { return (const re_detail::re_syntax_base*)e.data.data(); } - static const unsigned char* BOOST_REGEX_CALL get_map(const reg_expression& e) - { return e.startmap; } - static std::size_t BOOST_REGEX_CALL leading_length(const reg_expression& e) - { return e._leading_len; } - static const re_detail::kmp_info* get_kmp(const reg_expression& e) - { return e.pkmp; } - static bool BOOST_REGEX_CALL can_start(charT c, const unsigned char* _map, unsigned char mask, const re_detail::_wide_type&); - static bool BOOST_REGEX_CALL can_start(charT c, const unsigned char* _map, unsigned char mask, const re_detail::_narrow_type&); -}; - -#ifdef BOOST_MSVC -#pragma warning (pop) -#endif - -template -inline void BOOST_REGEX_CALL reg_expression::swap(reg_expression& that)throw() -{ - // this is not as efficient as it should be, - // however swapping traits classes is problematic - // so just use 'brute force' method for now: - reg_expression e(that); - that = *this; - *this = e; -} - - -// -// class match_results and match_results_base -// handles what matched where - -template -struct sub_match -{ - typedef typename re_detail::regex_iterator_traits::value_type value_type; -#if defined(BOOST_NO_STD_ITERATOR_TRAITS) || defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - typedef std::ptrdiff_t difference_type; -#else - typedef typename re_detail::regex_iterator_traits::difference_type difference_type; -#endif - typedef iterator iterator_type; - - iterator first; - iterator second; - bool matched; - - operator std::basic_string ()const - { - std::basic_string result; - std::size_t len = boost::re_detail::distance((iterator)first, (iterator)second); - result.reserve(len); - iterator i = first; - while(i != second) - { - result.append(1, *i); - ++i; - } - return result; - } - #ifdef BOOST_OLD_REGEX_H - // - // the following are deprecated, do not use!! - // - operator int()const; - operator unsigned int()const; - operator short()const - { - return (short)(int)(*this); - } - operator unsigned short()const - { - return (unsigned short)(unsigned int)(*this); - } - #endif - sub_match() { matched = false; } - sub_match(iterator i) : first(i), second(i), matched(false) {} - - bool operator==(const sub_match& that)const - { - return (first == that.first) && (second == that.second) && (matched == that.matched); - } - bool BOOST_REGEX_CALL operator !=(const sub_match& that)const - { return !(*this == that); } - - difference_type BOOST_REGEX_CALL length()const - { - difference_type n = boost::re_detail::distance((iterator)first, (iterator)second); - return n; - } -}; - -#ifdef BOOST_OLD_REGEX_H -namespace re_detail{ -template -int do_toi(iterator i, iterator j, char c, int radix) -{ - std::string s(i, j); - char* p; - int result = std::strtol(s.c_str(), &p, radix); -#ifndef BOOST_NO_EXCEPTIONS - if(*p)throw bad_pattern("Bad sub-expression"); -#endif - BOOST_REGEX_NOEH_ASSERT(0 == *p) - return result; -} - -// -// helper: -template -int do_toi(I& i, I j, charT c) -{ - int result = 0; - while((i != j) && (isdigit(*i))) - { - result = result*10 + (*i - '0'); - ++i; - } - return result; -} -} - - -template -sub_match::operator int()const -{ - iterator i = first; - iterator j = second; -#ifndef BOOST_NO_EXCEPTIONS - if(i == j)throw bad_pattern("Bad sub-expression"); -#endif - BOOST_REGEX_NOEH_ASSERT(i != j) - int neg = 1; - if((i != j) && (*i == '-')) - { - neg = -1; - ++i; - } - neg *= re_detail::do_toi(i, j, *i); -#ifndef BOOST_NO_EXCEPTIONS - if(i != j)throw bad_pattern("Bad sub-expression"); -#endif - BOOST_REGEX_NOEH_ASSERT(i == j) - return neg; -} -template -sub_match::operator unsigned int()const -{ - iterator i = first; - iterator j = second; -#ifndef BOOST_NO_EXCEPTIONS - if(i == j) - throw bad_pattern("Bad sub-expression"); -#endif - BOOST_REGEX_NOEH_ASSERT(i != j) - return re_detail::do_toi(i, j, *first); -} -#endif - -namespace re_detail{ - -template ::type) > -class match_results_base -{ -public: - typedef Allocator alloc_type; - typedef typename boost::detail::rebind_allocator::type iterator_alloc; - typedef typename iterator_alloc::size_type size_type; -#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_STD_ITERATOR_TRAITS) - typedef typename std::iterator_traits::difference_type difference_type; - typedef typename std::iterator_traits::value_type char_type; -#else - typedef std::ptrdiff_t difference_type; - typedef typename re_detail::regex_iterator_traits::value_type char_type; -#endif - typedef sub_match value_type; - typedef iterator iterator_type; - -protected: - typedef typename boost::detail::rebind_allocator::type c_alloc; - - struct c_reference : public c_alloc - { - std::size_t cmatches; - unsigned count; - sub_match head, tail, null; - unsigned int lines; - iterator line_pos, base; - c_reference(const Allocator& a) - : c_alloc(a), cmatches(0), count(0), lines(0) { } - - bool operator==(const c_reference& that)const - { - return (cmatches == that.cmatches) && - (count == that.count) && - (head == that.head) && - (tail == that.tail) && - (lines == that.lines) && - (base == that.base); - } - bool operator!=(const c_reference& that)const - { return !(*this == that); } - }; - - c_reference* ref; - - void BOOST_REGEX_CALL cow(); - - // protected contructor for derived class... - match_results_base(bool){} - void BOOST_REGEX_CALL m_free(); - -public: - - match_results_base(const Allocator& a = Allocator()); - - match_results_base(const match_results_base& m) - { - ref = m.ref; - ++(ref->count); - } - - match_results_base& BOOST_REGEX_CALL operator=(const match_results_base& m); - - ~match_results_base() - { - m_free(); - } - - size_type BOOST_REGEX_CALL size()const - { - //return (*this)[0].matched ? ref->cmatches : 0; - return ref->cmatches; - } - - const sub_match& BOOST_REGEX_CALL operator[](int n) const - { - if((n >= 0) && ((unsigned int)n < ref->cmatches)) - return *(sub_match*)((char*)ref + sizeof(c_reference) + sizeof(sub_match)*n); - return (n == -1) ? ref->head : (n == -2) ? ref->tail : ref->null; - } - - Allocator BOOST_REGEX_CALL allocator()const; - - difference_type BOOST_REGEX_CALL length(unsigned int sub = 0)const - { - jm_assert(ref->cmatches); - const sub_match& m = (*this)[sub]; - if(m.matched == false) - return 0; - difference_type n = boost::re_detail::distance((iterator)m.first, (iterator)m.second); - return n; - } - - std::basic_string str(int i)const - { - return static_cast >((*this)[i]); - } - - unsigned int BOOST_REGEX_CALL line()const - { - return ref->lines; - } - - difference_type BOOST_REGEX_CALL position(unsigned int sub = 0)const - { - jm_assert(ref->cmatches); - const sub_match& s = (*this)[sub]; - if(s.matched == false) - return -1; - difference_type n = boost::re_detail::distance((iterator)(ref->base), (iterator)(s.first)); - return n; - } - - iterator BOOST_REGEX_CALL line_start()const - { - return ref->line_pos; - } - - void swap(match_results_base& that) - { - c_reference* t = that.ref; - that.ref = ref; - ref = t; - } - - bool operator==(const match_results_base& that)const; - bool operator<(const match_results_base& that)const - { return position() < that.position(); } - - friend class match_results; - - void BOOST_REGEX_CALL set_size(size_type n); - void BOOST_REGEX_CALL set_size(size_type n, iterator i, iterator j); - void BOOST_REGEX_CALL maybe_assign(const match_results_base& m); - void BOOST_REGEX_CALL init_fail(iterator i, iterator j); - - void BOOST_REGEX_CALL set_first(iterator i); - void BOOST_REGEX_CALL set_first(iterator i, std::size_t pos); - - void BOOST_REGEX_CALL set_second(iterator i) - { - cow(); - ((sub_match*)(ref+1))->second = i; - ((sub_match*)(ref+1))->matched = true; - ref->tail.first = i; - ref->tail.matched = (ref->tail.first == ref->tail.second) ? false : true; - } - - void BOOST_REGEX_CALL set_second(iterator i, std::size_t pos, bool m = true) - { - cow(); - ((sub_match*)((char*)ref + sizeof(c_reference) + sizeof(sub_match) * pos))->second = i; - ((sub_match*)((char*)ref + sizeof(c_reference) + sizeof(sub_match) * pos))->matched = m; - if(pos == 0) - { - ref->tail.first = i; - ref->tail.matched = (ref->tail.first == ref->tail.second) ? false : true; - } - } - - void BOOST_REGEX_CALL set_line(unsigned int i, iterator pos) - { - ref->lines = i; - ref->line_pos = pos; - } - - void BOOST_REGEX_CALL set_base(iterator pos) - { - ref->base = pos; - } -}; - -template -void BOOST_REGEX_CALL match_results_base::set_first(iterator i) -{ - cow(); - ref->head.second = i; - ref->head.matched = (ref->head.first == ref->head.second) ? false : true; - sub_match* p1 = (sub_match*)(ref+1); - sub_match* p2 = p1 + ref->cmatches; - p1->first = i; - p1->matched = false; - ++p1; - while(p1 != p2) - { - p1->matched = false; - p1->first = ref->tail.second; - p1->second = ref->tail.second; - ++p1; - } -} - -template -void BOOST_REGEX_CALL match_results_base::set_first(iterator i, std::size_t pos) -{ - cow(); - ((sub_match*)((char*)ref + sizeof(c_reference) + sizeof(sub_match) * pos))->first = i; - if(pos == 0) - { - ref->head.second = i; - ref->head.matched = (ref->head.first == ref->head.second) ? false : true; - sub_match* p1 = (sub_match*)(ref+1); - sub_match* p2 = p1 + ref->cmatches; - p1->first = i; - p1->matched = false; - ++p1; - while(p1 != p2) - { - p1->matched = false; - p1->first = ref->tail.second; - p1->second = ref->tail.second; - ++p1; - } - } -} - - -template -match_results_base::match_results_base(const Allocator& a) -{ - ref = (c_reference*)c_alloc(a).allocate(sizeof(sub_match) + sizeof(c_reference)); - BOOST_REGEX_NOEH_ASSERT(ref) -#ifndef BOOST_NO_EXCEPTIONS - try - { -#endif - new (ref) c_reference(a); - ref->cmatches = 1; - ref->count = 1; - // construct the sub_match: -#ifndef BOOST_NO_EXCEPTIONS - try - { -#endif - new ((sub_match*)(ref+1)) sub_match(); -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - ::boost::re_detail::pointer_destroy(ref); - throw; - } - } - catch(...) - { - c_alloc(a).deallocate((char*)(void*)ref, sizeof(sub_match) + sizeof(c_reference)); - throw; - } -#endif -} - -template -Allocator BOOST_REGEX_CALL match_results_base::allocator()const -{ - return *((c_alloc*)ref); -} - -template -inline match_results_base& BOOST_REGEX_CALL match_results_base::operator=(const match_results_base& m) -{ - if(ref != m.ref) - { - m_free(); - ref = m.ref; - ++(ref->count); - } - return *this; -} - - -template -void BOOST_REGEX_CALL match_results_base::m_free() -{ - if(--(ref->count) == 0) - { - c_alloc a(*ref); - sub_match* p1, *p2; - p1 = (sub_match*)(ref+1); - p2 = p1 + ref->cmatches; - while(p1 != p2) - { - ::boost::re_detail::pointer_destroy(p1); - ++p1; - } - ::boost::re_detail::pointer_destroy(ref); - a.deallocate((char*)(void*)ref, sizeof(sub_match) * ref->cmatches + sizeof(c_reference)); - } -} - -template -bool match_results_base::operator==(const match_results_base& that)const -{ - if(*ref != *(that.ref)) - return false; - const sub_match* p1 = (sub_match*)(ref+1); - const sub_match* p2 = p1 + ref->cmatches; - const sub_match* p3 = (sub_match*)(that.ref+1); - while(p1 != p2) - { - if(*p1 != *p3) - return false; - ++p1; - ++p3; - } - return true; -} - -template -void BOOST_REGEX_CALL match_results_base::set_size(size_type n) -{ - if(ref->cmatches != n) - { - c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match) * n + sizeof(c_reference)); - BOOST_REGEX_NOEH_ASSERT(newref) -#ifndef BOOST_NO_EXCEPTIONS - try - { -#endif - new (newref) c_reference(*ref); - newref->count = 1; - newref->cmatches = n; - sub_match* p1, *p2; - p1 = (sub_match*)(newref+1); - p2 = p1 + newref->cmatches; -#ifndef BOOST_NO_EXCEPTIONS - try - { -#endif - while(p1 != p2) - { - new (p1) sub_match(); - ++p1; - } - m_free(); -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - p2 = (sub_match*)(newref+1); - while(p2 != p1) - { - ::boost::re_detail::pointer_destroy(p2); - ++p2; - } - ::boost::re_detail::pointer_destroy(ref); - throw; - } -#endif - ref = newref; -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - ref->deallocate((char*)(void*)newref, sizeof(sub_match) * n + sizeof(c_reference)); - throw; - } -#endif - } -} - -template -void BOOST_REGEX_CALL match_results_base::set_size(size_type n, iterator i, iterator j) -{ - if(ref->cmatches != n) - { - c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match) * n + sizeof(c_reference)); - BOOST_REGEX_NOEH_ASSERT(newref) -#ifndef BOOST_NO_EXCEPTIONS - try{ -#endif - new (newref) c_reference(*ref); - newref->count = 1; - newref->cmatches = n; - sub_match* p1 = (sub_match*)(newref+1); - sub_match* p2 = p1 + newref->cmatches; -#ifndef BOOST_NO_EXCEPTIONS - try - { -#endif - while(p1 != p2) - { - new (p1) sub_match(j); - ++p1; - } - m_free(); -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - p2 = (sub_match*)(newref+1); - while(p2 != p1) - { - ::boost::re_detail::pointer_destroy(p2); - ++p2; - } - ::boost::re_detail::pointer_destroy(ref); - throw; - } -#endif - ref = newref; -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - ref->deallocate((char*)(void*)newref, sizeof(sub_match) * n + sizeof(c_reference)); - throw; - } -#endif - } - else - { - cow(); - // set iterators to be i, matched to false: - sub_match* p1, *p2; - p1 = (sub_match*)(ref+1); - p2 = p1 + ref->cmatches; - while(p1 != p2) - { - p1->first = j; - p1->second = j; - p1->matched = false; - ++p1; - } - } - ref->head.first = i; - ref->tail.second = j; - ref->head.matched = ref->tail.matched = true; - ref->null.first = ref->null.second = j; - ref->null.matched = false; -} - -template -inline void BOOST_REGEX_CALL match_results_base::init_fail(iterator i, iterator j) -{ - set_size(ref->cmatches, i, j); -} - -template -void BOOST_REGEX_CALL match_results_base::maybe_assign(const match_results_base& m) -{ - sub_match* p1, *p2; - p1 = (sub_match*)(ref+1); - p2 = (sub_match*)(m.ref+1); - iterator base = (*this)[-1].first; - std::size_t len1 = 0; - std::size_t len2 = 0; - std::size_t base1 = 0; - std::size_t base2 = 0; - std::size_t i; - for(i = 0; i < ref->cmatches; ++i) - { - // - // leftmost takes priority over longest: - base1 = boost::re_detail::distance(base, p1->first); - base2 = boost::re_detail::distance(base, p2->first); - if(base1 < base2) return; - if(base2 < base1) break; - - len1 = boost::re_detail::distance(p1->first, p1->second); - len2 = boost::re_detail::distance(p2->first, p2->second); - if((len1 != len2) || ((p1->matched == false) && (p2->matched == true))) - break; - if((p1->matched == true) && (p2->matched == false)) - return; - ++p1; - ++p2; - } - if(i == ref->cmatches) - return; - if(base2 < base1) - *this = m; - else if((len2 > len1) || ((p1->matched == false) && (p2->matched == true)) ) - *this = m; -} - -template -void BOOST_REGEX_CALL match_results_base::cow() -{ - if(ref->count > 1) - { - c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match) * ref->cmatches + sizeof(c_reference)); - BOOST_REGEX_NOEH_ASSERT(newref) -#ifndef BOOST_NO_EXCEPTIONS - try{ -#endif - new (newref) c_reference(*ref); - newref->count = 1; - sub_match* p1 = (sub_match*)(newref+1); - sub_match* p2 = p1 + newref->cmatches; - sub_match* p3 = (sub_match*)(ref+1); -#ifndef BOOST_NO_EXCEPTIONS - try{ -#endif - while(p1 != p2) - { - new (p1) sub_match(*p3); - ++p1; - ++p3; - } -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - p2 = (sub_match*)(newref+1); - while(p2 != p1) - { - ::boost::re_detail::pointer_destroy(p2); - ++p2; - } - ::boost::re_detail::pointer_destroy(ref); - throw; - } -#endif - --(ref->count); - ref = newref; -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - ref->deallocate((char*)(void*)newref, sizeof(sub_match) * ref->cmatches + sizeof(c_reference)); - throw; - } -#endif - } -} - -} // namespace re_detail - -// -// class match_results -// encapsulates match_results_base, does a deep copy rather than -// reference counting to ensure thread safety when copying -// other match_results instances - -template -class match_results : public re_detail::match_results_base -{ - typedef re_detail::match_results_base base_type; -public: - - typedef typename base_type::alloc_type alloc_type; - typedef typename base_type::size_type size_type; - typedef typename base_type::char_type char_type; - typedef typename base_type::value_type value_type; - typedef typename base_type::difference_type difference_type; - typedef typename base_type::iterator_type iterator_type; - - explicit match_results(const Allocator& a = Allocator()) - : re_detail::match_results_base(a){} - - match_results(const re_detail::match_results_base& m) - : re_detail::match_results_base(m){} - - match_results& operator=(const re_detail::match_results_base& m) - { - // shallow copy - base_type::operator=(m); - return *this; - } - - match_results(const match_results& m); - match_results& operator=(const match_results& m); - // - // the following function definitions should *not* be required, except - // when this class is used as a template inside another template definition, - // in which members of the base class are not visible to the calling code. - // As a workaround we define simple forwarding functions: - // - size_type size()const - { return static_cast(this)->size(); } - - const sub_match& operator[](int n) const - { return (*static_cast(this))[n]; } - - Allocator allocator()const - { return static_cast(this)->allocator(); } - - difference_type length(int sub = 0)const - { return static_cast(this)->length(sub); } - - difference_type position(unsigned int sub = 0)const - { return static_cast(this)->position(sub); } - - unsigned int line()const - { return static_cast(this)->line(); } - - iterator line_start()const - { return static_cast(this)->line_start(); } - - std::basic_string str(int sub = 0)const - { return static_cast(this)->str(sub); } - - void swap(match_results& that) - { static_cast(this)->swap(that); } - - bool operator==(const match_results& that)const - { return static_cast(*this) == static_cast(that); } - - bool operator<(const match_results& that) const - { return position() < that.position(); } -}; - -template -match_results::match_results(const match_results& m) - : re_detail::match_results_base(false) -{ - this->ref = - reinterpret_cast::c_reference *> - (m.ref->allocate(sizeof(sub_match) * m.ref->cmatches + - sizeof(typename re_detail::match_results_base::c_reference))); - BOOST_REGEX_NOEH_ASSERT(this->ref) -#ifndef BOOST_NO_EXCEPTIONS - try{ -#endif - new (this->ref) typename re_detail::match_results_base::c_reference(*m.ref); - this->ref->count = 1; - sub_match* p1 = (sub_match*)(this->ref+1); - sub_match* p2 = p1 + this->ref->cmatches; - sub_match* p3 = (sub_match*)(m.ref+1); -#ifndef BOOST_NO_EXCEPTIONS - try{ -#endif - while(p1 != p2) - { - new (p1) sub_match(*p3); - ++p1; - ++p3; - } -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - p2 = (sub_match*)(this->ref+1); - while(p2 != p1) - { - re_detail::pointer_destroy(p2); - ++p2; - } - re_detail::pointer_destroy(this->ref); - throw; - } - } - catch(...) - { - m.ref->deallocate((char*)(void*)this->ref, sizeof(sub_match) * m.ref->cmatches + sizeof(typename re_detail::match_results_base::c_reference)); - throw; - } -#endif -} - -template -match_results& match_results::operator=(const match_results& m) -{ - match_results t(m); - this->swap(t); - return *this; -} - -namespace re_detail{ -template -iterator BOOST_REGEX_CALL re_is_set_member(iterator next, - iterator last, - const re_set_long* set_, - const reg_expression& e); -} // namepsace re_detail - -#ifdef __BORLANDC__ - #pragma option pop -#endif - -} // namespace boost - -#include - -// -// template instances: -// -#define BOOST_REGEX_CHAR_T char -#ifdef BOOST_REGEX_NARROW_INSTANTIATE -# define BOOST_REGEX_INSTANTIATE -#endif -#include -#undef BOOST_REGEX_CHAR_T -#ifdef BOOST_REGEX_INSTANTIATE -# undef BOOST_REGEX_INSTANTIATE -#endif - -#ifndef BOOST_NO_WREGEX -#define BOOST_REGEX_CHAR_T wchar_t -#ifdef BOOST_REGEX_WIDE_INSTANTIATE -# define BOOST_REGEX_INSTANTIATE -#endif -#include -#undef BOOST_REGEX_CHAR_T -#ifdef BOOST_REGEX_INSTANTIATE -# undef BOOST_REGEX_INSTANTIATE -#endif -#endif - - -namespace boost{ -#ifdef BOOST_REGEX_NO_FWD -typedef reg_expression, BOOST_DEFAULT_ALLOCATOR(char)> regex; -#ifndef BOOST_NO_WREGEX -typedef reg_expression, BOOST_DEFAULT_ALLOCATOR(wchar_t)> wregex; -#endif -#endif - -typedef match_results cmatch; -typedef match_results smatch; -#ifndef BOOST_NO_WREGEX -typedef match_results wcmatch; -typedef match_results wsmatch; -#endif - -} // namespace boost -#include -#include -#include - - -#endif // __cplusplus +#include #endif // include - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/include/boost/regex/regex_traits.hpp b/include/boost/regex/regex_traits.hpp index bab6b61b..cee79a1e 100644 --- a/include/boost/regex/regex_traits.hpp +++ b/include/boost/regex/regex_traits.hpp @@ -23,787 +23,12 @@ #ifndef BOOST_REGEX_TRAITS_HPP #define BOOST_REGEX_TRAITS_HPP -#include -#include -#include - -namespace boost{ - -#ifdef __BORLANDC__ - #pragma option push -a8 -b -Vx -Ve -pc +#ifndef BOOST_REGEX_TRAITS_HPP_INCLUDED +#include #endif -template -class c_regex_traits; - -namespace re_detail{ - -struct mss -{ - unsigned int id; - const char* what; -}; - -BOOST_REGEX_DECL bool BOOST_REGEX_CALL re_lookup_def_collate_name(std::string& buf, const char* name); -BOOST_REGEX_DECL std::size_t BOOST_REGEX_CALL re_get_default_message(char* buf, std::size_t len, std::size_t id); -extern BOOST_REGEX_DECL const char *re_default_error_messages[]; - -#ifndef BOOST_NO_WREGEX -extern BOOST_REGEX_DECL wchar_t wide_lower_case_map[]; -extern BOOST_REGEX_DECL unsigned short wide_unicode_classes[]; -BOOST_REGEX_DECL bool BOOST_REGEX_CALL is_combining(wchar_t c); -#endif - - -struct BOOST_REGEX_DECL regex_traits_base -{ - enum char_syntax_type - { - syntax_char = 0, - syntax_open_bracket = 1, // ( - syntax_close_bracket = 2, // ) - syntax_dollar = 3, // $ - syntax_caret = 4, // ^ - syntax_dot = 5, // . - syntax_star = 6, // * - syntax_plus = 7, // + - syntax_question = 8, // ? - syntax_open_set = 9, // [ - syntax_close_set = 10, // ] - syntax_or = 11, // | - syntax_slash = 12, // - syntax_hash = 13, // # - syntax_dash = 14, // - - syntax_open_brace = 15, // { - syntax_close_brace = 16, // } - syntax_digit = 17, // 0-9 - syntax_b = 18, // for \b - syntax_B = 19, // for \B - syntax_left_word = 20, // for \< - syntax_right_word = 21, // for \> - syntax_w = 22, // for \w - syntax_W = 23, // for \W - syntax_start_buffer = 24, // for \` - syntax_end_buffer = 25, // for \' - syntax_newline = 26, // for newline alt - syntax_comma = 27, // for {x,y} - - syntax_a = 28, // for \a - syntax_f = 29, // for \f - syntax_n = 30, // for \n - syntax_r = 31, // for \r - syntax_t = 32, // for \t - syntax_v = 33, // for \v - syntax_x = 34, // for \xdd - syntax_c = 35, // for \cx - syntax_colon = 36, // for [:...:] - syntax_equal = 37, // for [=...=] - - // perl ops: - syntax_e = 38, // for \e - syntax_l = 39, // for \l - syntax_L = 40, // for \L - syntax_u = 41, // for \u - syntax_U = 42, // for \U - syntax_s = 43, // for \s - syntax_S = 44, // for \S - syntax_d = 45, // for \d - syntax_D = 46, // for \D - syntax_E = 47, // for \Q\E - syntax_Q = 48, // for \Q\E - syntax_X = 49, // for \X - syntax_C = 50, // for \C - syntax_Z = 51, // for \Z - syntax_G = 52, // for \G - - // new extentions: - syntax_not = 53, // for (?!...) - - syntax_max = 54 - }; -#ifdef __BORLANDC__ -private: - char dummy_member; -#endif -}; - -struct BOOST_REGEX_DECL c_traits_base : public regex_traits_base -{ -public: - enum{ - char_class_none = 0, - char_class_alpha = 0x0001, - char_class_cntrl = 0x0002, - char_class_digit = 0x0004, - char_class_lower = 0x0008, - char_class_punct = 0x0010, - char_class_space = 0x0020, - char_class_upper = 0x0040, - char_class_xdigit = 0x0080, - char_class_blank = 0x0100, - char_class_underscore = 0x4000, - char_class_unicode = 0x8000, - - char_class_alnum = char_class_alpha | char_class_digit, - char_class_graph = char_class_alpha | char_class_digit | char_class_punct | char_class_underscore, - char_class_print = char_class_alpha | char_class_digit | char_class_punct | char_class_underscore | char_class_blank, - char_class_word = char_class_alpha | char_class_digit | char_class_underscore - }; - static std::string BOOST_REGEX_CALL set_message_catalogue(const std::string& s); -protected: -#if defined(__MWERKS__) && __MWERKS__ <= 0x6000 - friend class c_regex_traits; - friend class c_regex_traits; -#endif - - static char regex_message_catalogue[BOOST_REGEX_MAX_PATH]; - enum syntax_map_size - { - map_size = UCHAR_MAX + 1 - }; - - static unsigned char syntax_map[map_size]; - static unsigned short class_map[map_size]; - static char lower_case_map[map_size]; - - static boost::uint_fast32_t BOOST_REGEX_CALL do_lookup_class(const char* p); - static bool BOOST_REGEX_CALL do_lookup_collate(std::string& buf, const char* p); - static void BOOST_REGEX_CALL do_update_ctype(); - static void BOOST_REGEX_CALL do_update_collate(); -public: - static std::string BOOST_REGEX_CALL error_string(unsigned id); - static char* BOOST_REGEX_CALL get_catalogue() { return regex_message_catalogue; } -}; - -} // namespace re_detail - - -template<> -class BOOST_REGEX_DECL c_regex_traits : public re_detail::c_traits_base -{ - typedef re_detail::c_traits_base base_type; -public: - typedef char char_type; - typedef unsigned char uchar_type; - typedef unsigned int size_type; - typedef std::string string_type; - typedef int locale_type; - - static std::size_t BOOST_REGEX_CALL length(const char_type* p) - { - return std::strlen(p); - } - static unsigned int BOOST_REGEX_CALL syntax_type(size_type c) - { - return syntax_map[c]; - } - static char BOOST_REGEX_CALL translate(char c, bool icase) - { - return icase ? lower_case_map[(size_type)(uchar_type)c] : c; - } - static void BOOST_REGEX_CALL transform(std::string& out, const std::string& in); - - static void BOOST_REGEX_CALL transform_primary(std::string& out, const std::string& in); - - static bool BOOST_REGEX_CALL is_separator(char c) - { - return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r')); - } - - static bool BOOST_REGEX_CALL is_combining(char) - { - return false; - } - - static bool BOOST_REGEX_CALL is_class(char c, boost::uint_fast32_t f) - { - return BOOST_REGEX_MAKE_BOOL(class_map[(size_type)(uchar_type)c] & f); - } - - static int BOOST_REGEX_CALL toi(char c); - static int BOOST_REGEX_CALL toi(const char*& first, const char* last, int radix); - - static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const char* first, const char* last) - { - std::string s(first, last); - return do_lookup_class(s.c_str()); - } - - static bool BOOST_REGEX_CALL lookup_collatename(std::string& buf, const char* first, const char* last) - { - std::string s(first, last); - return do_lookup_collate(buf, s.c_str()); - } - - static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; } - locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); } - - c_regex_traits() - { - init(); - } - ~c_regex_traits() - { - m_free(); - } - struct sentry - { - sentry(const c_regex_traits&) - { c_regex_traits::update(); } - operator void*() { return this; } - }; - static void BOOST_REGEX_CALL update(); -private: - static void BOOST_REGEX_CALL init(); - static void BOOST_REGEX_CALL m_free(); - static c_regex_traits i; - - static unsigned sort_type; - static char sort_delim; -}; - -#ifndef BOOST_NO_WREGEX -template<> -class BOOST_REGEX_DECL c_regex_traits : public re_detail::c_traits_base -{ - typedef re_detail::c_traits_base base_type; -public: - typedef wchar_t char_type; - typedef unsigned short uchar_type; - typedef unsigned int size_type; - typedef std::basic_string string_type; - typedef int locale_type; - static std::size_t BOOST_REGEX_CALL length(const char_type* p) - { - return std::wcslen(p); - } - static unsigned int BOOST_REGEX_CALL syntax_type(size_type c); - static wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool icase) - { - return icase ? ((c < 256) ? re_detail::wide_lower_case_map[(uchar_type)c] : std::towlower(c)) : c; - } - - static void BOOST_REGEX_CALL transform(std::basic_string& out, const std::basic_string& in); - - static void BOOST_REGEX_CALL transform_primary(std::basic_string& out, const std::basic_string& in); - - static bool BOOST_REGEX_CALL is_separator(wchar_t c) - { - return BOOST_REGEX_MAKE_BOOL((c == L'\n') || (c == L'\r') || (c == (wchar_t)0x2028) || (c == (wchar_t)0x2029)); - } - - static bool BOOST_REGEX_CALL is_combining(wchar_t c) - { return re_detail::is_combining(c); } - - static bool BOOST_REGEX_CALL is_class(wchar_t c, boost::uint_fast32_t f) - { - return BOOST_REGEX_MAKE_BOOL(((uchar_type)c < 256) ? (re_detail::wide_unicode_classes[(size_type)(uchar_type)c] & f) : do_iswclass(c, f)); - } - - static int BOOST_REGEX_CALL toi(wchar_t c); - static int BOOST_REGEX_CALL toi(const wchar_t*& first, const wchar_t* last, int radix); - - static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last); - - static bool BOOST_REGEX_CALL lookup_collatename(std::basic_string& s, const wchar_t* first, const wchar_t* last); - - static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; } - locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); } - c_regex_traits() - { init(); } - ~c_regex_traits() - { m_free(); } - struct sentry - { - sentry(const c_regex_traits&) - { c_regex_traits::update(); } - operator void*() { return this; } - }; - static void BOOST_REGEX_CALL update(); - static std::size_t BOOST_REGEX_CALL strnarrow(char *s1, std::size_t len, const wchar_t *s2); - static std::size_t BOOST_REGEX_CALL strwiden(wchar_t *s1, std::size_t len, const char *s2); -private: - static bool BOOST_REGEX_CALL do_iswclass(wchar_t c, boost::uint_fast32_t f); - static void BOOST_REGEX_CALL m_free(); - static void BOOST_REGEX_CALL init(); - static bool BOOST_REGEX_CALL do_lookup_collate(std::basic_string& out, const wchar_t* first, const wchar_t* last); - static c_regex_traits init_; - - static unsigned sort_type; - static wchar_t sort_delim; -}; -#endif - -#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32) - -namespace re_detail{ - -struct BOOST_REGEX_DECL w32_traits_base : public regex_traits_base -{ - enum{ - char_class_none = 0, - char_class_alnum = C1_ALPHA | C1_DIGIT, - char_class_alpha = C1_ALPHA, - char_class_cntrl = C1_CNTRL, - char_class_digit = C1_DIGIT, - char_class_graph = C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA, - char_class_lower = C1_LOWER, - char_class_print = C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_BLANK | C1_ALPHA, - char_class_punct = C1_PUNCT, - char_class_space = C1_SPACE, - char_class_upper = C1_UPPER, - char_class_xdigit = C1_XDIGIT, - char_class_blank = C1_BLANK, - char_class_underscore = 0x4000, - char_class_word = C1_ALPHA | C1_DIGIT | char_class_underscore, - char_class_unicode = 0x8000, - char_class_win = 0x01FF - }; - - -public: - static std::string BOOST_REGEX_CALL set_message_catalogue(const std::string& s); -protected: - static char regex_message_catalogue[BOOST_REGEX_MAX_PATH]; - enum syntax_map_size - { - map_size = UCHAR_MAX + 1 - }; - - static unsigned char syntax_map[map_size]; - static unsigned short class_map[map_size]; - static char lower_case_map[map_size]; - - static boost::uint_fast32_t BOOST_REGEX_CALL do_lookup_class(const char* p); - static bool BOOST_REGEX_CALL do_lookup_collate(std::string& buf, const char* p); - static void BOOST_REGEX_CALL do_free(); - static void BOOST_REGEX_CALL do_init(); -public: - static std::string BOOST_REGEX_CALL error_string(unsigned id); - static char* BOOST_REGEX_CALL get_catalogue() { return regex_message_catalogue; } -}; - - -} // namespace re_detail - -template -class w32_regex_traits; - -template<> -class BOOST_REGEX_DECL w32_regex_traits : public re_detail::w32_traits_base -{ - typedef re_detail::w32_traits_base base_type; -public: - typedef char char_type; - typedef unsigned char uchar_type; - typedef unsigned int size_type; - typedef std::string string_type; - typedef int locale_type; - - static std::size_t BOOST_REGEX_CALL length(const char_type* p) - { - return std::strlen(p); - } - static unsigned int BOOST_REGEX_CALL syntax_type(size_type c) - { - return syntax_map[c]; - } - static char BOOST_REGEX_CALL translate(char c, bool icase) - { - return icase ? lower_case_map[(size_type)(uchar_type)c] : c; - } - static void BOOST_REGEX_CALL transform(std::string& out, const std::string& in); - - static void BOOST_REGEX_CALL transform_primary(std::string& out, const std::string& in); - - static bool BOOST_REGEX_CALL is_separator(char c) - { - return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r')); - } - - static bool BOOST_REGEX_CALL is_combining(char) - { - return false; - } - - static bool BOOST_REGEX_CALL is_class(char c, boost::uint_fast32_t f) - { - return BOOST_REGEX_MAKE_BOOL(class_map[(size_type)(uchar_type)c] & f); - } - - static int BOOST_REGEX_CALL toi(char c); - static int BOOST_REGEX_CALL toi(const char*& first, const char* last, int radix); - - static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const char* first, const char* last) - { - std::string s(first, last); - return do_lookup_class(s.c_str()); - } - - static bool BOOST_REGEX_CALL lookup_collatename(std::string& buf, const char* first, const char* last) - { - std::string s(first, last); - return do_lookup_collate(buf, s.c_str()); - } - - static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; } - locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); } - - struct sentry - { - sentry(const w32_regex_traits&) - { w32_regex_traits::update(); } - ~sentry(){} - operator void*() { return this; } - }; - static void BOOST_REGEX_CALL update(); - w32_regex_traits(); - ~w32_regex_traits(); -private: - static w32_regex_traits i; -}; - -#ifndef BOOST_NO_WREGEX -template<> -class BOOST_REGEX_DECL w32_regex_traits : public re_detail::w32_traits_base -{ - typedef re_detail::w32_traits_base base_type; -public: - typedef wchar_t char_type; - typedef unsigned short uchar_type; - typedef unsigned int size_type; - typedef std::basic_string string_type; - typedef int locale_type; - static std::size_t BOOST_REGEX_CALL length(const char_type* p) - { - return std::wcslen(p); - } - static unsigned int BOOST_REGEX_CALL syntax_type(size_type c); - static wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool icase) - { - return icase ? ((c < 256) ? re_detail::wide_lower_case_map[(uchar_type)c] : wtolower(c)) : c; - } - - static void BOOST_REGEX_CALL transform(std::basic_string& out, const std::basic_string& in); - - static void BOOST_REGEX_CALL transform_primary(std::basic_string& out, const std::basic_string& in); - - static bool BOOST_REGEX_CALL is_separator(wchar_t c) - { - return BOOST_REGEX_MAKE_BOOL((c == L'\n') || (c == L'\r') || (c == (wchar_t)0x2028) || (c == (wchar_t)0x2029)); - } - - static bool BOOST_REGEX_CALL is_combining(wchar_t c) - { return re_detail::is_combining(c); } - - static bool BOOST_REGEX_CALL is_class(wchar_t c, boost::uint_fast32_t f) - { - return BOOST_REGEX_MAKE_BOOL(((uchar_type)c < 256) ? (wide_unicode_classes[(size_type)(uchar_type)c] & f) : do_iswclass(c, f)); - } - - static int BOOST_REGEX_CALL toi(wchar_t c); - static int BOOST_REGEX_CALL toi(const wchar_t*& first, const wchar_t* last, int radix); - - static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last); - - static bool BOOST_REGEX_CALL lookup_collatename(std::basic_string& s, const wchar_t* first, const wchar_t* last); - - static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; } - locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); } - - struct sentry - { - sentry(const w32_regex_traits&) - { w32_regex_traits::update(); } - ~sentry(){} - operator void*() { return this; } - }; - static void BOOST_REGEX_CALL update(); - w32_regex_traits(); - ~w32_regex_traits(); - static std::size_t BOOST_REGEX_CALL strnarrow(char *s1, std::size_t len, const wchar_t *s2); - static std::size_t BOOST_REGEX_CALL strwiden(wchar_t *s1, std::size_t len, const char *s2); - -private: - static bool BOOST_REGEX_CALL do_iswclass(wchar_t c, boost::uint_fast32_t f); - static bool BOOST_REGEX_CALL do_lookup_collate(std::basic_string& out, const wchar_t* first, const wchar_t* last); - static w32_regex_traits init_; - static wchar_t BOOST_REGEX_CALL wtolower(wchar_t c); - static unsigned short wide_unicode_classes[]; -}; -#endif // Wide strings -#endif // Win32 - -#if !defined(BOOST_NO_STD_LOCALE) && !defined(BOOST_NO_STD_WSTREAMBUF) - -} // namspace boost - -#ifdef __BORLANDC__ - #pragma option pop -#endif -#include -#ifdef __BORLANDC__ - #pragma option push -a4 -b -Ve -pc -#endif - -namespace boost{ - -namespace re_detail -{ - -template -struct message_data; - -template <> -struct message_data; - -template <> -struct message_data; - -struct BOOST_REGEX_DECL cpp_regex_traits_base : public regex_traits_base -{ - enum char_class_type - { - char_class_none = 0, - char_class_alnum = std::ctype_base::alnum, - char_class_alpha = std::ctype_base::alpha, - char_class_cntrl = std::ctype_base::cntrl, - char_class_digit = std::ctype_base::digit, - char_class_graph = std::ctype_base::graph, - char_class_lower = std::ctype_base::lower, - char_class_print = std::ctype_base::print, - char_class_punct = std::ctype_base::punct, - char_class_space = std::ctype_base::space, - char_class_upper = std::ctype_base::upper, - char_class_xdigit = std::ctype_base::xdigit, - char_class_blank = 1<<12, - char_class_underscore = 1<<13, - char_class_word = std::ctype_base::alnum | char_class_underscore, - char_class_unicode = 1<<14, - char_class_all_base = char_class_alnum | char_class_alpha | char_class_cntrl - | char_class_digit | char_class_graph | char_class_lower - | char_class_print | char_class_punct | char_class_space - | char_class_upper | char_class_xdigit - }; - - static std::string BOOST_REGEX_CALL set_message_catalogue(const std::string& s); -protected: - static char regex_message_cat[BOOST_REGEX_MAX_PATH]; -}; - -} // namespace re_detail - -template -class cpp_regex_traits; - -template<> -class BOOST_REGEX_DECL cpp_regex_traits : public re_detail::cpp_regex_traits_base -{ - typedef re_detail::cpp_regex_traits_base base_type; -private: - re_detail::message_data* pmd; - const unsigned char* psyntax; - char* lower_map; - const std::ctype* pctype; - const std::collate* pcollate; - std::locale locale_inst; - unsigned sort_type; - char sort_delim; - - cpp_regex_traits(const cpp_regex_traits&); - cpp_regex_traits& operator=(const cpp_regex_traits&); - -public: - typedef char char_type; - typedef unsigned char uchar_type; - typedef unsigned int size_type; - typedef std::string string_type; - typedef std::locale locale_type; - - cpp_regex_traits(); - ~cpp_regex_traits(); - - static std::size_t BOOST_REGEX_CALL length(const char_type* p) - { - return std::strlen(p); - } - unsigned int BOOST_REGEX_CALL syntax_type(size_type c)const - { - return psyntax[c]; - } - char BOOST_REGEX_CALL translate(char c, bool icase)const - { - return icase ? lower_map[(size_type)(uchar_type)c] : c; - } - void BOOST_REGEX_CALL transform(std::string& out, const std::string& in)const - { - out = pcollate->transform(in.c_str(), in.c_str() + in.size()).c_str(); - } - - void BOOST_REGEX_CALL transform_primary(std::string& out, const std::string& in)const; - - static bool BOOST_REGEX_CALL is_separator(char c) - { - return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r')); - } - - static bool BOOST_REGEX_CALL is_combining(char) - { - return false; - } - - bool BOOST_REGEX_CALL is_class(char c, boost::uint_fast32_t f)const - { - if(pctype->is((std::ctype::mask)(f & char_class_all_base), c)) - return true; - if((f & char_class_underscore) && (c == '_')) - return true; - if((f & char_class_blank) && ((c == ' ') || (c == '\t'))) - return true; - return false; - } - - int BOOST_REGEX_CALL toi(char c)const; - int BOOST_REGEX_CALL toi(const char*& first, const char* last, int radix)const; - - boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const char* first, const char* last)const; - bool BOOST_REGEX_CALL lookup_collatename(std::string& s, const char* first, const char* last)const; - - std::string BOOST_REGEX_CALL error_string(unsigned id)const; - locale_type BOOST_REGEX_CALL imbue(locale_type l); - locale_type BOOST_REGEX_CALL getloc()const{ return locale_inst; } - - struct sentry - { - sentry(const cpp_regex_traits&){} - operator void*() { return this; } - }; -}; - -#ifndef BOOST_NO_WREGEX -template<> -class BOOST_REGEX_DECL cpp_regex_traits : public re_detail::cpp_regex_traits_base -{ - typedef re_detail::cpp_regex_traits_base base_type; -public: - typedef wchar_t char_type; - typedef unsigned short uchar_type; - typedef unsigned int size_type; - typedef std::basic_string string_type; - typedef std::locale locale_type; - -private: - re_detail::message_data* pmd; - const unsigned char* psyntax; - wchar_t* lower_map; - const std::ctype* pctype; - const std::collate* pcollate; - const std::codecvt* pcdv; - std::locale locale_inst; - unsigned int BOOST_REGEX_CALL do_syntax_type(size_type c)const; - unsigned sort_type; - wchar_t sort_delim; - - cpp_regex_traits(const cpp_regex_traits&); - cpp_regex_traits& operator=(const cpp_regex_traits&); - -public: - - static std::size_t BOOST_REGEX_CALL length(const char_type* p) - { - return std::wcslen(p); - } - unsigned int BOOST_REGEX_CALL syntax_type(size_type c)const - { - return (c < UCHAR_MAX) ? psyntax[c] : do_syntax_type(c); - } - wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool icase)const - { - return icase ? (((uchar_type)c) <= UCHAR_MAX) ? lower_map[c] : pctype->tolower(c) : c; - } - void BOOST_REGEX_CALL transform(std::basic_string& out, const std::basic_string& in)const - { - out = pcollate->transform(in.c_str(), in.c_str() + in.size()); - } - - void BOOST_REGEX_CALL transform_primary(std::basic_string& out, const std::basic_string& in)const; - - static bool BOOST_REGEX_CALL is_separator(wchar_t c) - { - return BOOST_REGEX_MAKE_BOOL((c == L'\n') || (c == L'\r') || (c == (wchar_t)0x2028) || (c == (wchar_t)0x2029)); - } - - static bool BOOST_REGEX_CALL is_combining(wchar_t c) - { return re_detail::is_combining(c); } - - bool BOOST_REGEX_CALL is_class(wchar_t c, boost::uint_fast32_t f)const - { - if(pctype->is((std::ctype::mask)(f & char_class_all_base), c)) - return true; - if((f & char_class_underscore) && (c == '_')) - return true; - if((f & char_class_blank) && ((c == ' ') || (c == '\t'))) - return true; - if((f & char_class_unicode) && ((uchar_type)c > (uchar_type)255)) - return true; - return false; - } - - int BOOST_REGEX_CALL toi(wchar_t c)const; - int BOOST_REGEX_CALL toi(const wchar_t*& first, const wchar_t* last, int radix)const; - - boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last)const; - bool BOOST_REGEX_CALL lookup_collatename(std::basic_string& s, const wchar_t* first, const wchar_t* last)const; - - std::string BOOST_REGEX_CALL error_string(unsigned id)const; - cpp_regex_traits(); - ~cpp_regex_traits(); - locale_type BOOST_REGEX_CALL imbue(locale_type l); - locale_type BOOST_REGEX_CALL getloc()const{ return locale_inst; } - std::size_t BOOST_REGEX_CALL strwiden(wchar_t *s1, std::size_t len, const char *s2)const; - - struct sentry - { - sentry(const cpp_regex_traits&){} - operator void*() { return this; } - }; -}; -#endif // BOOST_NO_WREGEX - -#endif // BOOST_NO_STD_LOCALE - -#ifdef BOOST_REGEX_USE_WIN32_LOCALE - -template -class regex_traits : public w32_regex_traits -{ -}; - -#elif defined(BOOST_REGEX_USE_C_LOCALE) - -template -class regex_traits : public c_regex_traits -{ -}; - -#elif defined(BOOST_REGEX_USE_CPP_LOCALE) - -template -class regex_traits : public cpp_regex_traits -{ -}; - -#else -#error No default localisation model defined -#endif - -#ifdef __BORLANDC__ - #pragma option pop -#endif - -} // namespace boost - #endif // include + diff --git a/include/boost/regex/v3/cregex.hpp b/include/boost/regex/v3/cregex.hpp new file mode 100644 index 00000000..2112abf8 --- /dev/null +++ b/include/boost/regex/v3/cregex.hpp @@ -0,0 +1,316 @@ +/* + * + * Copyright (c) 1998-2002 + * Dr John Maddock + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Dr John Maddock makes no representations + * about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + */ + + /* + * LOCATION: see http://www.boost.org for most recent version. + * FILE cregex.cpp + * VERSION see + * DESCRIPTION: Declares POSIX API functions + * + boost::RegEx high level wrapper. + */ + +#ifndef BOOST_RE_CREGEX_HPP_INCLUDED +#define BOOST_RE_CREGEX_HPP_INCLUDED + +#ifndef BOOST_REGEX_CONFIG_HPP +#include +#endif + +#ifdef __BORLANDC__ + #pragma option push -a8 -b -Vx -Ve -pc +#endif + +/* include these defs only for POSIX compatablity */ +#ifdef __cplusplus +namespace boost{ +extern "C" { +#endif + +#if defined(__cplusplus) && !defined(BOOST_NO_STDC_NAMESPACE) +typedef std::ptrdiff_t regoff_t; +typedef std::size_t regsize_t; +#else +typedef ptrdiff_t regoff_t; +typedef size_t regsize_t; +#endif + +typedef struct +{ + unsigned int re_magic; + unsigned int re_nsub; /* number of parenthesized subexpressions */ + const char* re_endp; /* end pointer for REG_PEND */ + void* guts; /* none of your business :-) */ + unsigned int eflags; /* none of your business :-) */ +} regex_tA; + +#ifndef BOOST_NO_WREGEX +typedef struct +{ + unsigned int re_magic; + unsigned int re_nsub; /* number of parenthesized subexpressions */ + const wchar_t* re_endp; /* end pointer for REG_PEND */ + void* guts; /* none of your business :-) */ + unsigned int eflags; /* none of your business :-) */ +} regex_tW; +#endif + +typedef struct +{ + regoff_t rm_so; /* start of match */ + regoff_t rm_eo; /* end of match */ +} regmatch_t; + +/* regcomp() flags */ +typedef enum{ + REG_BASIC = 0000, + REG_EXTENDED = 0001, + REG_ICASE = 0002, + REG_NOSUB = 0004, + REG_NEWLINE = 0010, + REG_NOSPEC = 0020, + REG_PEND = 0040, + REG_DUMP = 0200, + REG_NOCOLLATE = 0400, + REG_ESCAPE_IN_LISTS = 01000, + REG_NEWLINE_ALT = 02000, + + REG_PERL = REG_EXTENDED | REG_NOCOLLATE | REG_ESCAPE_IN_LISTS, + REG_AWK = REG_EXTENDED | REG_ESCAPE_IN_LISTS, + REG_GREP = REG_BASIC | REG_NEWLINE_ALT, + REG_EGREP = REG_EXTENDED | REG_NEWLINE_ALT, + + REG_ASSERT = 15, + REG_INVARG = 16, + REG_ATOI = 255, /* convert name to number (!) */ + REG_ITOA = 0400 /* convert number to name (!) */ +} reg_comp_flags; + +/* regexec() flags */ +typedef enum{ + REG_NOTBOL = 00001, + REG_NOTEOL = 00002, + REG_STARTEND = 00004 +} reg_exec_flags; + +BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA*, const char*, int); +BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int, const regex_tA*, char*, regsize_t); +BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecA(const regex_tA*, const char*, regsize_t, regmatch_t*, int); +BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeA(regex_tA*); + +#ifndef BOOST_NO_WREGEX +BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW*, const wchar_t*, int); +BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int, const regex_tW*, wchar_t*, regsize_t); +BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecW(const regex_tW*, const wchar_t*, regsize_t, regmatch_t*, int); +BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeW(regex_tW*); +#endif + +#ifdef UNICODE +#define regcomp regcompW +#define regerror regerrorW +#define regexec regexecW +#define regfree regfreeW +#define regex_t regex_tW +#else +#define regcomp regcompA +#define regerror regerrorA +#define regexec regexecA +#define regfree regfreeA +#define regex_t regex_tA +#endif + +/* regerror() flags */ +typedef enum +{ + REG_NOERROR = 0, /* Success. */ + REG_NOMATCH = 1, /* Didn't find a match (for regexec). */ + + /* POSIX regcomp return error codes. (In the order listed in the + standard.) */ + REG_BADPAT = 2, /* Invalid pattern. */ + REG_ECOLLATE = 3, /* Undefined collating element. */ + REG_ECTYPE = 4, /* Invalid character class name. */ + REG_EESCAPE = 5, /* Trailing backslash. */ + REG_ESUBREG = 6, /* Invalid back reference. */ + REG_EBRACK = 7, /* Unmatched left bracket. */ + REG_EPAREN = 8, /* Parenthesis imbalance. */ + REG_EBRACE = 9, /* Unmatched \{. */ + REG_BADBR = 10, /* Invalid contents of \{\}. */ + REG_ERANGE = 11, /* Invalid range end. */ + REG_ESPACE = 12, /* Ran out of memory. */ + REG_BADRPT = 13, /* No preceding re for repetition op. */ + REG_EEND = 14, /* unexpected end of expression */ + REG_ESIZE = 15, /* expression too big */ + REG_ERPAREN = 16, /* unmatched right parenthesis */ + REG_EMPTY = 17, /* empty expression */ + REG_E_MEMORY = REG_ESIZE, /* out of memory */ + REG_E_UNKNOWN = 18 /* unknown error */ +} reg_errcode_t; + +enum match_flags +{ + match_default = 0, + match_not_bol = 1, // first is not start of line + match_not_eol = match_not_bol << 1, // last is not end of line + match_not_bob = match_not_eol << 1, // first is not start of buffer + match_not_eob = match_not_bob << 1, // last is not end of buffer + match_not_bow = match_not_eob << 1, // first is not start of word + match_not_eow = match_not_bow << 1, // last is not end of word + match_not_dot_newline = match_not_eow << 1, // \n is not matched by '.' + match_not_dot_null = match_not_dot_newline << 1, // '\0' is not matched by '.' + match_prev_avail = match_not_dot_null << 1, // *--first is a valid expression + match_init = match_prev_avail << 1, // internal use + match_any = match_init << 1, // don't care what we match + match_not_null = match_any << 1, // string can't be null + match_continuous = match_not_null << 1, // each grep match must continue from + // uninterupted from the previous one + match_partial = match_continuous << 1, // find partial matches + + match_stop = match_partial << 1, // stop after first match (grep) + match_all = match_stop << 1, // must find the whole of input even if match_any is set + match_max = match_all +}; + + +#ifdef __cplusplus +} // extern "C" +} // namespace +#endif + + +#ifdef __BORLANDC__ + #if __BORLANDC__ > 0x520 + #pragma option pop + #endif +#endif + + +// +// C++ high level wrapper goes here: +// +#if defined(__cplusplus) +#include +#include +namespace boost{ + +#ifdef __BORLANDC__ + #if __BORLANDC__ == 0x530 + #pragma option push -a4 -b + #elif __BORLANDC__ > 0x530 + #pragma option push -a8 -b + #endif +#endif + +class RegEx; + +namespace re_detail{ + +class RegExData; +struct pred1; +struct pred2; +struct pred3; +struct pred4; + +} // namespace re_detail + +#if defined(BOOST_MSVC) || defined(__BORLANDC__) +typedef bool (__cdecl *GrepCallback)(const RegEx& expression); +typedef bool (__cdecl *GrepFileCallback)(const char* file, const RegEx& expression); +typedef bool (__cdecl *FindFilesCallback)(const char* file); +#else +typedef bool (*GrepCallback)(const RegEx& expression); +typedef bool (*GrepFileCallback)(const char* file, const RegEx& expression); +typedef bool (*FindFilesCallback)(const char* file); +#endif + +class BOOST_REGEX_DECL RegEx +{ +private: + re_detail::RegExData* pdata; +public: + RegEx(); + RegEx(const RegEx& o); + ~RegEx(); + explicit RegEx(const char* c, bool icase = false); + explicit RegEx(const std::string& s, bool icase = false); + RegEx& operator=(const RegEx& o); + RegEx& operator=(const char* p); + RegEx& operator=(const std::string& s){ return this->operator=(s.c_str()); } + unsigned int SetExpression(const char* p, bool icase = false); + unsigned int SetExpression(const std::string& s, bool icase = false){ return SetExpression(s.c_str(), icase); } + std::string Expression()const; + unsigned int error_code()const; + // + // now matching operators: + // + bool Match(const char* p, unsigned int flags = match_default); + bool Match(const std::string& s, unsigned int flags = match_default) { return Match(s.c_str(), flags); } + bool Search(const char* p, unsigned int flags = match_default); + bool Search(const std::string& s, unsigned int flags = match_default) { return Search(s.c_str(), flags); } + unsigned int Grep(GrepCallback cb, const char* p, unsigned int flags = match_default); + unsigned int Grep(GrepCallback cb, const std::string& s, unsigned int flags = match_default) { return Grep(cb, s.c_str(), flags); } + unsigned int Grep(std::vector& v, const char* p, unsigned int flags = match_default); + unsigned int Grep(std::vector& v, const std::string& s, unsigned int flags = match_default) { return Grep(v, s.c_str(), flags); } + unsigned int Grep(std::vector& v, const char* p, unsigned int flags = match_default); + unsigned int Grep(std::vector& v, const std::string& s, unsigned int flags = match_default) { return Grep(v, s.c_str(), flags); } +#ifndef BOOST_REGEX_NO_FILEITER + unsigned int GrepFiles(GrepFileCallback cb, const char* files, bool recurse = false, unsigned int flags = match_default); + unsigned int GrepFiles(GrepFileCallback cb, const std::string& files, bool recurse = false, unsigned int flags = match_default) { return GrepFiles(cb, files.c_str(), recurse, flags); } + unsigned int FindFiles(FindFilesCallback cb, const char* files, bool recurse = false, unsigned int flags = match_default); + unsigned int FindFiles(FindFilesCallback cb, const std::string& files, bool recurse = false, unsigned int flags = match_default) { return FindFiles(cb, files.c_str(), recurse, flags); } +#endif + + std::string Merge(const std::string& in, const std::string& fmt, + bool copy = true, unsigned int flags = match_default); + std::string Merge(const char* in, const char* fmt, + bool copy = true, unsigned int flags = match_default); + + std::size_t Split(std::vector& v, std::string& s, unsigned flags = match_default, unsigned max_count = ~0); + // + // now operators for returning what matched in more detail: + // + std::size_t Position(int i = 0)const; + std::size_t Length(int i = 0)const; + bool Matched(int i = 0)const; + unsigned int Line()const; + unsigned int Marks()const; + std::string What(int i = 0)const; + std::string operator[](int i)const { return What(i); } + + static const unsigned int npos; + + friend struct re_detail::pred1; + friend struct re_detail::pred2; + friend struct re_detail::pred3; + friend struct re_detail::pred4; +}; + +#ifdef __BORLANDC__ + #pragma option pop +#endif + +} // namespace boost + +#endif + +#endif // include guard + + + + + + + + + diff --git a/include/boost/regex/detail/fileiter.hpp b/include/boost/regex/v3/fileiter.hpp similarity index 98% rename from include/boost/regex/detail/fileiter.hpp rename to include/boost/regex/v3/fileiter.hpp index bb909675..eaf18ba2 100644 --- a/include/boost/regex/detail/fileiter.hpp +++ b/include/boost/regex/v3/fileiter.hpp @@ -22,10 +22,12 @@ * the form of class map_file. */ -#ifndef BOOST_RE_FILEITER_HPP -#define BOOST_RE_FILEITER_HPP +#ifndef BOOST_RE_FILEITER_HPP_INCLUDED +#define BOOST_RE_FILEITER_HPP_INCLUDED +#ifndef BOOST_REGEX_CONFIG_HPP #include +#endif #ifndef BOOST_REGEX_NO_FILEITER @@ -451,3 +453,4 @@ using boost::re_detail::mapfile; + diff --git a/include/boost/regex/detail/instances.hpp b/include/boost/regex/v3/instances.hpp similarity index 99% rename from include/boost/regex/detail/instances.hpp rename to include/boost/regex/v3/instances.hpp index a99a2977..aa283a16 100644 --- a/include/boost/regex/detail/instances.hpp +++ b/include/boost/regex/v3/instances.hpp @@ -21,6 +21,9 @@ * library rather than in the users object files. */ +// +// note no include guard, we may include this multiple times: +// #ifndef BOOST_REGEX_NO_EXTERNAL_TEMPLATES namespace boost{ @@ -162,3 +165,4 @@ template void BOOST_REGEX_CALL match_results_base::cow(); #endif // BOOST_REGEX_NO_EXTERNAL_TEMPLATES + diff --git a/include/boost/regex/v3/regex.hpp b/include/boost/regex/v3/regex.hpp new file mode 100644 index 00000000..db7f8609 --- /dev/null +++ b/include/boost/regex/v3/regex.hpp @@ -0,0 +1,1636 @@ +/* + * + * Copyright (c) 1998-2002 + * Dr John Maddock + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Dr John Maddock makes no representations + * about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + */ + + /* + * LOCATION: see http://www.boost.org for most recent version. + * FILE regex.cpp + * VERSION see + * DESCRIPTION: Declares boost::reg_expression<> and associated + * functions and classes. This header is the main + * entry point for the template regex code. + */ + + +/* start with C compatibility API */ + +#ifndef BOOST_RE_REGEX_HPP_INCLUDED +#define BOOST_RE_REGEX_HPP_INCLUDED + +#ifndef BOOST_RE_CREGEX_HPP +#include +#endif + +#ifdef __cplusplus + +// what follows is all C++ don't include in C builds!! + +#ifdef BOOST_REGEX_DEBUG +# include +#endif + +#include +#include +#ifndef BOOST_REGEX_CONFIG_HPP +#include +#endif +#ifndef BOOST_REGEX_FWD_HPP +#include +#endif +#ifndef BOOST_REGEX_STACK_HPP +#include +#endif +#ifndef BOOST_REGEX_RAW_BUFFER_HPP +#include +#endif +#ifndef BOOST_REGEX_KMP_HPP +#include +#endif +#ifndef BOOST_RE_PAT_EXCEPT_HPP +#include +#endif +#ifndef BOOST_REGEX_TRAITS_HPP +#include +#endif +#include +#include + + +namespace boost{ + +#ifdef __BORLANDC__ + #pragma option push -a8 -b -Vx -Ve -pc -w-8027 +#endif + +namespace re_detail{ + +struct re_set_long; +struct re_syntax_base; + +} // namespace re_detail + +namespace deprecated{ +// +// class char_regex_traits_i +// provides case insensitive traits classes (deprecated): +template +class char_regex_traits_i : public regex_traits {}; + +template<> +class char_regex_traits_i : public regex_traits +{ +public: + typedef char char_type; + typedef unsigned char uchar_type; + typedef unsigned int size_type; + typedef regex_traits base_type; + + char BOOST_REGEX_CALL translate(char c, bool)const + { + return static_cast*>(this)->translate(c, true); + } +}; + +#ifndef BOOST_NO_WREGEX +template<> +class char_regex_traits_i : public regex_traits +{ +public: + typedef wchar_t char_type; + typedef unsigned short uchar_type; + typedef unsigned int size_type; + typedef regex_traits base_type; + + wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool)const + { + return static_cast*>(this)->translate(c, true); + } + boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last)const + { + boost::uint_fast32_t result = static_cast*>(this)->lookup_classname(first, last); + if((result & base_type::char_class_upper) == base_type::char_class_upper) + result |= base_type::char_class_alpha; + return result; + } +}; +#endif +} // namespace deprecated + + +namespace re_detail{ + +enum mask_type +{ + mask_take = 1, + mask_skip = 2, + mask_any = mask_skip | mask_take, + mask_all = mask_any +}; + +struct _narrow_type{}; +struct _wide_type{}; + +template +class is_byte; + +template<> +class is_byte +{ +public: + typedef _narrow_type width_type; +}; + +template<> +class is_byte +{ +public: + typedef _narrow_type width_type; +}; + +template<> +class is_byte +{ +public: + typedef _narrow_type width_type; +}; + +template +class is_byte +{ +public: + typedef _wide_type width_type; +}; + + +// +// compiled structures +// +// the following defs describe the format of the compiled string +// + +// +// enum syntax_element_type +// describes the type of a record +enum syntax_element_type +{ + syntax_element_startmark = 0, + syntax_element_endmark = syntax_element_startmark + 1, + syntax_element_literal = syntax_element_endmark + 1, + syntax_element_start_line = syntax_element_literal + 1, + syntax_element_end_line = syntax_element_start_line + 1, + syntax_element_wild = syntax_element_end_line + 1, + syntax_element_match = syntax_element_wild + 1, + syntax_element_word_boundary = syntax_element_match + 1, + syntax_element_within_word = syntax_element_word_boundary + 1, + syntax_element_word_start = syntax_element_within_word + 1, + syntax_element_word_end = syntax_element_word_start + 1, + syntax_element_buffer_start = syntax_element_word_end + 1, + syntax_element_buffer_end = syntax_element_buffer_start + 1, + syntax_element_backref = syntax_element_buffer_end + 1, + syntax_element_long_set = syntax_element_backref + 1, + syntax_element_set = syntax_element_long_set + 1, + syntax_element_jump = syntax_element_set + 1, + syntax_element_alt = syntax_element_jump + 1, + syntax_element_rep = syntax_element_alt + 1, + syntax_element_combining = syntax_element_rep + 1, + syntax_element_soft_buffer_end = syntax_element_combining + 1, + syntax_element_restart_continue = syntax_element_soft_buffer_end + 1 +}; + +#ifdef BOOST_REGEX_DEBUG +// dwa 09/26/00 - This is needed to suppress warnings about an ambiguous conversion +std::ostream& operator<<(std::ostream&, syntax_element_type); +#endif + +union offset_type +{ + re_syntax_base* p; + std::size_t i; +}; + +// +// struct re_syntax_base +// base class for all syntax types: +struct re_syntax_base +{ + syntax_element_type type; + offset_type next; + unsigned int can_be_null; +}; + +// +// struct re_brace +// marks start or end of (...) +struct re_brace : public re_syntax_base +{ + int index; +}; + +// +// struct re_literal +// marks a literal string and +// is followed by an array of charT[length]: +struct re_literal : public re_syntax_base +{ + unsigned int length; +}; + +// +// struct re_long_set +// provides data for sets [...] containing +// wide characters +struct re_set_long : public re_syntax_base +{ + unsigned int csingles, cranges, cequivalents; + boost::uint_fast32_t cclasses; + bool isnot; +}; + +// +// struct re_set +// provides a map of bools for sets containing +// narrow, single byte characters. +struct re_set : public re_syntax_base +{ + unsigned char _map[256]; +}; + +// +// struct re_jump +// provides alternative next destination +struct re_jump : public re_syntax_base +{ + offset_type alt; + unsigned char _map[256]; +}; + +// +// struct re_repeat +// provides repeat expressions +struct re_repeat : public re_jump +{ + unsigned min, max; + int id; + bool leading; + bool greedy; + bool singleton; +}; + + +// +// enum re_jump_size_type +// provides compiled size of re_jump +// allowing for trailing alignment +// provide this so we know how many +// bytes to insert +enum re_jump_size_type +{ + re_jump_size = (sizeof(re_jump) + padding_mask) & ~(padding_mask), + re_repeater_size = (sizeof(re_repeat) + padding_mask) & ~(padding_mask) +}; + +} // namespace re_detail + +// +// class basic_regex +// handles error codes and flags + +class BOOST_REGEX_DECL regbase +{ +public: + enum flag_type_ + { + escape_in_lists = 1, // '\' special inside [...] + char_classes = escape_in_lists << 1, // [[:CLASS:]] allowed + intervals = char_classes << 1, // {x,y} allowed + limited_ops = intervals << 1, // all of + ? and | are normal characters + newline_alt = limited_ops << 1, // \n is the same as | + bk_plus_qm = newline_alt << 1, // uses \+ and \? + bk_braces = bk_plus_qm << 1, // uses \{ and \} + bk_parens = bk_braces << 1, // uses \( and \) + bk_refs = bk_parens << 1, // \d allowed + bk_vbar = bk_refs << 1, // uses \| + + use_except = bk_vbar << 1, // exception on error + failbit = use_except << 1, // error flag + literal = failbit << 1, // all characters are literals + icase = literal << 1, // characters are matched regardless of case + nocollate = icase << 1, // don't use locale specific collation + + basic = char_classes | intervals | limited_ops | bk_braces | bk_parens | bk_refs, + extended = char_classes | intervals | bk_refs, + normal = escape_in_lists | char_classes | intervals | bk_refs | nocollate, + emacs = bk_braces | bk_parens | bk_refs | bk_vbar, + awk = extended | escape_in_lists, + grep = basic | newline_alt, + egrep = extended | newline_alt, + sed = basic, + perl = normal + }; + typedef unsigned int flag_type; + + enum restart_info + { + restart_any = 0, + restart_word = 1, + restart_line = 2, + restart_buf = 3, + restart_continue = 4, + restart_lit = 5, + restart_fixed_lit = 6 + }; + + flag_type BOOST_REGEX_CALL flags()const + { + return _flags; + } + + regbase(); + regbase(const regbase& b); +protected: + flag_type _flags; +}; + +// +// some forward declarations: +namespace re_detail{ +template +class _priv_match_data; + +#if defined(BOOST_NO_STD_ITERATOR_TRAITS) || defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) + +template +struct regex_iterator_traits +{ + typedef typename T::iterator_category iterator_category; + typedef typename T::value_type value_type; +#if !defined(BOOST_NO_STD_ITERATOR) + typedef typename T::difference_type difference_type; + typedef typename T::pointer pointer; + typedef typename T::reference reference; +#else + typedef std::ptrdiff_t difference_type; + typedef value_type* pointer; + typedef value_type& reference; +#endif +}; + +template +struct pointer_iterator_traits +{ + typedef std::ptrdiff_t difference_type; + typedef T value_type; + typedef T* pointer; + typedef T& reference; + typedef std::random_access_iterator_tag iterator_category; +}; +template +struct const_pointer_iterator_traits +{ + typedef std::ptrdiff_t difference_type; + typedef T value_type; + typedef const T* pointer; + typedef const T& reference; + typedef std::random_access_iterator_tag iterator_category; +}; + +template<> +struct regex_iterator_traits : pointer_iterator_traits{}; +template<> +struct regex_iterator_traits : const_pointer_iterator_traits{}; +template<> +struct regex_iterator_traits : pointer_iterator_traits{}; +template<> +struct regex_iterator_traits : const_pointer_iterator_traits{}; + +#if defined(__SGI_STL_PORT) && defined(__STL_DEBUG) +template<> +struct regex_iterator_traits : pointer_iterator_traits{}; +template<> +struct regex_iterator_traits : const_pointer_iterator_traits{}; +#ifndef BOOST_NO_STD_WSTRING +template<> +struct regex_iterator_traits : pointer_iterator_traits{}; +template<> +struct regex_iterator_traits : const_pointer_iterator_traits{}; +#endif // BOOST_NO_WSTRING +#endif // stport + +#else + +template +struct regex_iterator_traits : public std::iterator_traits {}; + +#endif + +template +struct def_alloc_param_traits +{ + typedef typename regex_iterator_traits::value_type const_value_type; + typedef typename remove_cv::type type; +}; +template <> +struct def_alloc_param_traits +{ + typedef char type; +}; +template <> +struct def_alloc_param_traits +{ + typedef wchar_t type; +}; + +} + +template ::type) > +#else +BOOST_DEFAULT_ALLOCATOR(re_detail::def_alloc_param_traits::type) > +#endif +class match_results; + +// +// class reg_expression +// represents the compiled +// regular expression: +// + +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable : 4251 4231 4660) +#endif + +#ifdef BOOST_REGEX_NO_FWD +template , class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) > +#else +template +#endif +class reg_expression : public regbase +{ +public: + typedef typename traits::size_type traits_size_type; + typedef typename traits::uchar_type traits_uchar_type; + typedef typename traits::string_type traits_string_type; + // typedefs: + typedef charT char_type; + typedef traits traits_type; + + // locale_type + // placeholder for actual locale type used by the + // traits class to localise *this. + typedef typename traits::locale_type locale_type; + // value_type + typedef charT value_type; + // reference, const_reference + typedef charT& reference; + typedef const charT& const_reference; + // iterator, const_iterator + typedef const charT* const_iterator; + typedef const_iterator iterator; + // difference_type + typedef typename Allocator::difference_type difference_type; + // size_type + typedef typename Allocator::size_type size_type; + // allocator_type + typedef Allocator allocator_type; + typedef Allocator alloc_type; + // flag_type + typedef regbase::flag_type flag_type; + +public: + explicit reg_expression(const Allocator& a = Allocator()); + explicit reg_expression(const charT* p, flag_type f = regbase::normal, const Allocator& a = Allocator()); + reg_expression(const charT* p1, const charT* p2, flag_type f = regbase::normal, const Allocator& a = Allocator()); + reg_expression(const charT* p, size_type len, flag_type f, const Allocator& a = Allocator()); + reg_expression(const reg_expression&); + ~reg_expression(); + reg_expression& BOOST_REGEX_CALL operator=(const reg_expression&); + reg_expression& BOOST_REGEX_CALL operator=(const charT* ptr) + { + set_expression(ptr, regbase::normal | regbase::use_except); + return *this; + } + + // + // assign: + reg_expression& assign(const reg_expression& that) + { return *this = that; } + reg_expression& assign(const charT* ptr, flag_type f = regbase::normal) + { + set_expression(ptr, f | regbase::use_except); + return *this; + } + + reg_expression& assign(const charT* first, + const charT* last, + flag_type f = regbase::normal) + { + set_expression(first, last, f | regbase::use_except); + return *this; + } +#if !defined(BOOST_NO_MEMBER_TEMPLATES) && !(defined(__IBMCPP__) && (__IBMCPP__ <= 502)) + + template + unsigned int BOOST_REGEX_CALL set_expression(const std::basic_string& p, flag_type f = regbase::normal) + { return set_expression(p.data(), p.data() + p.size(), f); } + + template + explicit reg_expression(const std::basic_string& p, flag_type f = regbase::normal, const Allocator& a = Allocator()) + : data(a), pkmp(0), error_code_(REG_EMPTY), _expression(0) { set_expression(p, f | regbase::use_except); } + + template + reg_expression(I first, I last, flag_type f = regbase::normal, const Allocator& al = Allocator()) + : data(al), pkmp(0), error_code_(REG_EMPTY), _expression(0) + { + size_type len = last-first; + scoped_array a(new charT[len]); + std::copy(first, last, a.get()); + set_expression(a.get(), a.get() + len, f | regbase::use_except); + } + + template + reg_expression& BOOST_REGEX_CALL operator=(const std::basic_string& p) + { + set_expression(p.c_str(), p.c_str() + p.size(), regbase::normal | regbase::use_except); + return *this; + } + + template + reg_expression& BOOST_REGEX_CALL assign( + const std::basic_string& s, + flag_type f = regbase::normal) + { + set_expression(s.c_str(), s.c_str() + s.size(), f | regbase::use_except); + return *this; + } + + template + reg_expression& BOOST_REGEX_CALL assign(fwd_iterator first, + fwd_iterator last, + flag_type f = regbase::normal) + { + size_type len = last-first; + scoped_array a(new charT[len]); + std::copy(first, last, a.get()); + set_expression(a.get(), a.get() + len, f | regbase::use_except); + return *this; + } +#else + unsigned int BOOST_REGEX_CALL set_expression(const std::basic_string& p, flag_type f = regbase::normal) + { return set_expression(p.data(), p.data() + p.size(), f | regbase::use_except); } + + reg_expression(const std::basic_string& p, flag_type f = regbase::normal, const Allocator& a = Allocator()) + : data(a), pkmp(0) { set_expression(p, f | regbase::use_except); } + + reg_expression& BOOST_REGEX_CALL operator=(const std::basic_string& p) + { + set_expression(p.c_str(), p.c_str() + p.size(), regbase::normal | regbase::use_except); + return *this; + } + + reg_expression& BOOST_REGEX_CALL assign( + const std::basic_string& s, + flag_type f = regbase::normal) + { + set_expression(s.c_str(), s.c_str() + s.size(), f | regbase::use_except); + return *this; + } + +#endif + + + // + // allocator access: + Allocator BOOST_REGEX_CALL get_allocator()const; + // + // locale: + locale_type BOOST_REGEX_CALL imbue(locale_type l){ return traits_inst.imbue(l); } + locale_type BOOST_REGEX_CALL getloc()const{ return traits_inst.getloc(); } + // + // flags: + flag_type BOOST_REGEX_CALL getflags()const + { return flags(); } + // + // str: + std::basic_string BOOST_REGEX_CALL str()const + { + std::basic_string result; + if(this->error_code() == 0) + result = std::basic_string(_expression, _expression_len); + return result; + } + // + // begin, end: + const_iterator BOOST_REGEX_CALL begin()const + { return (this->error_code() ? 0 : _expression); } + const_iterator BOOST_REGEX_CALL end()const + { return (this->error_code() ? 0 : _expression + _expression_len); } + // + // swap: + void BOOST_REGEX_CALL swap(reg_expression&)throw(); + // + // size: + size_type BOOST_REGEX_CALL size()const + { return (this->error_code() ? 0 : _expression_len); } + // + // max_size: + size_type BOOST_REGEX_CALL max_size()const + { return UINT_MAX; } + // + // empty: + bool BOOST_REGEX_CALL empty()const + { return 0 != this->error_code(); } + + unsigned BOOST_REGEX_CALL mark_count()const { return (this->error_code() ? 0 : marks); } + bool BOOST_REGEX_CALL operator==(const reg_expression&)const; + bool BOOST_REGEX_CALL operator<(const reg_expression&)const; + // + // The following are deprecated as public interfaces + // but are available for compatibility with earlier versions. + allocator_type BOOST_REGEX_CALL allocator()const; + const charT* BOOST_REGEX_CALL expression()const { return (this->error_code() ? 0 : _expression); } + unsigned int BOOST_REGEX_CALL set_expression(const charT* p, const charT* end, flag_type f = regbase::normal); + unsigned int BOOST_REGEX_CALL set_expression(const charT* p, flag_type f = regbase::normal) { return set_expression(p, p + traits_type::length(p), f); } + // + // this should be private but template friends don't work: + const traits_type& get_traits()const { return traits_inst; } + unsigned int BOOST_REGEX_CALL error_code()const + { + return error_code_; + } + +private: + traits_type traits_inst; + re_detail::raw_storage data; + unsigned _restart_type; + unsigned marks; + int repeats; + unsigned char* startmap; + std::size_t _expression_len; + std::size_t _leading_len; + const charT* _leading_string; + std::size_t _leading_string_len; + re_detail::kmp_info* pkmp; + unsigned error_code_; + charT* _expression; + + void BOOST_REGEX_CALL compile_maps(); + void BOOST_REGEX_CALL compile_map(re_detail::re_syntax_base* node, unsigned char* _map, unsigned int* pnull, unsigned char mask, re_detail::re_syntax_base* terminal = 0)const; + bool BOOST_REGEX_CALL probe_start(re_detail::re_syntax_base* node, charT c, re_detail::re_syntax_base* terminal)const; + bool BOOST_REGEX_CALL probe_start_null(re_detail::re_syntax_base* node, re_detail::re_syntax_base* terminal)const; + void BOOST_REGEX_CALL fixup_apply(re_detail::re_syntax_base* b, unsigned cbraces); + void BOOST_REGEX_CALL move_offsets(re_detail::re_syntax_base* j, unsigned size); + re_detail::re_syntax_base* BOOST_REGEX_CALL compile_set(const charT*& first, const charT* last); + re_detail::re_syntax_base* BOOST_REGEX_CALL compile_set_aux(re_detail::jstack& singles, re_detail::jstack& ranges, re_detail::jstack& classes, re_detail::jstack& equivalents, bool isnot, const re_detail::_narrow_type&); + re_detail::re_syntax_base* BOOST_REGEX_CALL compile_set_aux(re_detail::jstack& singles, re_detail::jstack& ranges, re_detail::jstack& classes, re_detail::jstack& equivalents, bool isnot, const re_detail::_wide_type&); + re_detail::re_syntax_base* BOOST_REGEX_CALL compile_set_simple(re_detail::re_syntax_base* dat, unsigned long cls, bool isnot = false); + unsigned int BOOST_REGEX_CALL parse_inner_set(const charT*& first, const charT* last); + + re_detail::re_syntax_base* BOOST_REGEX_CALL add_simple(re_detail::re_syntax_base* dat, re_detail::syntax_element_type type, unsigned int size = sizeof(re_detail::re_syntax_base)); + re_detail::re_syntax_base* BOOST_REGEX_CALL add_literal(re_detail::re_syntax_base* dat, charT c); + charT BOOST_REGEX_CALL parse_escape(const charT*& first, const charT* last); + void BOOST_REGEX_CALL parse_range(const charT*& first, const charT* last, unsigned& min, unsigned& max); + bool BOOST_REGEX_CALL skip_space(const charT*& first, const charT* last); + unsigned int BOOST_REGEX_CALL probe_restart(re_detail::re_syntax_base* dat); + unsigned int BOOST_REGEX_CALL fixup_leading_rep(re_detail::re_syntax_base* dat, re_detail::re_syntax_base* end); + void BOOST_REGEX_CALL fail(unsigned int err); + +protected: + static int BOOST_REGEX_CALL repeat_count(const reg_expression& e) + { return e.repeats; } + static unsigned int BOOST_REGEX_CALL restart_type(const reg_expression& e) + { return e._restart_type; } + static const re_detail::re_syntax_base* BOOST_REGEX_CALL first(const reg_expression& e) + { return (const re_detail::re_syntax_base*)e.data.data(); } + static const unsigned char* BOOST_REGEX_CALL get_map(const reg_expression& e) + { return e.startmap; } + static std::size_t BOOST_REGEX_CALL leading_length(const reg_expression& e) + { return e._leading_len; } + static const re_detail::kmp_info* get_kmp(const reg_expression& e) + { return e.pkmp; } + static bool BOOST_REGEX_CALL can_start(charT c, const unsigned char* _map, unsigned char mask, const re_detail::_wide_type&); + static bool BOOST_REGEX_CALL can_start(charT c, const unsigned char* _map, unsigned char mask, const re_detail::_narrow_type&); +}; + +#ifdef BOOST_MSVC +#pragma warning (pop) +#endif + +template +inline void BOOST_REGEX_CALL reg_expression::swap(reg_expression& that)throw() +{ + // this is not as efficient as it should be, + // however swapping traits classes is problematic + // so just use 'brute force' method for now: + reg_expression e(that); + that = *this; + *this = e; +} + + +// +// class match_results and match_results_base +// handles what matched where + +template +struct sub_match +{ + typedef typename re_detail::regex_iterator_traits::value_type value_type; +#if defined(BOOST_NO_STD_ITERATOR_TRAITS) || defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) + typedef std::ptrdiff_t difference_type; +#else + typedef typename re_detail::regex_iterator_traits::difference_type difference_type; +#endif + typedef iterator iterator_type; + + iterator first; + iterator second; + bool matched; + + operator std::basic_string ()const + { + std::basic_string result; + std::size_t len = boost::re_detail::distance((iterator)first, (iterator)second); + result.reserve(len); + iterator i = first; + while(i != second) + { + result.append(1, *i); + ++i; + } + return result; + } + #ifdef BOOST_OLD_REGEX_H + // + // the following are deprecated, do not use!! + // + operator int()const; + operator unsigned int()const; + operator short()const + { + return (short)(int)(*this); + } + operator unsigned short()const + { + return (unsigned short)(unsigned int)(*this); + } + #endif + sub_match() { matched = false; } + sub_match(iterator i) : first(i), second(i), matched(false) {} + + bool operator==(const sub_match& that)const + { + return (first == that.first) && (second == that.second) && (matched == that.matched); + } + bool BOOST_REGEX_CALL operator !=(const sub_match& that)const + { return !(*this == that); } + + difference_type BOOST_REGEX_CALL length()const + { + difference_type n = boost::re_detail::distance((iterator)first, (iterator)second); + return n; + } +}; + +#ifdef BOOST_OLD_REGEX_H +namespace re_detail{ +template +int do_toi(iterator i, iterator j, char c, int radix) +{ + std::string s(i, j); + char* p; + int result = std::strtol(s.c_str(), &p, radix); +#ifndef BOOST_NO_EXCEPTIONS + if(*p)throw bad_pattern("Bad sub-expression"); +#endif + BOOST_REGEX_NOEH_ASSERT(0 == *p) + return result; +} + +// +// helper: +template +int do_toi(I& i, I j, charT c) +{ + int result = 0; + while((i != j) && (isdigit(*i))) + { + result = result*10 + (*i - '0'); + ++i; + } + return result; +} +} + + +template +sub_match::operator int()const +{ + iterator i = first; + iterator j = second; +#ifndef BOOST_NO_EXCEPTIONS + if(i == j)throw bad_pattern("Bad sub-expression"); +#endif + BOOST_REGEX_NOEH_ASSERT(i != j) + int neg = 1; + if((i != j) && (*i == '-')) + { + neg = -1; + ++i; + } + neg *= re_detail::do_toi(i, j, *i); +#ifndef BOOST_NO_EXCEPTIONS + if(i != j)throw bad_pattern("Bad sub-expression"); +#endif + BOOST_REGEX_NOEH_ASSERT(i == j) + return neg; +} +template +sub_match::operator unsigned int()const +{ + iterator i = first; + iterator j = second; +#ifndef BOOST_NO_EXCEPTIONS + if(i == j) + throw bad_pattern("Bad sub-expression"); +#endif + BOOST_REGEX_NOEH_ASSERT(i != j) + return re_detail::do_toi(i, j, *first); +} +#endif + +namespace re_detail{ + +template ::type) > +class match_results_base +{ +public: + typedef Allocator alloc_type; + typedef typename boost::detail::rebind_allocator::type iterator_alloc; + typedef typename iterator_alloc::size_type size_type; +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_STD_ITERATOR_TRAITS) + typedef typename std::iterator_traits::difference_type difference_type; + typedef typename std::iterator_traits::value_type char_type; +#else + typedef std::ptrdiff_t difference_type; + typedef typename re_detail::regex_iterator_traits::value_type char_type; +#endif + typedef sub_match value_type; + typedef iterator iterator_type; + +protected: + typedef typename boost::detail::rebind_allocator::type c_alloc; + + struct c_reference : public c_alloc + { + std::size_t cmatches; + unsigned count; + sub_match head, tail, null; + unsigned int lines; + iterator line_pos, base; + c_reference(const Allocator& a) + : c_alloc(a), cmatches(0), count(0), lines(0) { } + + bool operator==(const c_reference& that)const + { + return (cmatches == that.cmatches) && + (count == that.count) && + (head == that.head) && + (tail == that.tail) && + (lines == that.lines) && + (base == that.base); + } + bool operator!=(const c_reference& that)const + { return !(*this == that); } + }; + + c_reference* ref; + + void BOOST_REGEX_CALL cow(); + + // protected contructor for derived class... + match_results_base(bool){} + void BOOST_REGEX_CALL m_free(); + +public: + + match_results_base(const Allocator& a = Allocator()); + + match_results_base(const match_results_base& m) + { + ref = m.ref; + ++(ref->count); + } + + match_results_base& BOOST_REGEX_CALL operator=(const match_results_base& m); + + ~match_results_base() + { + m_free(); + } + + size_type BOOST_REGEX_CALL size()const + { + //return (*this)[0].matched ? ref->cmatches : 0; + return ref->cmatches; + } + + const sub_match& BOOST_REGEX_CALL operator[](int n) const + { + if((n >= 0) && ((unsigned int)n < ref->cmatches)) + return *(sub_match*)((char*)ref + sizeof(c_reference) + sizeof(sub_match)*n); + return (n == -1) ? ref->head : (n == -2) ? ref->tail : ref->null; + } + + Allocator BOOST_REGEX_CALL allocator()const; + + difference_type BOOST_REGEX_CALL length(unsigned int sub = 0)const + { + jm_assert(ref->cmatches); + const sub_match& m = (*this)[sub]; + if(m.matched == false) + return 0; + difference_type n = boost::re_detail::distance((iterator)m.first, (iterator)m.second); + return n; + } + + std::basic_string str(int i)const + { + return static_cast >((*this)[i]); + } + + unsigned int BOOST_REGEX_CALL line()const + { + return ref->lines; + } + + difference_type BOOST_REGEX_CALL position(unsigned int sub = 0)const + { + jm_assert(ref->cmatches); + const sub_match& s = (*this)[sub]; + if(s.matched == false) + return -1; + difference_type n = boost::re_detail::distance((iterator)(ref->base), (iterator)(s.first)); + return n; + } + + iterator BOOST_REGEX_CALL line_start()const + { + return ref->line_pos; + } + + void swap(match_results_base& that) + { + c_reference* t = that.ref; + that.ref = ref; + ref = t; + } + + bool operator==(const match_results_base& that)const; + bool operator<(const match_results_base& that)const + { return position() < that.position(); } + + friend class match_results; + + void BOOST_REGEX_CALL set_size(size_type n); + void BOOST_REGEX_CALL set_size(size_type n, iterator i, iterator j); + void BOOST_REGEX_CALL maybe_assign(const match_results_base& m); + void BOOST_REGEX_CALL init_fail(iterator i, iterator j); + + void BOOST_REGEX_CALL set_first(iterator i); + void BOOST_REGEX_CALL set_first(iterator i, std::size_t pos); + + void BOOST_REGEX_CALL set_second(iterator i) + { + cow(); + ((sub_match*)(ref+1))->second = i; + ((sub_match*)(ref+1))->matched = true; + ref->tail.first = i; + ref->tail.matched = (ref->tail.first == ref->tail.second) ? false : true; + } + + void BOOST_REGEX_CALL set_second(iterator i, std::size_t pos, bool m = true) + { + cow(); + ((sub_match*)((char*)ref + sizeof(c_reference) + sizeof(sub_match) * pos))->second = i; + ((sub_match*)((char*)ref + sizeof(c_reference) + sizeof(sub_match) * pos))->matched = m; + if(pos == 0) + { + ref->tail.first = i; + ref->tail.matched = (ref->tail.first == ref->tail.second) ? false : true; + } + } + + void BOOST_REGEX_CALL set_line(unsigned int i, iterator pos) + { + ref->lines = i; + ref->line_pos = pos; + } + + void BOOST_REGEX_CALL set_base(iterator pos) + { + ref->base = pos; + } +}; + +template +void BOOST_REGEX_CALL match_results_base::set_first(iterator i) +{ + cow(); + ref->head.second = i; + ref->head.matched = (ref->head.first == ref->head.second) ? false : true; + sub_match* p1 = (sub_match*)(ref+1); + sub_match* p2 = p1 + ref->cmatches; + p1->first = i; + p1->matched = false; + ++p1; + while(p1 != p2) + { + p1->matched = false; + p1->first = ref->tail.second; + p1->second = ref->tail.second; + ++p1; + } +} + +template +void BOOST_REGEX_CALL match_results_base::set_first(iterator i, std::size_t pos) +{ + cow(); + ((sub_match*)((char*)ref + sizeof(c_reference) + sizeof(sub_match) * pos))->first = i; + if(pos == 0) + { + ref->head.second = i; + ref->head.matched = (ref->head.first == ref->head.second) ? false : true; + sub_match* p1 = (sub_match*)(ref+1); + sub_match* p2 = p1 + ref->cmatches; + p1->first = i; + p1->matched = false; + ++p1; + while(p1 != p2) + { + p1->matched = false; + p1->first = ref->tail.second; + p1->second = ref->tail.second; + ++p1; + } + } +} + + +template +match_results_base::match_results_base(const Allocator& a) +{ + ref = (c_reference*)c_alloc(a).allocate(sizeof(sub_match) + sizeof(c_reference)); + BOOST_REGEX_NOEH_ASSERT(ref) +#ifndef BOOST_NO_EXCEPTIONS + try + { +#endif + new (ref) c_reference(a); + ref->cmatches = 1; + ref->count = 1; + // construct the sub_match: +#ifndef BOOST_NO_EXCEPTIONS + try + { +#endif + new ((sub_match*)(ref+1)) sub_match(); +#ifndef BOOST_NO_EXCEPTIONS + } + catch(...) + { + ::boost::re_detail::pointer_destroy(ref); + throw; + } + } + catch(...) + { + c_alloc(a).deallocate((char*)(void*)ref, sizeof(sub_match) + sizeof(c_reference)); + throw; + } +#endif +} + +template +Allocator BOOST_REGEX_CALL match_results_base::allocator()const +{ + return *((c_alloc*)ref); +} + +template +inline match_results_base& BOOST_REGEX_CALL match_results_base::operator=(const match_results_base& m) +{ + if(ref != m.ref) + { + m_free(); + ref = m.ref; + ++(ref->count); + } + return *this; +} + + +template +void BOOST_REGEX_CALL match_results_base::m_free() +{ + if(--(ref->count) == 0) + { + c_alloc a(*ref); + sub_match* p1, *p2; + p1 = (sub_match*)(ref+1); + p2 = p1 + ref->cmatches; + while(p1 != p2) + { + ::boost::re_detail::pointer_destroy(p1); + ++p1; + } + ::boost::re_detail::pointer_destroy(ref); + a.deallocate((char*)(void*)ref, sizeof(sub_match) * ref->cmatches + sizeof(c_reference)); + } +} + +template +bool match_results_base::operator==(const match_results_base& that)const +{ + if(*ref != *(that.ref)) + return false; + const sub_match* p1 = (sub_match*)(ref+1); + const sub_match* p2 = p1 + ref->cmatches; + const sub_match* p3 = (sub_match*)(that.ref+1); + while(p1 != p2) + { + if(*p1 != *p3) + return false; + ++p1; + ++p3; + } + return true; +} + +template +void BOOST_REGEX_CALL match_results_base::set_size(size_type n) +{ + if(ref->cmatches != n) + { + c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match) * n + sizeof(c_reference)); + BOOST_REGEX_NOEH_ASSERT(newref) +#ifndef BOOST_NO_EXCEPTIONS + try + { +#endif + new (newref) c_reference(*ref); + newref->count = 1; + newref->cmatches = n; + sub_match* p1, *p2; + p1 = (sub_match*)(newref+1); + p2 = p1 + newref->cmatches; +#ifndef BOOST_NO_EXCEPTIONS + try + { +#endif + while(p1 != p2) + { + new (p1) sub_match(); + ++p1; + } + m_free(); +#ifndef BOOST_NO_EXCEPTIONS + } + catch(...) + { + p2 = (sub_match*)(newref+1); + while(p2 != p1) + { + ::boost::re_detail::pointer_destroy(p2); + ++p2; + } + ::boost::re_detail::pointer_destroy(ref); + throw; + } +#endif + ref = newref; +#ifndef BOOST_NO_EXCEPTIONS + } + catch(...) + { + ref->deallocate((char*)(void*)newref, sizeof(sub_match) * n + sizeof(c_reference)); + throw; + } +#endif + } +} + +template +void BOOST_REGEX_CALL match_results_base::set_size(size_type n, iterator i, iterator j) +{ + if(ref->cmatches != n) + { + c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match) * n + sizeof(c_reference)); + BOOST_REGEX_NOEH_ASSERT(newref) +#ifndef BOOST_NO_EXCEPTIONS + try{ +#endif + new (newref) c_reference(*ref); + newref->count = 1; + newref->cmatches = n; + sub_match* p1 = (sub_match*)(newref+1); + sub_match* p2 = p1 + newref->cmatches; +#ifndef BOOST_NO_EXCEPTIONS + try + { +#endif + while(p1 != p2) + { + new (p1) sub_match(j); + ++p1; + } + m_free(); +#ifndef BOOST_NO_EXCEPTIONS + } + catch(...) + { + p2 = (sub_match*)(newref+1); + while(p2 != p1) + { + ::boost::re_detail::pointer_destroy(p2); + ++p2; + } + ::boost::re_detail::pointer_destroy(ref); + throw; + } +#endif + ref = newref; +#ifndef BOOST_NO_EXCEPTIONS + } + catch(...) + { + ref->deallocate((char*)(void*)newref, sizeof(sub_match) * n + sizeof(c_reference)); + throw; + } +#endif + } + else + { + cow(); + // set iterators to be i, matched to false: + sub_match* p1, *p2; + p1 = (sub_match*)(ref+1); + p2 = p1 + ref->cmatches; + while(p1 != p2) + { + p1->first = j; + p1->second = j; + p1->matched = false; + ++p1; + } + } + ref->head.first = i; + ref->tail.second = j; + ref->head.matched = ref->tail.matched = true; + ref->null.first = ref->null.second = j; + ref->null.matched = false; +} + +template +inline void BOOST_REGEX_CALL match_results_base::init_fail(iterator i, iterator j) +{ + set_size(ref->cmatches, i, j); +} + +template +void BOOST_REGEX_CALL match_results_base::maybe_assign(const match_results_base& m) +{ + sub_match* p1, *p2; + p1 = (sub_match*)(ref+1); + p2 = (sub_match*)(m.ref+1); + iterator base = (*this)[-1].first; + std::size_t len1 = 0; + std::size_t len2 = 0; + std::size_t base1 = 0; + std::size_t base2 = 0; + std::size_t i; + for(i = 0; i < ref->cmatches; ++i) + { + // + // leftmost takes priority over longest: + base1 = boost::re_detail::distance(base, p1->first); + base2 = boost::re_detail::distance(base, p2->first); + if(base1 < base2) return; + if(base2 < base1) break; + + len1 = boost::re_detail::distance(p1->first, p1->second); + len2 = boost::re_detail::distance(p2->first, p2->second); + if((len1 != len2) || ((p1->matched == false) && (p2->matched == true))) + break; + if((p1->matched == true) && (p2->matched == false)) + return; + ++p1; + ++p2; + } + if(i == ref->cmatches) + return; + if(base2 < base1) + *this = m; + else if((len2 > len1) || ((p1->matched == false) && (p2->matched == true)) ) + *this = m; +} + +template +void BOOST_REGEX_CALL match_results_base::cow() +{ + if(ref->count > 1) + { + c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match) * ref->cmatches + sizeof(c_reference)); + BOOST_REGEX_NOEH_ASSERT(newref) +#ifndef BOOST_NO_EXCEPTIONS + try{ +#endif + new (newref) c_reference(*ref); + newref->count = 1; + sub_match* p1 = (sub_match*)(newref+1); + sub_match* p2 = p1 + newref->cmatches; + sub_match* p3 = (sub_match*)(ref+1); +#ifndef BOOST_NO_EXCEPTIONS + try{ +#endif + while(p1 != p2) + { + new (p1) sub_match(*p3); + ++p1; + ++p3; + } +#ifndef BOOST_NO_EXCEPTIONS + } + catch(...) + { + p2 = (sub_match*)(newref+1); + while(p2 != p1) + { + ::boost::re_detail::pointer_destroy(p2); + ++p2; + } + ::boost::re_detail::pointer_destroy(ref); + throw; + } +#endif + --(ref->count); + ref = newref; +#ifndef BOOST_NO_EXCEPTIONS + } + catch(...) + { + ref->deallocate((char*)(void*)newref, sizeof(sub_match) * ref->cmatches + sizeof(c_reference)); + throw; + } +#endif + } +} + +} // namespace re_detail + +// +// class match_results +// encapsulates match_results_base, does a deep copy rather than +// reference counting to ensure thread safety when copying +// other match_results instances + +template +class match_results : public re_detail::match_results_base +{ + typedef re_detail::match_results_base base_type; +public: + + typedef typename base_type::alloc_type alloc_type; + typedef typename base_type::size_type size_type; + typedef typename base_type::char_type char_type; + typedef typename base_type::value_type value_type; + typedef typename base_type::difference_type difference_type; + typedef typename base_type::iterator_type iterator_type; + + explicit match_results(const Allocator& a = Allocator()) + : re_detail::match_results_base(a){} + + match_results(const re_detail::match_results_base& m) + : re_detail::match_results_base(m){} + + match_results& operator=(const re_detail::match_results_base& m) + { + // shallow copy + base_type::operator=(m); + return *this; + } + + match_results(const match_results& m); + match_results& operator=(const match_results& m); + // + // the following function definitions should *not* be required, except + // when this class is used as a template inside another template definition, + // in which members of the base class are not visible to the calling code. + // As a workaround we define simple forwarding functions: + // + size_type size()const + { return static_cast(this)->size(); } + + const sub_match& operator[](int n) const + { return (*static_cast(this))[n]; } + + Allocator allocator()const + { return static_cast(this)->allocator(); } + + difference_type length(int sub = 0)const + { return static_cast(this)->length(sub); } + + difference_type position(unsigned int sub = 0)const + { return static_cast(this)->position(sub); } + + unsigned int line()const + { return static_cast(this)->line(); } + + iterator line_start()const + { return static_cast(this)->line_start(); } + + std::basic_string str(int sub = 0)const + { return static_cast(this)->str(sub); } + + void swap(match_results& that) + { static_cast(this)->swap(that); } + + bool operator==(const match_results& that)const + { return static_cast(*this) == static_cast(that); } + + bool operator<(const match_results& that) const + { return position() < that.position(); } +}; + +template +match_results::match_results(const match_results& m) + : re_detail::match_results_base(false) +{ + this->ref = + reinterpret_cast::c_reference *> + (m.ref->allocate(sizeof(sub_match) * m.ref->cmatches + + sizeof(typename re_detail::match_results_base::c_reference))); + BOOST_REGEX_NOEH_ASSERT(this->ref) +#ifndef BOOST_NO_EXCEPTIONS + try{ +#endif + new (this->ref) typename re_detail::match_results_base::c_reference(*m.ref); + this->ref->count = 1; + sub_match* p1 = (sub_match*)(this->ref+1); + sub_match* p2 = p1 + this->ref->cmatches; + sub_match* p3 = (sub_match*)(m.ref+1); +#ifndef BOOST_NO_EXCEPTIONS + try{ +#endif + while(p1 != p2) + { + new (p1) sub_match(*p3); + ++p1; + ++p3; + } +#ifndef BOOST_NO_EXCEPTIONS + } + catch(...) + { + p2 = (sub_match*)(this->ref+1); + while(p2 != p1) + { + re_detail::pointer_destroy(p2); + ++p2; + } + re_detail::pointer_destroy(this->ref); + throw; + } + } + catch(...) + { + m.ref->deallocate((char*)(void*)this->ref, sizeof(sub_match) * m.ref->cmatches + sizeof(typename re_detail::match_results_base::c_reference)); + throw; + } +#endif +} + +template +match_results& match_results::operator=(const match_results& m) +{ + match_results t(m); + this->swap(t); + return *this; +} + +namespace re_detail{ +template +iterator BOOST_REGEX_CALL re_is_set_member(iterator next, + iterator last, + const re_set_long* set_, + const reg_expression& e); +} // namepsace re_detail + +#ifdef __BORLANDC__ + #pragma option pop +#endif + +} // namespace boost + +#ifndef BOOST_REGEX_COMPILE_HPP +#include +#endif + +// +// template instances: +// +#define BOOST_REGEX_CHAR_T char +#ifdef BOOST_REGEX_NARROW_INSTANTIATE +# define BOOST_REGEX_INSTANTIATE +#endif +#include +#undef BOOST_REGEX_CHAR_T +#ifdef BOOST_REGEX_INSTANTIATE +# undef BOOST_REGEX_INSTANTIATE +#endif + +#ifndef BOOST_NO_WREGEX +#define BOOST_REGEX_CHAR_T wchar_t +#ifdef BOOST_REGEX_WIDE_INSTANTIATE +# define BOOST_REGEX_INSTANTIATE +#endif +#include +#undef BOOST_REGEX_CHAR_T +#ifdef BOOST_REGEX_INSTANTIATE +# undef BOOST_REGEX_INSTANTIATE +#endif +#endif + + +namespace boost{ +#ifdef BOOST_REGEX_NO_FWD +typedef reg_expression, BOOST_DEFAULT_ALLOCATOR(char)> regex; +#ifndef BOOST_NO_WREGEX +typedef reg_expression, BOOST_DEFAULT_ALLOCATOR(wchar_t)> wregex; +#endif +#endif + +typedef match_results cmatch; +typedef match_results smatch; +#ifndef BOOST_NO_WREGEX +typedef match_results wcmatch; +typedef match_results wsmatch; +#endif + +} // namespace boost +#ifndef BOOST_REGEX_MATCH_HPP +#include +#endif +#ifndef BOOST_REGEX_FORMAT_HPP +#include +#endif +#ifndef BOOST_REGEX_SPLIT_HPP +#include +#endif + +#endif // __cplusplus + +#endif // include + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/include/boost/regex/detail/regex_compile.hpp b/include/boost/regex/v3/regex_compile.hpp similarity index 100% rename from include/boost/regex/detail/regex_compile.hpp rename to include/boost/regex/v3/regex_compile.hpp diff --git a/include/boost/regex/detail/regex_cstring.hpp b/include/boost/regex/v3/regex_cstring.hpp similarity index 100% rename from include/boost/regex/detail/regex_cstring.hpp rename to include/boost/regex/v3/regex_cstring.hpp diff --git a/include/boost/regex/detail/regex_format.hpp b/include/boost/regex/v3/regex_format.hpp similarity index 100% rename from include/boost/regex/detail/regex_format.hpp rename to include/boost/regex/v3/regex_format.hpp diff --git a/include/boost/regex/v3/regex_fwd.hpp b/include/boost/regex/v3/regex_fwd.hpp new file mode 100644 index 00000000..2c3aca1a --- /dev/null +++ b/include/boost/regex/v3/regex_fwd.hpp @@ -0,0 +1,70 @@ +/* + * + * Copyright (c) 1998-2002 + * Dr John Maddock + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Dr John Maddock makes no representations + * about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + */ + + /* + * LOCATION: see http://www.boost.org for most recent version. + * FILE regex_fwd.cpp + * VERSION see + * DESCRIPTION: Forward declares boost::reg_expression<> and + * associated typedefs. + */ + +#ifndef BOOST_REGEX_FWD_HPP_INCLUDED +#define BOOST_REGEX_FWD_HPP_INCLUDED + +#ifndef BOOST_REGEX_CONFIG_HPP +#include +#endif +#include + +// +// define BOOST_REGEX_NO_FWD if this +// header doesn't work! +// +#ifdef BOOST_REGEX_NO_FWD +# ifndef BOOST_RE_REGEX_HPP +# include +# endif +#else + +// +// If there isn't good enough wide character support then there will +// be no wide character regular expressions: +// +#if (defined(BOOST_NO_CWCHAR) || defined(BOOST_NO_CWCTYPE) || defined(BOOST_NO_STD_WSTRING)) && !defined(BOOST_NO_WREGEX) +# define BOOST_NO_WREGEX +#endif + +namespace boost{ + +template +class regex_traits; + +template , class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) > +class reg_expression; + +typedef reg_expression, BOOST_DEFAULT_ALLOCATOR(char) > regex; +#ifndef BOOST_NO_WREGEX +typedef reg_expression, BOOST_DEFAULT_ALLOCATOR(wchar_t) > wregex; +#endif + +} // namespace boost + +#endif // BOOST_REGEX_NO_FWD + +#endif + + + diff --git a/include/boost/regex/detail/regex_kmp.hpp b/include/boost/regex/v3/regex_kmp.hpp similarity index 100% rename from include/boost/regex/detail/regex_kmp.hpp rename to include/boost/regex/v3/regex_kmp.hpp diff --git a/include/boost/regex/detail/regex_library_include.hpp b/include/boost/regex/v3/regex_library_include.hpp similarity index 100% rename from include/boost/regex/detail/regex_library_include.hpp rename to include/boost/regex/v3/regex_library_include.hpp diff --git a/include/boost/regex/detail/regex_match.hpp b/include/boost/regex/v3/regex_match.hpp similarity index 100% rename from include/boost/regex/detail/regex_match.hpp rename to include/boost/regex/v3/regex_match.hpp diff --git a/include/boost/regex/detail/regex_raw_buffer.hpp b/include/boost/regex/v3/regex_raw_buffer.hpp similarity index 100% rename from include/boost/regex/detail/regex_raw_buffer.hpp rename to include/boost/regex/v3/regex_raw_buffer.hpp diff --git a/include/boost/regex/detail/regex_split.hpp b/include/boost/regex/v3/regex_split.hpp similarity index 100% rename from include/boost/regex/detail/regex_split.hpp rename to include/boost/regex/v3/regex_split.hpp diff --git a/include/boost/regex/detail/regex_stack.hpp b/include/boost/regex/v3/regex_stack.hpp similarity index 99% rename from include/boost/regex/detail/regex_stack.hpp rename to include/boost/regex/v3/regex_stack.hpp index e66d031e..e81403b3 100644 --- a/include/boost/regex/detail/regex_stack.hpp +++ b/include/boost/regex/v3/regex_stack.hpp @@ -29,7 +29,7 @@ #include #endif #ifndef BOOST_REGEX_RAW_BUFFER_HPP -#include +#include #endif namespace boost{ @@ -224,3 +224,4 @@ jstack::~jstack() + diff --git a/include/boost/regex/detail/regex_synch.hpp b/include/boost/regex/v3/regex_synch.hpp similarity index 100% rename from include/boost/regex/detail/regex_synch.hpp rename to include/boost/regex/v3/regex_synch.hpp diff --git a/include/boost/regex/v3/regex_traits.hpp b/include/boost/regex/v3/regex_traits.hpp new file mode 100644 index 00000000..bd8b6413 --- /dev/null +++ b/include/boost/regex/v3/regex_traits.hpp @@ -0,0 +1,815 @@ +/* + * + * Copyright (c) 1998-2002 + * Dr John Maddock + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Dr John Maddock makes no representations + * about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + */ + + /* + * LOCATION: see http://www.boost.org for most recent version. + * FILE regex_traits.hpp + * VERSION see + * DESCRIPTION: Declares regular expression traits classes. + */ + +#ifndef BOOST_REGEX_TRAITS_HPP_INCLUDED +#define BOOST_REGEX_TRAITS_HPP_INCLUDED + +#ifndef BOOST_RE_CREGEX_HPP +#include +#endif +#ifndef BOOST_REGEX_CSTRING_HPP +#include +#endif + +namespace boost{ + +#ifdef __BORLANDC__ + #pragma option push -a8 -b -Vx -Ve -pc +#endif + +template +class c_regex_traits; + +namespace re_detail{ + +struct mss +{ + unsigned int id; + const char* what; +}; + +BOOST_REGEX_DECL bool BOOST_REGEX_CALL re_lookup_def_collate_name(std::string& buf, const char* name); +BOOST_REGEX_DECL std::size_t BOOST_REGEX_CALL re_get_default_message(char* buf, std::size_t len, std::size_t id); +extern BOOST_REGEX_DECL const char *re_default_error_messages[]; + +#ifndef BOOST_NO_WREGEX +extern BOOST_REGEX_DECL wchar_t wide_lower_case_map[]; +extern BOOST_REGEX_DECL unsigned short wide_unicode_classes[]; +BOOST_REGEX_DECL bool BOOST_REGEX_CALL is_combining(wchar_t c); +#endif + + +struct BOOST_REGEX_DECL regex_traits_base +{ + enum char_syntax_type + { + syntax_char = 0, + syntax_open_bracket = 1, // ( + syntax_close_bracket = 2, // ) + syntax_dollar = 3, // $ + syntax_caret = 4, // ^ + syntax_dot = 5, // . + syntax_star = 6, // * + syntax_plus = 7, // + + syntax_question = 8, // ? + syntax_open_set = 9, // [ + syntax_close_set = 10, // ] + syntax_or = 11, // | + syntax_slash = 12, // + syntax_hash = 13, // # + syntax_dash = 14, // - + syntax_open_brace = 15, // { + syntax_close_brace = 16, // } + syntax_digit = 17, // 0-9 + syntax_b = 18, // for \b + syntax_B = 19, // for \B + syntax_left_word = 20, // for \< + syntax_right_word = 21, // for \> + syntax_w = 22, // for \w + syntax_W = 23, // for \W + syntax_start_buffer = 24, // for \` + syntax_end_buffer = 25, // for \' + syntax_newline = 26, // for newline alt + syntax_comma = 27, // for {x,y} + + syntax_a = 28, // for \a + syntax_f = 29, // for \f + syntax_n = 30, // for \n + syntax_r = 31, // for \r + syntax_t = 32, // for \t + syntax_v = 33, // for \v + syntax_x = 34, // for \xdd + syntax_c = 35, // for \cx + syntax_colon = 36, // for [:...:] + syntax_equal = 37, // for [=...=] + + // perl ops: + syntax_e = 38, // for \e + syntax_l = 39, // for \l + syntax_L = 40, // for \L + syntax_u = 41, // for \u + syntax_U = 42, // for \U + syntax_s = 43, // for \s + syntax_S = 44, // for \S + syntax_d = 45, // for \d + syntax_D = 46, // for \D + syntax_E = 47, // for \Q\E + syntax_Q = 48, // for \Q\E + syntax_X = 49, // for \X + syntax_C = 50, // for \C + syntax_Z = 51, // for \Z + syntax_G = 52, // for \G + + // new extentions: + syntax_not = 53, // for (?!...) + + syntax_max = 54 + }; +#ifdef __BORLANDC__ +private: + char dummy_member; +#endif +}; + +struct BOOST_REGEX_DECL c_traits_base : public regex_traits_base +{ +public: + enum{ + char_class_none = 0, + char_class_alpha = 0x0001, + char_class_cntrl = 0x0002, + char_class_digit = 0x0004, + char_class_lower = 0x0008, + char_class_punct = 0x0010, + char_class_space = 0x0020, + char_class_upper = 0x0040, + char_class_xdigit = 0x0080, + char_class_blank = 0x0100, + char_class_underscore = 0x4000, + char_class_unicode = 0x8000, + + char_class_alnum = char_class_alpha | char_class_digit, + char_class_graph = char_class_alpha | char_class_digit | char_class_punct | char_class_underscore, + char_class_print = char_class_alpha | char_class_digit | char_class_punct | char_class_underscore | char_class_blank, + char_class_word = char_class_alpha | char_class_digit | char_class_underscore + }; + static std::string BOOST_REGEX_CALL set_message_catalogue(const std::string& s); +protected: +#if defined(__MWERKS__) && __MWERKS__ <= 0x6000 + friend class c_regex_traits; + friend class c_regex_traits; +#endif + + static char regex_message_catalogue[BOOST_REGEX_MAX_PATH]; + enum syntax_map_size + { + map_size = UCHAR_MAX + 1 + }; + + static unsigned char syntax_map[map_size]; + static unsigned short class_map[map_size]; + static char lower_case_map[map_size]; + + static boost::uint_fast32_t BOOST_REGEX_CALL do_lookup_class(const char* p); + static bool BOOST_REGEX_CALL do_lookup_collate(std::string& buf, const char* p); + static void BOOST_REGEX_CALL do_update_ctype(); + static void BOOST_REGEX_CALL do_update_collate(); +public: + static std::string BOOST_REGEX_CALL error_string(unsigned id); + static char* BOOST_REGEX_CALL get_catalogue() { return regex_message_catalogue; } +}; + +} // namespace re_detail + + +template<> +class BOOST_REGEX_DECL c_regex_traits : public re_detail::c_traits_base +{ + typedef re_detail::c_traits_base base_type; +public: + typedef char char_type; + typedef unsigned char uchar_type; + typedef unsigned int size_type; + typedef std::string string_type; + typedef int locale_type; + + static std::size_t BOOST_REGEX_CALL length(const char_type* p) + { + return std::strlen(p); + } + static unsigned int BOOST_REGEX_CALL syntax_type(size_type c) + { + return syntax_map[c]; + } + static char BOOST_REGEX_CALL translate(char c, bool icase) + { + return icase ? lower_case_map[(size_type)(uchar_type)c] : c; + } + static void BOOST_REGEX_CALL transform(std::string& out, const std::string& in); + + static void BOOST_REGEX_CALL transform_primary(std::string& out, const std::string& in); + + static bool BOOST_REGEX_CALL is_separator(char c) + { + return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r')); + } + + static bool BOOST_REGEX_CALL is_combining(char) + { + return false; + } + + static bool BOOST_REGEX_CALL is_class(char c, boost::uint_fast32_t f) + { + return BOOST_REGEX_MAKE_BOOL(class_map[(size_type)(uchar_type)c] & f); + } + + static int BOOST_REGEX_CALL toi(char c); + static int BOOST_REGEX_CALL toi(const char*& first, const char* last, int radix); + + static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const char* first, const char* last) + { + std::string s(first, last); + return do_lookup_class(s.c_str()); + } + + static bool BOOST_REGEX_CALL lookup_collatename(std::string& buf, const char* first, const char* last) + { + std::string s(first, last); + return do_lookup_collate(buf, s.c_str()); + } + + static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; } + locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); } + + c_regex_traits() + { + init(); + } + ~c_regex_traits() + { + m_free(); + } + struct sentry + { + sentry(const c_regex_traits&) + { c_regex_traits::update(); } + operator void*() { return this; } + }; + static void BOOST_REGEX_CALL update(); +private: + static void BOOST_REGEX_CALL init(); + static void BOOST_REGEX_CALL m_free(); + static c_regex_traits i; + + static unsigned sort_type; + static char sort_delim; +}; + +#ifndef BOOST_NO_WREGEX +template<> +class BOOST_REGEX_DECL c_regex_traits : public re_detail::c_traits_base +{ + typedef re_detail::c_traits_base base_type; +public: + typedef wchar_t char_type; + typedef unsigned short uchar_type; + typedef unsigned int size_type; + typedef std::basic_string string_type; + typedef int locale_type; + static std::size_t BOOST_REGEX_CALL length(const char_type* p) + { + return std::wcslen(p); + } + static unsigned int BOOST_REGEX_CALL syntax_type(size_type c); + static wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool icase) + { + return icase ? ((c < 256) ? re_detail::wide_lower_case_map[(uchar_type)c] : std::towlower(c)) : c; + } + + static void BOOST_REGEX_CALL transform(std::basic_string& out, const std::basic_string& in); + + static void BOOST_REGEX_CALL transform_primary(std::basic_string& out, const std::basic_string& in); + + static bool BOOST_REGEX_CALL is_separator(wchar_t c) + { + return BOOST_REGEX_MAKE_BOOL((c == L'\n') || (c == L'\r') || (c == (wchar_t)0x2028) || (c == (wchar_t)0x2029)); + } + + static bool BOOST_REGEX_CALL is_combining(wchar_t c) + { return re_detail::is_combining(c); } + + static bool BOOST_REGEX_CALL is_class(wchar_t c, boost::uint_fast32_t f) + { + return BOOST_REGEX_MAKE_BOOL(((uchar_type)c < 256) ? (re_detail::wide_unicode_classes[(size_type)(uchar_type)c] & f) : do_iswclass(c, f)); + } + + static int BOOST_REGEX_CALL toi(wchar_t c); + static int BOOST_REGEX_CALL toi(const wchar_t*& first, const wchar_t* last, int radix); + + static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last); + + static bool BOOST_REGEX_CALL lookup_collatename(std::basic_string& s, const wchar_t* first, const wchar_t* last); + + static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; } + locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); } + c_regex_traits() + { init(); } + ~c_regex_traits() + { m_free(); } + struct sentry + { + sentry(const c_regex_traits&) + { c_regex_traits::update(); } + operator void*() { return this; } + }; + static void BOOST_REGEX_CALL update(); + static std::size_t BOOST_REGEX_CALL strnarrow(char *s1, std::size_t len, const wchar_t *s2); + static std::size_t BOOST_REGEX_CALL strwiden(wchar_t *s1, std::size_t len, const char *s2); +private: + static bool BOOST_REGEX_CALL do_iswclass(wchar_t c, boost::uint_fast32_t f); + static void BOOST_REGEX_CALL m_free(); + static void BOOST_REGEX_CALL init(); + static bool BOOST_REGEX_CALL do_lookup_collate(std::basic_string& out, const wchar_t* first, const wchar_t* last); + static c_regex_traits init_; + + static unsigned sort_type; + static wchar_t sort_delim; +}; +#endif + +#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32) + +namespace re_detail{ + +struct BOOST_REGEX_DECL w32_traits_base : public regex_traits_base +{ + enum{ + char_class_none = 0, + char_class_alnum = C1_ALPHA | C1_DIGIT, + char_class_alpha = C1_ALPHA, + char_class_cntrl = C1_CNTRL, + char_class_digit = C1_DIGIT, + char_class_graph = C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA, + char_class_lower = C1_LOWER, + char_class_print = C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_BLANK | C1_ALPHA, + char_class_punct = C1_PUNCT, + char_class_space = C1_SPACE, + char_class_upper = C1_UPPER, + char_class_xdigit = C1_XDIGIT, + char_class_blank = C1_BLANK, + char_class_underscore = 0x4000, + char_class_word = C1_ALPHA | C1_DIGIT | char_class_underscore, + char_class_unicode = 0x8000, + char_class_win = 0x01FF + }; + + +public: + static std::string BOOST_REGEX_CALL set_message_catalogue(const std::string& s); +protected: + static char regex_message_catalogue[BOOST_REGEX_MAX_PATH]; + enum syntax_map_size + { + map_size = UCHAR_MAX + 1 + }; + + static unsigned char syntax_map[map_size]; + static unsigned short class_map[map_size]; + static char lower_case_map[map_size]; + + static boost::uint_fast32_t BOOST_REGEX_CALL do_lookup_class(const char* p); + static bool BOOST_REGEX_CALL do_lookup_collate(std::string& buf, const char* p); + static void BOOST_REGEX_CALL do_free(); + static void BOOST_REGEX_CALL do_init(); +public: + static std::string BOOST_REGEX_CALL error_string(unsigned id); + static char* BOOST_REGEX_CALL get_catalogue() { return regex_message_catalogue; } +}; + + +} // namespace re_detail + +template +class w32_regex_traits; + +template<> +class BOOST_REGEX_DECL w32_regex_traits : public re_detail::w32_traits_base +{ + typedef re_detail::w32_traits_base base_type; +public: + typedef char char_type; + typedef unsigned char uchar_type; + typedef unsigned int size_type; + typedef std::string string_type; + typedef int locale_type; + + static std::size_t BOOST_REGEX_CALL length(const char_type* p) + { + return std::strlen(p); + } + static unsigned int BOOST_REGEX_CALL syntax_type(size_type c) + { + return syntax_map[c]; + } + static char BOOST_REGEX_CALL translate(char c, bool icase) + { + return icase ? lower_case_map[(size_type)(uchar_type)c] : c; + } + static void BOOST_REGEX_CALL transform(std::string& out, const std::string& in); + + static void BOOST_REGEX_CALL transform_primary(std::string& out, const std::string& in); + + static bool BOOST_REGEX_CALL is_separator(char c) + { + return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r')); + } + + static bool BOOST_REGEX_CALL is_combining(char) + { + return false; + } + + static bool BOOST_REGEX_CALL is_class(char c, boost::uint_fast32_t f) + { + return BOOST_REGEX_MAKE_BOOL(class_map[(size_type)(uchar_type)c] & f); + } + + static int BOOST_REGEX_CALL toi(char c); + static int BOOST_REGEX_CALL toi(const char*& first, const char* last, int radix); + + static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const char* first, const char* last) + { + std::string s(first, last); + return do_lookup_class(s.c_str()); + } + + static bool BOOST_REGEX_CALL lookup_collatename(std::string& buf, const char* first, const char* last) + { + std::string s(first, last); + return do_lookup_collate(buf, s.c_str()); + } + + static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; } + locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); } + + struct sentry + { + sentry(const w32_regex_traits&) + { w32_regex_traits::update(); } + ~sentry(){} + operator void*() { return this; } + }; + static void BOOST_REGEX_CALL update(); + w32_regex_traits(); + ~w32_regex_traits(); +private: + static w32_regex_traits i; +}; + +#ifndef BOOST_NO_WREGEX +template<> +class BOOST_REGEX_DECL w32_regex_traits : public re_detail::w32_traits_base +{ + typedef re_detail::w32_traits_base base_type; +public: + typedef wchar_t char_type; + typedef unsigned short uchar_type; + typedef unsigned int size_type; + typedef std::basic_string string_type; + typedef int locale_type; + static std::size_t BOOST_REGEX_CALL length(const char_type* p) + { + return std::wcslen(p); + } + static unsigned int BOOST_REGEX_CALL syntax_type(size_type c); + static wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool icase) + { + return icase ? ((c < 256) ? re_detail::wide_lower_case_map[(uchar_type)c] : wtolower(c)) : c; + } + + static void BOOST_REGEX_CALL transform(std::basic_string& out, const std::basic_string& in); + + static void BOOST_REGEX_CALL transform_primary(std::basic_string& out, const std::basic_string& in); + + static bool BOOST_REGEX_CALL is_separator(wchar_t c) + { + return BOOST_REGEX_MAKE_BOOL((c == L'\n') || (c == L'\r') || (c == (wchar_t)0x2028) || (c == (wchar_t)0x2029)); + } + + static bool BOOST_REGEX_CALL is_combining(wchar_t c) + { return re_detail::is_combining(c); } + + static bool BOOST_REGEX_CALL is_class(wchar_t c, boost::uint_fast32_t f) + { + return BOOST_REGEX_MAKE_BOOL(((uchar_type)c < 256) ? (wide_unicode_classes[(size_type)(uchar_type)c] & f) : do_iswclass(c, f)); + } + + static int BOOST_REGEX_CALL toi(wchar_t c); + static int BOOST_REGEX_CALL toi(const wchar_t*& first, const wchar_t* last, int radix); + + static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last); + + static bool BOOST_REGEX_CALL lookup_collatename(std::basic_string& s, const wchar_t* first, const wchar_t* last); + + static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; } + locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); } + + struct sentry + { + sentry(const w32_regex_traits&) + { w32_regex_traits::update(); } + ~sentry(){} + operator void*() { return this; } + }; + static void BOOST_REGEX_CALL update(); + w32_regex_traits(); + ~w32_regex_traits(); + static std::size_t BOOST_REGEX_CALL strnarrow(char *s1, std::size_t len, const wchar_t *s2); + static std::size_t BOOST_REGEX_CALL strwiden(wchar_t *s1, std::size_t len, const char *s2); + +private: + static bool BOOST_REGEX_CALL do_iswclass(wchar_t c, boost::uint_fast32_t f); + static bool BOOST_REGEX_CALL do_lookup_collate(std::basic_string& out, const wchar_t* first, const wchar_t* last); + static w32_regex_traits init_; + static wchar_t BOOST_REGEX_CALL wtolower(wchar_t c); + static unsigned short wide_unicode_classes[]; +}; +#endif // Wide strings +#endif // Win32 + +#if !defined(BOOST_NO_STD_LOCALE) && !defined(BOOST_NO_STD_WSTREAMBUF) + +} // namspace boost + +#ifdef __BORLANDC__ + #pragma option pop +#endif +#include +#ifdef __BORLANDC__ + #pragma option push -a4 -b -Ve -pc +#endif + +namespace boost{ + +namespace re_detail +{ + +template +struct message_data; + +template <> +struct message_data; + +template <> +struct message_data; + +struct BOOST_REGEX_DECL cpp_regex_traits_base : public regex_traits_base +{ + enum char_class_type + { + char_class_none = 0, + char_class_alnum = std::ctype_base::alnum, + char_class_alpha = std::ctype_base::alpha, + char_class_cntrl = std::ctype_base::cntrl, + char_class_digit = std::ctype_base::digit, + char_class_graph = std::ctype_base::graph, + char_class_lower = std::ctype_base::lower, + char_class_print = std::ctype_base::print, + char_class_punct = std::ctype_base::punct, + char_class_space = std::ctype_base::space, + char_class_upper = std::ctype_base::upper, + char_class_xdigit = std::ctype_base::xdigit, + char_class_blank = 1<<12, + char_class_underscore = 1<<13, + char_class_word = std::ctype_base::alnum | char_class_underscore, + char_class_unicode = 1<<14, + char_class_all_base = char_class_alnum | char_class_alpha | char_class_cntrl + | char_class_digit | char_class_graph | char_class_lower + | char_class_print | char_class_punct | char_class_space + | char_class_upper | char_class_xdigit + }; + + static std::string BOOST_REGEX_CALL set_message_catalogue(const std::string& s); +protected: + static char regex_message_cat[BOOST_REGEX_MAX_PATH]; +}; + +} // namespace re_detail + +template +class cpp_regex_traits; + +template<> +class BOOST_REGEX_DECL cpp_regex_traits : public re_detail::cpp_regex_traits_base +{ + typedef re_detail::cpp_regex_traits_base base_type; +private: + re_detail::message_data* pmd; + const unsigned char* psyntax; + char* lower_map; + const std::ctype* pctype; + const std::collate* pcollate; + std::locale locale_inst; + unsigned sort_type; + char sort_delim; + + cpp_regex_traits(const cpp_regex_traits&); + cpp_regex_traits& operator=(const cpp_regex_traits&); + +public: + typedef char char_type; + typedef unsigned char uchar_type; + typedef unsigned int size_type; + typedef std::string string_type; + typedef std::locale locale_type; + + cpp_regex_traits(); + ~cpp_regex_traits(); + + static std::size_t BOOST_REGEX_CALL length(const char_type* p) + { + return std::strlen(p); + } + unsigned int BOOST_REGEX_CALL syntax_type(size_type c)const + { + return psyntax[c]; + } + char BOOST_REGEX_CALL translate(char c, bool icase)const + { + return icase ? lower_map[(size_type)(uchar_type)c] : c; + } + void BOOST_REGEX_CALL transform(std::string& out, const std::string& in)const + { + out = pcollate->transform(in.c_str(), in.c_str() + in.size()).c_str(); + } + + void BOOST_REGEX_CALL transform_primary(std::string& out, const std::string& in)const; + + static bool BOOST_REGEX_CALL is_separator(char c) + { + return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r')); + } + + static bool BOOST_REGEX_CALL is_combining(char) + { + return false; + } + + bool BOOST_REGEX_CALL is_class(char c, boost::uint_fast32_t f)const + { + if(pctype->is((std::ctype::mask)(f & char_class_all_base), c)) + return true; + if((f & char_class_underscore) && (c == '_')) + return true; + if((f & char_class_blank) && ((c == ' ') || (c == '\t'))) + return true; + return false; + } + + int BOOST_REGEX_CALL toi(char c)const; + int BOOST_REGEX_CALL toi(const char*& first, const char* last, int radix)const; + + boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const char* first, const char* last)const; + bool BOOST_REGEX_CALL lookup_collatename(std::string& s, const char* first, const char* last)const; + + std::string BOOST_REGEX_CALL error_string(unsigned id)const; + locale_type BOOST_REGEX_CALL imbue(locale_type l); + locale_type BOOST_REGEX_CALL getloc()const{ return locale_inst; } + + struct sentry + { + sentry(const cpp_regex_traits&){} + operator void*() { return this; } + }; +}; + +#ifndef BOOST_NO_WREGEX +template<> +class BOOST_REGEX_DECL cpp_regex_traits : public re_detail::cpp_regex_traits_base +{ + typedef re_detail::cpp_regex_traits_base base_type; +public: + typedef wchar_t char_type; + typedef unsigned short uchar_type; + typedef unsigned int size_type; + typedef std::basic_string string_type; + typedef std::locale locale_type; + +private: + re_detail::message_data* pmd; + const unsigned char* psyntax; + wchar_t* lower_map; + const std::ctype* pctype; + const std::collate* pcollate; + const std::codecvt* pcdv; + std::locale locale_inst; + unsigned int BOOST_REGEX_CALL do_syntax_type(size_type c)const; + unsigned sort_type; + wchar_t sort_delim; + + cpp_regex_traits(const cpp_regex_traits&); + cpp_regex_traits& operator=(const cpp_regex_traits&); + +public: + + static std::size_t BOOST_REGEX_CALL length(const char_type* p) + { + return std::wcslen(p); + } + unsigned int BOOST_REGEX_CALL syntax_type(size_type c)const + { + return (c < UCHAR_MAX) ? psyntax[c] : do_syntax_type(c); + } + wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool icase)const + { + return icase ? (((uchar_type)c) <= UCHAR_MAX) ? lower_map[c] : pctype->tolower(c) : c; + } + void BOOST_REGEX_CALL transform(std::basic_string& out, const std::basic_string& in)const + { + out = pcollate->transform(in.c_str(), in.c_str() + in.size()); + } + + void BOOST_REGEX_CALL transform_primary(std::basic_string& out, const std::basic_string& in)const; + + static bool BOOST_REGEX_CALL is_separator(wchar_t c) + { + return BOOST_REGEX_MAKE_BOOL((c == L'\n') || (c == L'\r') || (c == (wchar_t)0x2028) || (c == (wchar_t)0x2029)); + } + + static bool BOOST_REGEX_CALL is_combining(wchar_t c) + { return re_detail::is_combining(c); } + + bool BOOST_REGEX_CALL is_class(wchar_t c, boost::uint_fast32_t f)const + { + if(pctype->is((std::ctype::mask)(f & char_class_all_base), c)) + return true; + if((f & char_class_underscore) && (c == '_')) + return true; + if((f & char_class_blank) && ((c == ' ') || (c == '\t'))) + return true; + if((f & char_class_unicode) && ((uchar_type)c > (uchar_type)255)) + return true; + return false; + } + + int BOOST_REGEX_CALL toi(wchar_t c)const; + int BOOST_REGEX_CALL toi(const wchar_t*& first, const wchar_t* last, int radix)const; + + boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last)const; + bool BOOST_REGEX_CALL lookup_collatename(std::basic_string& s, const wchar_t* first, const wchar_t* last)const; + + std::string BOOST_REGEX_CALL error_string(unsigned id)const; + cpp_regex_traits(); + ~cpp_regex_traits(); + locale_type BOOST_REGEX_CALL imbue(locale_type l); + locale_type BOOST_REGEX_CALL getloc()const{ return locale_inst; } + std::size_t BOOST_REGEX_CALL strwiden(wchar_t *s1, std::size_t len, const char *s2)const; + + struct sentry + { + sentry(const cpp_regex_traits&){} + operator void*() { return this; } + }; +}; +#endif // BOOST_NO_WREGEX + +#endif // BOOST_NO_STD_LOCALE + +#ifdef BOOST_REGEX_USE_WIN32_LOCALE + +template +class regex_traits : public w32_regex_traits +{ +}; + +#elif defined(BOOST_REGEX_USE_C_LOCALE) + +template +class regex_traits : public c_regex_traits +{ +}; + +#elif defined(BOOST_REGEX_USE_CPP_LOCALE) + +template +class regex_traits : public cpp_regex_traits +{ +}; + +#else +#error No default localisation model defined +#endif + +#ifdef __BORLANDC__ + #pragma option pop +#endif + +} // namespace boost + +#endif // include + + + + + + diff --git a/include/boost/regex_fwd.hpp b/include/boost/regex_fwd.hpp index 679ad945..be777260 100644 --- a/include/boost/regex_fwd.hpp +++ b/include/boost/regex_fwd.hpp @@ -24,44 +24,9 @@ #ifndef BOOST_REGEX_FWD_HPP #define BOOST_REGEX_FWD_HPP -#include -#include - -// -// define BOOST_REGEX_NO_FWD if this -// header doesn't work! -// -#ifdef BOOST_REGEX_NO_FWD -# ifndef BOOST_RE_REGEX_HPP -# include -# endif -#else - -// -// If there isn't good enough wide character support then there will -// be no wide character regular expressions: -// -#if (defined(BOOST_NO_CWCHAR) || defined(BOOST_NO_CWCTYPE) || defined(BOOST_NO_STD_WSTRING)) && !defined(BOOST_NO_WREGEX) -# define BOOST_NO_WREGEX -#endif - -namespace boost{ - -template -class regex_traits; - -template , class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) > -class reg_expression; - -typedef reg_expression, BOOST_DEFAULT_ALLOCATOR(char) > regex; -#ifndef BOOST_NO_WREGEX -typedef reg_expression, BOOST_DEFAULT_ALLOCATOR(wchar_t) > wregex; -#endif - -} // namespace boost - -#endif // BOOST_REGEX_NO_FWD +#include #endif +