Пример #1
0
void queryTable::ClickedFilterQuery()
{
    bool setFilter=false;
    if (!ui->searchLinePatientName->text().isEmpty()){
        QString UrlSearch("^");
        UrlSearch.append(ui->searchLinePatientName->text());
        QRegExp Regex(UrlSearch);
        proxyModel->setFilterRegExp(Regex);
        proxyModel->setFilterKeyColumn(0);
        setFilter = true;
    }
    if (!ui->searchLinePatientID->text().isEmpty()){
        QString UrlSearch("^");
        UrlSearch.append(ui->searchLinePatientID->text());
        qDebug() << UrlSearch;
        QRegExp Regex(UrlSearch);
        proxyModel->setFilterRegExp(Regex);
        proxyModel->setFilterKeyColumn(1);
        setFilter = true;
    }
    if (!ui->searchLineAccessionNumber->text().isEmpty()){
        QString UrlSearch("^");
        UrlSearch.append(ui->searchLineAccessionNumber->text());
        QRegExp Regex(UrlSearch);
        proxyModel->setFilterRegExp(Regex);
        proxyModel->setFilterKeyColumn(2);
        setFilter = true;
    }
    if (!setFilter)
        proxyModel->setFilterRegExp("");


}
Пример #2
0
BOOST_FIXTURE_TEST_CASE_TEMPLATE(Filters, PktType, PktTypes, RuleFixture<PktType::value>)
{
  this->rule.addFilter(make_unique<RegexNameFilter>(Regex("^<foo><bar>$")));

  BOOST_CHECK_EQUAL(this->rule.match(PktType::value, this->pktName), true);
  BOOST_CHECK_EQUAL(this->rule.match(PktType::value, "/not" + this->pktName.toUri()), false);

  this->rule.addFilter(make_unique<RegexNameFilter>(Regex("^<not><foo><bar>$")));

  BOOST_CHECK_EQUAL(this->rule.match(PktType::value, this->pktName), true);
  BOOST_CHECK_EQUAL(this->rule.match(PktType::value, "/not" + this->pktName.toUri()), true);

  auto state = make_shared<DummyValidationState>();
  BOOST_CHECK_EQUAL(this->rule.check(PktType::value, this->pktName, "/foo/bar", state), false);
}
Пример #3
0
 void WildcardCache(const string& Leftover, const string& ObjHandle, F Func)
 {
     std::regex Regex(Regexify(ObjHandle));
     for (auto i = Cache.begin(); i != Cache.end(); ++i)
         if (std::regex_match(i->first, Regex))
             Leftover.empty() ? CallSafe(&i->second, Func) : ExecuteSafe(i->first, Leftover, Func);
 }
Пример #4
0
bool RewriteMapParser::
parseRewriteGlobalAliasDescriptor(yaml::Stream &YS, yaml::ScalarNode *K,
                                  yaml::MappingNode *Descriptor,
                                  RewriteDescriptorList *DL) {
  std::string Source;
  std::string Target;
  std::string Transform;

  for (auto &Field : *Descriptor) {
    yaml::ScalarNode *Key;
    yaml::ScalarNode *Value;
    SmallString<32> KeyStorage;
    SmallString<32> ValueStorage;
    StringRef KeyValue;

    Key = dyn_cast<yaml::ScalarNode>(Field.getKey());
    if (!Key) {
      YS.printError(Field.getKey(), "descriptor key must be a scalar");
      return false;
    }

    Value = dyn_cast<yaml::ScalarNode>(Field.getValue());
    if (!Value) {
      YS.printError(Field.getValue(), "descriptor value must be a scalar");
      return false;
    }

    KeyValue = Key->getValue(KeyStorage);
    if (KeyValue.equals("source")) {
      std::string Error;

      Source = Value->getValue(ValueStorage);
      if (!Regex(Source).isValid(Error)) {
        YS.printError(Field.getKey(), "invalid regex: " + Error);
        return false;
      }
    } else if (KeyValue.equals("target")) {
      Target = Value->getValue(ValueStorage);
    } else if (KeyValue.equals("transform")) {
      Transform = Value->getValue(ValueStorage);
    } else {
      YS.printError(Field.getKey(), "unknown key for Global Alias");
      return false;
    }
  }

  if (Transform.empty() == Target.empty()) {
    YS.printError(Descriptor,
                  "exactly one of transform or target must be specified");
    return false;
  }

  if (!Target.empty())
    DL->push_back(new ExplicitRewriteNamedAliasDescriptor(Source, Target,
                                                          /*Naked*/false));
  else
    DL->push_back(new PatternRewriteNamedAliasDescriptor(Source, Transform));

  return true;
}
Пример #5
0
 void WildcardAlias(const string& Leftover, const string& ObjHandle, F Func)
 {
     std::regex Regex(Regexify(ObjHandle.substr(1)));
     for (auto i = Aliases.begin(); i != Aliases.end(); ++i)
         if (std::regex_match(i->first, Regex))
             Leftover.empty() ? Execute(i->second, Func) : ExecuteSafe(i->second, Leftover, Func);
 }
