Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
internal::GenericRegexSearch< RegexType, Allocator > Class Template Reference

#include <regex.h>

Public Types

typedef RegexType::EncodingType Encoding
 
typedef Encoding::Ch Ch
 

Public Member Functions

 GenericRegexSearch (const RegexType &regex, Allocator *allocator=0)
 
 ~GenericRegexSearch ()
 
template<typename InputStream >
bool Match (InputStream &is)
 
bool Match (const Ch *s)
 
template<typename InputStream >
bool Search (InputStream &is)
 
bool Search (const Ch *s)
 

Private Types

typedef RegexType::State State
 
typedef RegexType::Range Range
 

Private Member Functions

template<typename InputStream >
bool SearchWithAnchoring (InputStream &is, bool anchorBegin, bool anchorEnd)
 
size_t GetStateSetSize () const
 
bool AddState (Stack< Allocator > &l, SizeType index)
 
bool MatchRange (SizeType rangeIndex, unsigned codepoint) const
 

Private Attributes

const RegexType & regex_
 
Allocator * allocator_
 
Allocator * ownAllocator_
 
Stack< Allocator > state0_
 
Stack< Allocator > state1_
 
uint32_tstateSet_
 

Detailed Description

template<typename RegexType, typename Allocator = CrtAllocator>
class internal::GenericRegexSearch< RegexType, Allocator >

Definition at line 79 of file regex.h.

Member Typedef Documentation

template<typename RegexType, typename Allocator = CrtAllocator>
typedef Encoding::Ch internal::GenericRegexSearch< RegexType, Allocator >::Ch

Definition at line 602 of file regex.h.

template<typename RegexType, typename Allocator = CrtAllocator>
typedef RegexType::EncodingType internal::GenericRegexSearch< RegexType, Allocator >::Encoding

Definition at line 601 of file regex.h.

template<typename RegexType, typename Allocator = CrtAllocator>
typedef RegexType::Range internal::GenericRegexSearch< RegexType, Allocator >::Range
private

Definition at line 643 of file regex.h.

template<typename RegexType, typename Allocator = CrtAllocator>
typedef RegexType::State internal::GenericRegexSearch< RegexType, Allocator >::State
private

Definition at line 642 of file regex.h.

Constructor & Destructor Documentation

template<typename RegexType, typename Allocator = CrtAllocator>
internal::GenericRegexSearch< RegexType, Allocator >::GenericRegexSearch ( const RegexType &  regex,
Allocator *  allocator = 0 
)
inline

Definition at line 604 of file regex.h.

604  :
605  regex_(regex), allocator_(allocator), ownAllocator_(0),
606  state0_(allocator, 0), state1_(allocator, 0), stateSet_()
607  {
608  RAPIDJSON_ASSERT(regex_.IsValid());
609  if (!allocator_)
610  ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
611  stateSet_ = static_cast<unsigned*>(allocator_->Malloc(GetStateSetSize()));
612  state0_.template Reserve<SizeType>(regex_.stateCount_);
613  state1_.template Reserve<SizeType>(regex_.stateCount_);
614  }
Allocator * ownAllocator_
Definition: regex.h:712
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Stack< Allocator > state0_
Definition: regex.h:713
const RegexType & regex_
Definition: regex.h:710
Allocator * allocator_
Definition: regex.h:711
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:601
size_t GetStateSetSize() const
Definition: regex.h:679
Stack< Allocator > state1_
Definition: regex.h:714
template<typename RegexType, typename Allocator = CrtAllocator>
internal::GenericRegexSearch< RegexType, Allocator >::~GenericRegexSearch ( )
inline

Definition at line 616 of file regex.h.

616  {
617  Allocator::Free(stateSet_);
619  }
Allocator * ownAllocator_
Definition: regex.h:712
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:605

Member Function Documentation

