Navigation Menu

Skip to content

Commit

Permalink
tweaks to filter and regex handling to allow for continuous usage of …
Browse files Browse the repository at this point in the history
…Filter object
  • Loading branch information
atks committed Dec 9, 2016
1 parent 3b648be commit 29d5ac8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
32 changes: 22 additions & 10 deletions filter.cpp
Expand Up @@ -1028,16 +1028,9 @@ void Filter::parse(const char* exp, bool debug)
}
}

if (tree!=NULL)
{
delete tree;
tree = NULL;
}
else
{
tree = new Node();
parse(exp_no_space.c_str(), exp_no_space.size(), tree, debug);
}
reset();
tree = new Node();
parse(exp_no_space.c_str(), exp_no_space.size(), tree, debug);

if (!tree->type&VT_BOOL)
{
Expand Down Expand Up @@ -1079,6 +1072,25 @@ bool Filter::apply(bcf_hdr_t *h, bcf1_t *v, Variant *variant, bool debug) //recu
}
}

/**
* Attempts to simplify the expression tree by collapsing nodes that can be precomputed.
*/
void Filter::simplify()
{
}

/**
* Resets filter.
*/
void Filter::reset()
{
if (tree!=NULL)
{
delete tree;
tree = NULL;
}
}

/**
* Constructs the expression tree.
*/
Expand Down
5 changes: 5 additions & 0 deletions filter.h
Expand Up @@ -160,6 +160,11 @@ class Filter
* Attempts to simplify the expression tree by collapsing nodes that can be precomputed.
*/
void simplify();

/**
* Resets filter.
*/
void reset();

private:

Expand Down
20 changes: 16 additions & 4 deletions pregex.h
Expand Up @@ -32,6 +32,18 @@
/**
* Class for PERL regular expressions.
* Wrapper for pcre2.
*
* Usage
*
* //using C++ strings
* std::string regex = "abc";
* pregex.set(regex);
* std::string target = "aabcc";
* bool b = pregex.match(target);
*
* //using C strings
* pregex.set(regex.s);
* bool b = pregex.match(target.s);
*/
class PERLregex
{
Expand Down Expand Up @@ -69,7 +81,7 @@ class PERLregex
* Destructor.
*/
~PERLregex();

/**
* Sets the regular expression amd compiles it for matching later.
*/
Expand All @@ -79,16 +91,16 @@ class PERLregex
* Sets the regular expression amd compiles it for matching later.
*/
void set(char* regex);

/**
* Matches a text against a regular expression that has been compiled in set().
*/
bool match(std::string& text);

/**
* Matches a text against a regular expression that has been compiled in set().
*/
bool match(char* text);
bool match(char* text);
};

#endif

0 comments on commit 29d5ac8

Please sign in to comment.