Пример #6
0
bool PatternRewriteDescriptor<DT, ValueType, Get, Iterator>::
performOnModule(Module &M) {
  bool Changed = false;
  for (auto &C : (M.*Iterator)()) {
    std::string Error;

    std::string Name = Regex(Pattern).sub(Transform, C.getName(), &Error);
    if (!Error.empty())
      report_fatal_error("unable to transforn " + C.getName() + " in " +
                         M.getModuleIdentifier() + ": " + Error);

    if (C.getName() == Name)
      continue;

    if (GlobalObject *GO = dyn_cast<GlobalObject>(&C))
      rewriteComdat(M, GO, C.getName(), Name);

    if (Value *V = (M.*Get)(Name))
      C.setValueName(V->getValueName());
    else
      C.setName(Name);

    Changed = true;
  }
  return Changed;
}
Пример #7
0
ribi::cmap::ConceptMap ribi::cmap::XmlToConceptMap(const std::string& s)
{
 if (s.size() < 13)
  {
    std::stringstream msg;
    msg << __func__ << ": string too short, "
      << "received '" << s << "'"
    ;
    throw std::logic_error(msg.str());
  }
  const std::string required_tag{"<conceptmap>"};
  const int required_tag_size{static_cast<int>(required_tag.size())};
  if (s.substr(0, required_tag_size) != required_tag)
  {
    std::stringstream msg;
    msg << __func__ << ": incorrect starting tag, "
      << "required '" << required_tag << "', "
      << "received '" << s << "'"
    ;
    throw std::logic_error(msg.str());
  }
  if (s.substr(s.size() - 13,13) != "</conceptmap>")
  {
    std::stringstream msg;
    msg << __func__ << ": incorrect ending tag";
    throw std::logic_error(msg.str());
  }
  //Need to write the DOT to file
  const std::string dot_filename = ribi::fileio::FileIo().GetTempFileName(".dot");
  {
    const std::vector<std::string> v
      = Regex().GetRegexMatches(s,Regex().GetRegexConceptMap());
    assert(v.size() == 1);
    const std::string dot_str{
      ribi::xml::StripXmlTag(v[0])
    };

    std::ofstream f(dot_filename);
    f << dot_str;
  }
  ConceptMap conceptmap = LoadFromFile(dot_filename);
  ribi::fileio::FileIo().DeleteFile(dot_filename);
  return conceptmap;
}
ribi::About ribi::TestConceptMapMenuDialog::GetAbout() const noexcept
{
  About a(
    "Richel Bilderbeek",
    "TestConceptMap",
    "tests the ConceptMap classes",
    "on April 9th 2016",
    "2013-2016",
    "http://www.richelbilderbeek.nl/ToolTestConceptMap.htm",
    GetVersion(),
    GetVersionHistory());

  a.AddLibrary("apfloat version: 2.4.1");
  //a.AddLibrary("ConceptMap version: " + ribi::cmap::ConceptMap::GetVersion());
  a.AddLibrary("Container version: " + ribi::Container().GetVersion());
  a.AddLibrary("FileIo version: " + FileIo().GetVersion());
  a.AddLibrary("Geometry version: " + Geometry().GetVersion());
  a.AddLibrary("ribi::Regex version: " + Regex().GetVersion());
  a.AddLibrary("Plane version: " + Plane::GetVersion());
  a.AddLibrary("TestTimer version: " + TestTimer::GetVersion());
  a.AddLibrary("Trace version: " + Trace::GetVersion());

  return a;
}
namespace libdnf {

static const Regex RELDEP_REGEX = 
    Regex("^(\\S*)\\s*(<=|>=|<|>|=)?\\s*(.*)$", REG_EXTENDED);

static bool
getCmpFlags(int *cmp_type, std::string matchCmpType)
{
    int subexpr_len = matchCmpType.size();
    auto match_start = matchCmpType.c_str();
    if (subexpr_len == 2) {
        if (strncmp(match_start, "<=", 2) == 0) {
            *cmp_type |= HY_LT;
            *cmp_type |= HY_EQ;
        }
        else if (strncmp(match_start, ">=", 2) == 0) {
            *cmp_type |= HY_GT;
            *cmp_type |= HY_EQ;
        }
        else
            return false;
    } else if (subexpr_len == 1) {
        if (*match_start == '<')
            *cmp_type |= HY_LT;
        else if (*match_start == '>')
            *cmp_type |= HY_GT;
        else if (*match_start == '=')
            *cmp_type |= HY_EQ;
        else
            return false;
    } else
        return false;
    return true;
}

bool
DependencySplitter::parse(const char * reldepStr)
{
    enum { NAME = 1, CMP_TYPE = 2, EVR = 3, _LAST_ };
    auto matchResult = RELDEP_REGEX.match(reldepStr, false, _LAST_);
    if (!matchResult.isMatched() || matchResult.getMatchedLen(NAME) == 0) {
        return false;
    }
    name = matchResult.getMatchedString(NAME);
    evr = matchResult.getMatchedString(EVR);
    cmpType = 0;
    int evrLen = matchResult.getMatchedLen(EVR);
    int cmpTypeLen = matchResult.getMatchedLen(CMP_TYPE);
    if (cmpTypeLen < 1) {
        if (evrLen > 0) {
            // name contains the space char, e.g. filename like "hello world.jpg"
            evr.clear();
            name = reldepStr;
        }
        return true;
    }
    if (evrLen < 1)
        return false;

    return getCmpFlags(&cmpType, matchResult.getMatchedString(CMP_TYPE));
}

}
Пример #10
0
	const Regex Interpreter::regex(const String::Value& regexp, Raw_string flags) const {
		Scalar::Temp temp = implementation::Call_stack(raw_interp.get()).push(regexp, flags).sub_scalar("Embed::Perlpp::regexp");
		return Regex(std::unique_ptr<Regex::Implementation>(new Regex::Implementation(raw_interp.get(), temp.release())));
	}