template<typename RegexType, typename Allocator = CrtAllocator>
bool internal::GenericRegexSearch< RegexType, Allocator >::AddState ( Stack< Allocator > &  l,
SizeType  index 
)
inlineprivate

Definition at line 684 of file regex.h.

684  {
686 
687  const State& s = regex_.GetState(index);
688  if (s.out1 != kRegexInvalidState) { // Split
689  bool matched = AddState(l, s.out);
690  return AddState(l, s.out1) || matched;
691  }
692  else if (!(stateSet_[index >> 5] & (1u << (index & 31)))) {
693  stateSet_[index >> 5] |= (1u << (index & 31));
694  *l.template PushUnsafe<SizeType>() = index;
695  }
696  return s.out == kRegexInvalidState; // by using PushUnsafe() above, we can ensure s is not validated due to reallocation.
697  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
const RegexType & regex_
Definition: regex.h:710
bool AddState(Stack< Allocator > &l, SizeType index)
Definition: regex.h:684
static QStrList * l
Definition: config.cpp:1044
RegexType::State State
Definition: regex.h:642
static const SizeType kRegexInvalidState
Represents an invalid index in GenericRegex::State::out, out1.
Definition: regex.h:75
static QCString * s
Definition: config.cpp:1042
template<typename RegexType, typename Allocator = CrtAllocator>
size_t internal::GenericRegexSearch< RegexType, Allocator >::GetStateSetSize ( ) const
inlineprivate

Definition at line 679 of file regex.h.

679  {
680  return (regex_.stateCount_ + 31) / 32 * 4;
681  }
const RegexType & regex_
Definition: regex.h:710
template<typename RegexType, typename Allocator = CrtAllocator>
template<typename InputStream >
bool internal::GenericRegexSearch< RegexType, Allocator >::Match ( InputStream &  is)
inline

Definition at line 622 of file regex.h.

622  {
623  return SearchWithAnchoring(is, true, true);
624  }
bool SearchWithAnchoring(InputStream &is, bool anchorBegin, bool anchorEnd)
Definition: regex.h:646
template<typename RegexType, typename Allocator = CrtAllocator>
bool internal::GenericRegexSearch< RegexType, Allocator >::Match ( const Ch s)
inline

Definition at line 626 of file regex.h.

626  {
628  return Match(is);
629  }
Read-only string stream.
Definition: fwd.h:47
bool Match(InputStream &is)
Definition: regex.h:622
static QCString * s
Definition: config.cpp:1042
template<typename RegexType, typename Allocator = CrtAllocator>
bool internal::GenericRegexSearch< RegexType, Allocator >::MatchRange ( SizeType  rangeIndex,
unsigned  codepoint 
) const
inlineprivate

Definition at line 699 of file regex.h.

699  {
700  bool yes = (regex_.GetRange(rangeIndex).start & RegexType::kRangeNegationFlag) == 0;
701  while (rangeIndex != kRegexInvalidRange) {
702  const Range& r = regex_.GetRange(rangeIndex);
703  if (codepoint >= (r.start & ~RegexType::kRangeNegationFlag) && codepoint <= r.end)
704  return yes;
705  rangeIndex = r.next;
706  }
707  return !yes;
708  }
const RegexType & regex_
Definition: regex.h:710
int start
Definition: doxysearch.cpp:178
int end
Definition: doxysearch.cpp:179
static const SizeType kRegexInvalidRange
Definition: regex.h:76
template<typename RegexType, typename Allocator = CrtAllocator>
template<typename InputStream >
bool internal::GenericRegexSearch< RegexType, Allocator >::Search ( InputStream &  is)
inline

Definition at line 632 of file regex.h.

632  {
633  return SearchWithAnchoring(is, regex_.anchorBegin_, regex_.anchorEnd_);
634  }
const RegexType & regex_
Definition: regex.h:710
bool SearchWithAnchoring(InputStream &is, bool anchorBegin, bool anchorEnd)
Definition: regex.h:646
template<typename RegexType, typename Allocator = CrtAllocator>
bool internal::GenericRegexSearch< RegexType, Allocator >::Search ( const Ch s)
inline

Definition at line 636 of file regex.h.

636  {
638  return Search(is);
639  }
Read-only string stream.
Definition: fwd.h:47
bool Search(InputStream &is)
Definition: regex.h:632
static QCString * s
Definition: config.cpp:1042
template<typename RegexType, typename Allocator = CrtAllocator>
template<typename InputStream >
bool internal::GenericRegexSearch< RegexType, Allocator >::SearchWithAnchoring ( InputStream &  is,
bool  anchorBegin,
bool  anchorEnd 
)
inlineprivate

Definition at line 646 of file regex.h.

646  {
647  DecodedStream<InputStream, Encoding> ds(is);
648 
649  state0_.Clear();
650  Stack<Allocator> *current = &state0_, *next = &state1_;
651  const size_t stateSetSize = GetStateSetSize();
652  std::memset(stateSet_, 0, stateSetSize);
653 
654  bool matched = AddState(*current, regex_.root_);
655  unsigned codepoint;
656  while (!current->Empty() && (codepoint = ds.Take()) != 0) {
657  std::memset(stateSet_, 0, stateSetSize);
658  next->Clear();
659  matched = false;
660  for (const SizeType* s = current->template Bottom<SizeType>(); s != current->template End<SizeType>(); ++s) {
661  const State& sr = regex_.GetState(*s);
662  if (sr.codepoint == codepoint ||
663  sr.codepoint == RegexType::kAnyCharacterClass ||
664  (sr.codepoint == RegexType::kRangeCharacterClass && MatchRange(sr.rangeStart, codepoint)))
665  {
666  matched = AddState(*next, sr.out) || matched;
667  if (!anchorEnd && matched)
668  return true;
669  }
670  if (!anchorBegin)
671  AddState(*next, regex_.root_);
672  }
673  internal::Swap(current, next);
674  }
675 
676  return matched;
677  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
Stack< Allocator > state0_
Definition: regex.h:713
const RegexType & regex_
Definition: regex.h:710
bool AddState(Stack< Allocator > &l, SizeType index)
Definition: regex.h:684
RegexType::State State
Definition: regex.h:642
static Entry * current
size_t GetStateSetSize() const
Definition: regex.h:679
Stack< Allocator > state1_
Definition: regex.h:714
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition: swap.h:33
bool MatchRange(SizeType rangeIndex, unsigned codepoint) const
Definition: regex.h:699
static const double sr
Definition: Units.h:166
static QCString * s
Definition: config.cpp:1042

Member Data Documentation

template<typename RegexType, typename Allocator = CrtAllocator>
Allocator* internal::GenericRegexSearch< RegexType, Allocator >::allocator_
private

Definition at line 711 of file regex.h.

template<typename RegexType, typename Allocator = CrtAllocator>
Allocator* internal::GenericRegexSearch< RegexType, Allocator >::ownAllocator_
private

Definition at line 712 of file regex.h.

template<typename RegexType, typename Allocator = CrtAllocator>
const RegexType& internal::GenericRegexSearch< RegexType, Allocator >::regex_
private

Definition at line 710 of file regex.h.

template<typename RegexType, typename Allocator = CrtAllocator>
Stack<Allocator> internal::GenericRegexSearch< RegexType, Allocator >::state0_
private

Definition at line 713 of file regex.h.

template<typename RegexType, typename Allocator = CrtAllocator>
Stack<Allocator> internal::GenericRegexSearch< RegexType, Allocator >::state1_
private

Definition at line 714 of file regex.h.

template<typename RegexType, typename Allocator = CrtAllocator>
uint32_t* internal::GenericRegexSearch< RegexType, Allocator >::stateSet_
private

Definition at line 715 of file regex.h.


The documentation for this class was generated from the following file: