IN2OSM  1.0.1
GenericRegexSearch< RegexType, Allocator >

#include <regex.h>

Collaboration diagram for GenericRegexSearch< RegexType, Allocator >:
Collaboration graph

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

◆ Ch

typedef Encoding::Ch Ch

Definition at line 610 of file regex.h.

◆ Encoding

typedef RegexType::EncodingType Encoding

Definition at line 609 of file regex.h.

◆ Range

typedef RegexType::Range Range
private

Definition at line 651 of file regex.h.

◆ State

typedef RegexType::State State
private

Definition at line 650 of file regex.h.

Constructor & Destructor Documentation

◆ GenericRegexSearch()

GenericRegexSearch ( const RegexType &  regex,
Allocator *  allocator = 0 
)
inline

Definition at line 612 of file regex.h.

612  :
613  regex_(regex), allocator_(allocator), ownAllocator_(0),
614  state0_(allocator, 0), state1_(allocator, 0), stateSet_()
615  {
616  RAPIDJSON_ASSERT(regex_.IsValid());
617  if (!allocator_)
618  ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
619  stateSet_ = static_cast<unsigned*>(allocator_->Malloc(GetStateSetSize()));
620  state0_.template Reserve<SizeType>(regex_.stateCount_);
621  state1_.template Reserve<SizeType>(regex_.stateCount_);
622  }
Allocator * ownAllocator_
Definition: regex.h:720
Stack< Allocator > state0_
Definition: regex.h:721
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:625
Stack< Allocator > state1_
Definition: regex.h:722
size_t GetStateSetSize() const
Definition: regex.h:687
const RegexType & regex_
Definition: regex.h:718
Allocator * allocator_
Definition: regex.h:719
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406

◆ ~GenericRegexSearch()

~GenericRegexSearch ( )
inline

Definition at line 624 of file regex.h.

624  {
625  Allocator::Free(stateSet_);
627  }
Allocator * ownAllocator_
Definition: regex.h:720
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:629

Member Function Documentation

◆ AddState()

bool AddState ( Stack< Allocator > &  l,
SizeType  index 
)
inlineprivate

Definition at line 692 of file regex.h.

692  {
694 
695  const State& s = regex_.GetState(index);
696  if (s.out1 != kRegexInvalidState) { // Split
697  bool matched = AddState(l, s.out);
698  return AddState(l, s.out1) || matched;
699  }
700  else if (!(stateSet_[index >> 5] & (1u << (index & 31)))) {
701  stateSet_[index >> 5] |= (1u << (index & 31));
702  *l.template PushUnsafe<SizeType>() = index;
703  }
704  return s.out == kRegexInvalidState; // by using PushUnsafe() above, we can ensure s is not validated due to reallocation.
705  }
static const SizeType kRegexInvalidState
Represents an invalid index in GenericRegex::State::out, out1.
Definition: regex.h:75
const RegexType & regex_
Definition: regex.h:718
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
bool AddState(Stack< Allocator > &l, SizeType index)
Definition: regex.h:692
RegexType::State State
Definition: regex.h:650

◆ GetStateSetSize()

size_t GetStateSetSize ( ) const
inlineprivate

Definition at line 687 of file regex.h.

687  {
688  return (regex_.stateCount_ + 31) / 32 * 4;
689  }
const RegexType & regex_
Definition: regex.h:718

◆ Match() [1/2]

bool Match ( InputStream &  is)
inline

Definition at line 630 of file regex.h.

630  {
631  return SearchWithAnchoring(is, true, true);
632  }
bool SearchWithAnchoring(InputStream &is, bool anchorBegin, bool anchorEnd)
Definition: regex.h:654

◆ Match() [2/2]

bool Match ( const Ch s)
inline

Definition at line 634 of file regex.h.

634  {
636  return Match(is);
637  }
bool Match(InputStream &is)
Definition: regex.h:630
Read-only string stream.
Definition: fwd.h:47

◆ MatchRange()

bool MatchRange ( SizeType  rangeIndex,
unsigned  codepoint 
) const
inlineprivate

Definition at line 707 of file regex.h.

707  {
708  bool yes = (regex_.GetRange(rangeIndex).start & RegexType::kRangeNegationFlag) == 0;
709  while (rangeIndex != kRegexInvalidRange) {
710  const Range& r = regex_.GetRange(rangeIndex);
711  if (codepoint >= (r.start & ~RegexType::kRangeNegationFlag) && codepoint <= r.end)
712  return yes;
713  rangeIndex = r.next;
714  }
715  return !yes;
716  }
static const SizeType kRegexInvalidRange
Definition: regex.h:76
RegexType::Range Range
Definition: regex.h:651
const RegexType & regex_
Definition: regex.h:718

◆ Search() [1/2]

bool Search ( InputStream &  is)
inline

Definition at line 640 of file regex.h.

640  {
641  return SearchWithAnchoring(is, regex_.anchorBegin_, regex_.anchorEnd_);
642  }
bool SearchWithAnchoring(InputStream &is, bool anchorBegin, bool anchorEnd)
Definition: regex.h:654
const RegexType & regex_
Definition: regex.h:718
Here is the caller graph for this function:

◆ Search() [2/2]

bool Search ( const Ch s)
inline

Definition at line 644 of file regex.h.

644  {
646  return Search(is);
647  }
Read-only string stream.
Definition: fwd.h:47
bool Search(InputStream &is)
Definition: regex.h:640

◆ SearchWithAnchoring()

bool SearchWithAnchoring ( InputStream &  is,
bool  anchorBegin,
bool  anchorEnd 
)
inlineprivate

Definition at line 654 of file regex.h.

654  {
655  DecodedStream<InputStream, Encoding> ds(is);
656 
657  state0_.Clear();
658  Stack<Allocator> *current = &state0_, *next = &state1_;
659  const size_t stateSetSize = GetStateSetSize();
660  std::memset(stateSet_, 0, stateSetSize);
661 
662  bool matched = AddState(*current, regex_.root_);
663  unsigned codepoint;
664  while (!current->Empty() && (codepoint = ds.Take()) != 0) {
665  std::memset(stateSet_, 0, stateSetSize);
666  next->Clear();
667  matched = false;
668  for (const SizeType* s = current->template Bottom<SizeType>(); s != current->template End<SizeType>(); ++s) {
669  const State& sr = regex_.GetState(*s);
670  if (sr.codepoint == codepoint ||
671  sr.codepoint == RegexType::kAnyCharacterClass ||
672  (sr.codepoint == RegexType::kRangeCharacterClass && MatchRange(sr.rangeStart, codepoint)))
673  {
674  matched = AddState(*next, sr.out) || matched;
675  if (!anchorEnd && matched)
676  return true;
677  }
678  if (!anchorBegin)
679  AddState(*next, regex_.root_);
680  }
681  internal::Swap(current, next);
682  }
683 
684  return matched;
685  }
bool MatchRange(SizeType rangeIndex, unsigned codepoint) const
Definition: regex.h:707
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
Stack< Allocator > state0_
Definition: regex.h:721
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition: swap.h:33
Stack< Allocator > state1_
Definition: regex.h:722
size_t GetStateSetSize() const
Definition: regex.h:687
const RegexType & regex_
Definition: regex.h:718
bool AddState(Stack< Allocator > &l, SizeType index)
Definition: regex.h:692
RegexType::State State
Definition: regex.h:650
Here is the call graph for this function:

Member Data Documentation

◆ allocator_

Allocator* allocator_
private

Definition at line 719 of file regex.h.

◆ ownAllocator_

Allocator* ownAllocator_
private

Definition at line 720 of file regex.h.

◆ regex_

const RegexType& regex_
private

Definition at line 718 of file regex.h.

◆ state0_

Stack<Allocator> state0_
private

Definition at line 721 of file regex.h.

◆ state1_

Stack<Allocator> state1_
private

Definition at line 722 of file regex.h.

◆ stateSet_

uint32_t* stateSet_
private

Definition at line 723 of file regex.h.


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