Пример #11
0
bool RewriteMapParser::
parseRewriteFunctionDescriptor(yaml::Stream &YS, yaml::ScalarNode *K,
                               yaml::MappingNode *Descriptor,
                               RewriteDescriptorList *DL) {
  bool Naked = false;
  std::string Source;
  std::string Target;
  std::string Transform;

  for (auto &Field : *Descriptor) {
    yaml::ScalarNode *Key;
    yaml::ScalarNode *Value;
    SmallString<32> KeyStorage;
    SmallString<32> ValueStorage;
    StringRef KeyValue;

    Key = dyn_cast<yaml::ScalarNode>(Field.getKey());
    if (!Key) {
      YS.printError(Field.getKey(), "descriptor key must be a scalar");
      return false;
    }

    Value = dyn_cast<yaml::ScalarNode>(Field.getValue());
    if (!Value) {
      YS.printError(Field.getValue(), "descriptor value must be a scalar");
      return false;
    }

    KeyValue = Key->getValue(KeyStorage);
    if (KeyValue.equals("source")) {
      std::string Error;

      Source = Value->getValue(ValueStorage);
      if (!Regex(Source).isValid(Error)) {
        YS.printError(Field.getKey(), "invalid regex: " + Error);
        return false;
      }
    } else if (KeyValue.equals("target")) {
      Target = Value->getValue(ValueStorage);
    } else if (KeyValue.equals("transform")) {
      Transform = Value->getValue(ValueStorage);
    } else if (KeyValue.equals("naked")) {
      std::string Undecorated;

      Undecorated = Value->getValue(ValueStorage);
      Naked = StringRef(Undecorated).lower() == "true" || Undecorated == "1";
    } else {
      YS.printError(Field.getKey(), "unknown key for function");
      return false;
    }
  }

  if (Transform.empty() == Target.empty()) {
    YS.printError(Descriptor,
                  "exactly one of transform or target must be specified");
    return false;
  }

  // TODO see if there is a more elegant solution to selecting the rewrite
  // descriptor type
  if (!Target.empty())
    DL->push_back(new ExplicitRewriteFunctionDescriptor(Source, Target, Naked));
  else
    DL->push_back(new PatternRewriteFunctionDescriptor(Source, Transform));

  return true;
}
Пример #12
0
bool match_wildcard(const String& wildcard, const String& name) {
	return Regex(replace_all(replace_all(wildcard, _("."), _("\\.")), _("*"), _(".*"))).matches(name);
}
/** int _OS_Regex(char *pattern, char *str, char **prts_closure,
              char **prts_str, int flags) v0.1
 * Perform the pattern matching on the pattern/string provided.
 * Returns 1 on success and 0 on failure.
 * If prts_closure is set, the parenthesis locations will be
 * written on prts_str (which must not be NULL)
 */              
char *_OS_Regex(char *pattern, char *str, char **prts_closure, 
              char **prts_str, int flags)
{
    char *r_code = NULL;
    
    int ok_here;
    int _regex_matched = 0;
    
    int prts_int;

    char *st = str;
    char *st_error = NULL;
    
    char *pt = pattern;
    char *next_pt;

    char *pt_error[4] = {NULL, NULL, NULL, NULL};
    char *pt_error_str[4];
    

    /* Will loop the whole string, trying to find a match */
    do
    {
        switch(*pt)
        {
            case '\0':
                if(!(flags & END_SET) || (flags & END_SET && (*st == '\0')))
                    return(r_code);
                break;

                /* If it is a parenthesis do not match against the character */
            case '(':
                /* Find the closure for the parenthesis */
                if(prts_closure)
                {
                    prts_int = 0;
                    while(prts_closure[prts_int])
                    {
                        if(prts_closure[prts_int] == pt)
                        {
                            prts_str[prts_int] = st;
                            break;
                        }
                        prts_int++;
                    }
                }

                pt++;
                if(*pt == '\0')
                {
                    if(!(flags & END_SET) || (flags & END_SET && (*st == '\0')))
                        return(r_code);
                }
                break;
        }

        /* If it starts on Backslash (future regex) */
        if(*pt == BACKSLASH)
        {
            if(Regex((uchar)*(pt+1), (uchar)*st))
            {
                next_pt = pt+2;
                
                /* If we don't have a '+' or '*', we should skip
                 * searching using this pattern.
                 */
                if(!isPlus(*next_pt))
                {
                    pt = next_pt;
                    if(!st_error)
                    {
                        /* If st_error is not set, we need to set it here.
                         * In case of error in the matching later, we need
                         * to continue from here (it will be incremented in
                         * the while loop)
                         */
                        st_error = st;
                    }
                    r_code = st;
                    continue;
                }
                
                /* If it is a '*', we need to set the _regex_matched
                 * for the first pattern even.
                 */
                if(*next_pt == '*')
                {
                    _regex_matched = 1;
                }


                /* If our regex matches and we have a "+" set, we will
                 * try the next one to see if it matches. If yes, we 
                 * can jump to it, but saving our currently location
                 * in case of error.
                 * _regex_matched will set set to true after the first
                 * round of matches
                 */
                if(_regex_matched)
                {
                    next_pt++;
                    ok_here = -1;

                    /* If it is a parenthesis, jump to the next and write
                     * the location down if 'ok_here >= 0'
                     */
                    if(prts(*next_pt))
                    {
                        next_pt++;
                    }
                    
                    if(*next_pt == '\0')
                    {
                        ok_here = 1;
                    }
                    else if(*next_pt == BACKSLASH)
                    {
                        if(Regex((uchar)*(next_pt+1), (uchar)*st))
                        {
                            /* If the next one does not have
                             * a '+' or '*', we can set it as
                             * being read and continue.
                             */
                            if(!isPlus(*(next_pt+2)))
                            {
                                ok_here = 2;
                            }
                            else
                            {
                                ok_here = 0;
                            }
                        }
                    }
                    else if(*next_pt == charmap[(uchar)*st])
                    {
                        _regex_matched = 0;
                        ok_here = 1;
                    }

                    /* If the next character matches in here */
                    if(ok_here >= 0)
                    {
                        if(prts_closure && prts(*(next_pt - 1)))
                        {
                            prts_int = 0;
                            while(prts_closure[prts_int])
                            {
                                if(prts_closure[prts_int] == (next_pt -1))
                                {
                                    if(*(st+1) == '\0')
                                        prts_str[prts_int] = st+1;
                                    else    
                                        prts_str[prts_int] = st;
                                    break;
                                }
                                prts_int++;
                            }
                        }


                        /* If next_pt == \0, return the r_code */
                        if(*next_pt == '\0')
                        {
                            continue;
                        }

                            
                        /* Each "if" will increment the amount
                         * necessary for the next pattern in ok_here
                         */
                        if(ok_here) 
                            next_pt+=ok_here;
                        
                        
                        if(!pt_error[0])
                        {
                            pt_error[0] = pt;
                            pt_error_str[0] = st;
                        }
                        else if(!pt_error[1])
                        {
                            pt_error[1] = pt;
                            pt_error_str[1] = st;
                        }
                        else if(!pt_error[2])
                        {
                            pt_error[2] = pt;
                            pt_error_str[2] = st;

                        }
                        else if(!pt_error[3])
                        {
                            pt_error[3] = pt;
                            pt_error_str[3] = st;
                        }

                        pt = next_pt;
                    }
                }
                else
                {
                    next_pt++;

                    /* If it is a parenthesis, mark the location */
                    if(prts_closure && prts(*next_pt))
                    {
                        prts_int = 0;
                        while(prts_closure[prts_int])
                        {
                            if(prts_closure[prts_int] == next_pt)
                            {
                                if(*(st+1) == '\0')
                                    prts_str[prts_int] = st +1;
                                else
                                    prts_str[prts_int] = st;
                                break;
                            }
                            prts_int++;
                        }
                        next_pt++;
                    }

                    _regex_matched = 1;
                }
                
                r_code = st;
                continue;
            }
            
            else if((*(pt+3) == '\0') && (_regex_matched == 1)&&(r_code))
            {
                r_code = st;
                if(!(flags & END_SET) || (flags & END_SET && (*st == '\0')))
                    return(r_code);
            }
            
            /* If we didn't match regex, but _regex_matched == 1, jump
             * to the next available pattern
             */
            else if((*(pt+2) == '+') && (_regex_matched == 1))
            {
                pt+=3;
                st--;
                _regex_matched = 0;
                continue;
            }
            /* We may not match with '*' */
            else if(*(pt+2) == '*')
            {
                pt+=3;
                st--;
                r_code = st;
                _regex_matched = 0;
                continue;
            }

            _regex_matched = 0;
        }
        else if(*pt == charmap[(uchar)*st])
        {
            pt++;
            if(!st_error)
            {
                /* If st_error is not set, we need to set it here.
                 * In case of error in the matching later, we need
                 * to continue from here (it will be incremented in
                 * the while loop)
                 */
                st_error = st;
            }
            r_code = st;
            continue;
        }

        /* Error Handling */
            if(pt_error[3])
            {
                pt = pt_error[3];
                st = pt_error_str[3];
                pt_error[3] = NULL;
                continue;
            }
            else if(pt_error[2])
            {
                pt = pt_error[2];
                st = pt_error_str[2];
                pt_error[2] = NULL;
                continue;
            }
            else if(pt_error[1])
            {
                pt = pt_error[1];
                st = pt_error_str[1];
                pt_error[1] = NULL;
                continue;
            }
            else if(pt_error[0])
            {
                pt = pt_error[0];
                st = pt_error_str[0];
                pt_error[0] = NULL;
                continue;
            }
            else if(flags & BEGIN_SET)
            {
                /* If we get an error and the "^" option is
                 * set, we can return "not matched" in here.
                 */
                return(NULL);
            }
            else if(st_error)
            {
                st = st_error;
                st_error = NULL;
            }
            pt = pattern;
            r_code = NULL;
        
    }while(*(++st) != '\0');


    /* Matching for a possible last parenthesis */
    if(prts_closure)
    {
        while(!prts(*pt) && *pt != '\0')
        {
            if(*pt == BACKSLASH && *(pt+2) == '*')
                pt+=3;
            else
                break;    
        }
        
        if(prts(*pt))
        {
            prts_int = 0;
            while(prts_closure[prts_int])
            {
                if(prts_closure[prts_int] == pt)
                {
                    prts_str[prts_int] = st;
                    break;
                }
                prts_int++;
            }
        }
    }

    /* Cleaning up */
    if(ENDOFFILE(pt) || 
        (*pt == BACKSLASH && 
        _regex_matched && 
        (pt+=2) && 
        isPlus(*pt) && 
        (pt++) &&
        ((ENDOFFILE(pt)) || 
        ((*pt == BACKSLASH) && 
        (pt+=2) && 
        (*pt == '*') && 
        (pt++) && 
        (ENDOFFILE(pt)) ))) ||
        (*pt == BACKSLASH &&
        (pt+=2) &&
        (*pt == '*') &&
        (pt++) &&
        ENDOFFILE(pt))
        ) 
    {
        return(r_code);
    }
   
    return(NULL);
}
Пример #14
0
} // namespace


Embedder::QuantitationConfiguration::QuantitationConfiguration()
{
    NativeEmbedder::QuantitationConfiguration nativeConfig;
    this->QuantitationMethod = (IDPicker::QuantitationMethod) nativeConfig.quantitationMethod.value();
    ReporterIonMzTolerance = gcnew MZTolerance(nativeConfig.reporterIonMzTolerance.value, (MZTolerance::Units) nativeConfig.reporterIonMzTolerance.units);
    NormalizeIntensities = nativeConfig.normalizeIntensities;
}

Embedder::QuantitationConfiguration::QuantitationConfiguration(IDPicker::QuantitationMethod quantitationMethod, String^ settingsString)
{
    String^ pattern = "([\\d\\.]+)(\\w+) ; (\\d)";
    Regex^ rx = gcnew Regex(pattern);
    Match^ match = rx->Match(settingsString);
    if (match->Success)
    {
        MZTolerance::Units units = match->Groups[2]->Value->ToLower() == "mz" ? MZTolerance::Units::MZ : MZTolerance::Units::PPM;
        ReporterIonMzTolerance = gcnew MZTolerance(Double::Parse(match->Groups[1]->Value), units);
        NormalizeIntensities = (match->Groups[3]->Value == "1");
    }
    else
    {
        NativeEmbedder::QuantitationConfiguration nativeConfig;
        ReporterIonMzTolerance = gcnew MZTolerance(nativeConfig.reporterIonMzTolerance.value, (MZTolerance::Units) nativeConfig.reporterIonMzTolerance.units);
        NormalizeIntensities = nativeConfig.normalizeIntensities;
    }
    this->QuantitationMethod = quantitationMethod;
}
Пример #15
0
void Lexer::addDelimiters(const std::string& expr) {
    delimiters.push_back(Regex(expr));
}
Пример #16
0
void Lexer::addDelimiters(const std::initializer_list<char>& list) {
    for (char c : list) {
        delimiters.push_back(Regex("\\" + std::string(1, c)));
    }
}
Пример #17
0
void Lexer::addToken(const TokenType& tokenType, const Expression& expr) {
    tokenTypes.insert(std::make_pair(tokenType, Regex(expr)));
}