Exemplo n.º 1
0
QString QgsWfsCapabilities::NormalizeSRSName( QString crsName )
{
  QRegExp re( "urn:ogc:def:crs:([^:]+).+([^:]+)", Qt::CaseInsensitive );
  if ( re.exactMatch( crsName ) )
  {
    return re.cap( 1 ) + ':' + re.cap( 2 );
  }
  // urn:x-ogc:def:crs:EPSG:xxxx as returned by http://maps.warwickshire.gov.uk/gs/ows? in WFS 1.1
  QRegExp re2( "urn:x-ogc:def:crs:([^:]+).+([^:]+)", Qt::CaseInsensitive );
  if ( re2.exactMatch( crsName ) )
  {
    return re2.cap( 1 ) + ':' + re2.cap( 2 );
  }
  return crsName;
}
Exemplo n.º 2
0
int GoogleAppsMailbox::loginRequest()
{
    //const QRegExp moorhuntHashRegex("(<<a[a-h].*>>)");


    page = doGet("https://www.google.com/a/"+getMailbox());
    int pos = 0;
    QRegExp re3("GALX\\\".*value=\\\"(.*)\\\"./>");
    re3.setMinimal(true);
    if (re3.indexIn(page, pos) == -1)
        return 1;

    //LOG(Log::Info, page);
    const QString vars = QString("ltmpl=default&ltmplcache=2&continue=")
                + escape("https://mail.google.com/a/"+getMailbox()+"/")
                +"&service=mail&GALX="
                + escape(re3.cap(1))
                +"&rm=false&hl=pl&Email="+escape(getUser())
                +"&Passwd="+escape(getPassword())
                +"&rmShown=1";
    page = doPost("https://www.google.com/a/"+getMailbox()+"/LoginAction2?service=mail",vars, true);

    QString username = getUser();

    QRegExp re(username);
    QRegExp re2("&amp;");
    QRegExp authre("auth=([\\w\\d-]+)"); // To Do

    if (re.indexIn(page, pos) != -1)
    {
        QString url = re.cap(1);

        LOG(Log::Info, page + " <f");
        if(url.indexOf("answer=40695") != -1)
        {
            LOG(Log::Info, "Niestety, konto zostało wyłączone. - " + getMailbox());
            return 1;
        }
        url.replace(re2, "&");
        url = unescape(url);
        if (authre.indexIn(page, pos) != -1)
            auth = authre.cap(1);
            LOG(Log::Info, auth + " <s");
        return 0;
    }
    else
        return 1;
}
Exemplo n.º 3
0
void RockComMailbox::getHeadersRequest()
{
// 	LOG_ENTER("RockComMailbox::getHeadersRequest");
	std::string url("http://mymail.rock.com/scripts/mail/mailbox.mail?folder=INBOX"),page;
// 	setState(Mailbox::ReadHeadersIP); // request headers
	totalEmails = 0;
	pgcnt=0;
	page=doGet(url + auth);
	while(1)
	{
		//cout << "Read Headers In Progress" << endl;
		boost::match_results<std::string::const_iterator> match;
//		regex mheadre("<a href=\"/scripts/mail/(.*?) onclick=.+?title=\"(?:<B> )(.*?)(?: </B>)\">");
		boost::regex mheadre("<a href=\"/scripts/mail/(.*?) onclick=.+?title=\"(?:<B>)*(.*?)(?: </B>)*\">");
		std::string::const_iterator pbegin = page.begin();
		std::string::const_iterator pend = page.end();
		while (boost::regex_search(pbegin, pend, match, mheadre, boost::match_default))
		{
			EmailHeader hdr(match[1], match[2]);
			//cout << match[2] << endl;
//			LOG(Log::Debug, "Found header: " + hdr.subject);
	//		cout << hdr.subject << endl;
			addHeader(hdr);
			addHeaderLink(match[1]);
			pbegin = match[2].second;
		}
        boost::regex re2("<a href=\"/scripts/[^<>]*\"><img src=\"http://img1.us4.outblaze.com/rock.com/nextPg.gif\"");
        boost::smatch match2;

		if (!boost::regex_search(page,match,re2))
		{
// 			setState(Mailbox::ReadHeadersDone);
			break;
		}
		else
		{
			//cout << match[2] << endl;
			std::stringstream numstr;
			pgcnt++;
			numstr << pgcnt*50+1;
			std::string url = "http://mymail.rock.com/scripts/mail/mailbox.mail?folder=INBOX&order=Newest&.ob=2013874a6a87e3165de301dc859da6acf78d4520&mview=a&mstart="+numstr.str()+";";
			page=doGet(url);
		}
	}
}
Exemplo n.º 4
0
TEST(RegularExpressionTest, extract)
{
	std::string s;
	Poco::RegularExpression re1("[0-9]+");
	Poco::RegularExpression re2("([0-9]+) ([0-9]+)");

	EXPECT_EQ(1, re1.extract("123", s));
	EXPECT_EQ("123", s);

	EXPECT_EQ(1, re1.extract("ab12de", 0, s));
	EXPECT_EQ("12", s);

	EXPECT_EQ(0, re1.extract("abcd", 0, s));
	EXPECT_EQ("", s);

	std::vector<std::string> vec;
	re2.split("123 456", 0, vec);
	// FIXME: split?
	EXPECT_EQ("123 456", vec[0]);
	EXPECT_EQ("123", vec[1]);
	EXPECT_EQ("456", vec[2]);
}
Exemplo n.º 5
0
/// Find the most appropriate configuration file for a given run
/// @param run :: run number
std::string EQSANSLoad::findConfigFile(const int& run)
{
  // Append the standard location of EQSANS config file to the data search directory list
  std::string sns_folder = "/SNS/EQSANS/shared/instrument_configuration";
  if (Poco::File(sns_folder).exists())
    Kernel::ConfigService::Instance().appendDataSearchDir(sns_folder);

  const std::vector<std::string>& searchPaths =
      Kernel::ConfigService::Instance().getDataSearchDirs();
  std::vector<std::string>::const_iterator it = searchPaths.begin();

  int max_run_number = 0;
  std::string config_file = "";
  Poco::RegularExpression re1("eqsans_configuration.[0-9]+");
  Poco::RegularExpression re2("[0-9]+");
  for (; it != searchPaths.end(); ++it)
  {
    Poco::DirectoryIterator file_it(*it);
    Poco::DirectoryIterator end;
    for (; file_it != end; ++file_it)
    {
      if (re1.match(file_it.name()))
      {
        std::string s;
        if (re2.extract(file_it.name(), s)==1)
        {
          int run_number = 0;
          Poco::NumberParser::tryParse(s, run_number);
          if (run_number > max_run_number && run_number <= run)
          {
            max_run_number = run_number;
            config_file = file_it.path().toString();
          }
        }
      }
    }
  }
  return config_file;
}
Exemplo n.º 6
0
static void parseClass(const QString& name, const QString& in)
      {
      Class cl;
      cl.name = name;

      QStringList sl = in.split("\n");
      QStringList methodDescription;

      QRegExp re("@P ([^\\s]+)\\s+([^\\s]+)(.*)");

      // matches Q_INVOKABLE void mops(int a);   // comment
      QRegExp re1("Q_INVOKABLE +([^ ]+) +([^;]+); */*(.*)");
      QRegExp re2("Q_INVOKABLE +([^ ]+) +([^\\{]+)\\{");
      QRegExp re3("Q_INVOKABLE +([^ ]+) +(\\w+\\([^\\)]*\\))\\s+const\\s*([^\\{]*)\\{");

      QRegExp reD("//@ (.*)");
      QRegExp re4 ("class +(\\w+) *: *public +(\\w+) *\\{");
      QRegExp re4b("class +(\\w+) *: *public +(\\w+), *public");

      Q_ASSERT(re1.isValid() && re2.isValid() && re3.isValid());

      bool parseClassDescription = true;

      foreach(const QString& s, sl) {
            if (re.indexIn(s, 0) != -1) {             //@P
                  parseClassDescription = false;
                  Prop p;
                  p.name        = re.cap(1);
                  p.type        = re.cap(2);
                  p.description = re.cap(3);
                  cl.props.append(p);
                  }
            else if (re2.indexIn(s, 0) != -1) {
                  parseClassDescription = false;
                  Proc p;
                  p.type        = re2.cap(1);
                  p.name        = re2.cap(2);
                  p.description = methodDescription;
                  methodDescription.clear();
                  cl.procs.append(p);
                  }
            else if (re1.indexIn(s, 0) != -1) {
                  parseClassDescription = false;
                  Proc p;
                  p.type        = re1.cap(1);
                  p.name        = re1.cap(2);
                  p.description = methodDescription;
                  methodDescription.clear();
                  cl.procs.append(p);
                  }
            else if (re3.indexIn(s, 0) != -1) {
                  parseClassDescription = false;
                  Proc p;
                  p.type        = re3.cap(1);
                  p.name        = re3.cap(2);
                  p.description = methodDescription;
                  methodDescription.clear();
                  cl.procs.append(p);
                  }
            else if ((reD.indexIn(s, 0) != -1)) {
                  if (parseClassDescription)
                        cl.description.append(reD.cap(1));
                  else
                        methodDescription.append(reD.cap(1));
                  }
            else if (s.startsWith("///")) {
                  QString ss = s.mid(3);
                  if (parseClassDescription)
                        cl.description.append(ss);
                  else
                        methodDescription.append(ss);
                  }
            else if (re4.indexIn(s, 0) != -1) {
                  parseClassDescription = false;
                  QString parent = re4.cap(2).simplified();
                  if (name == re4.cap(1).simplified()) {
                        cl.parent = parent;
                        }
                  else {
                        printf("?<%s>!=<%s> derived from <%s>\n",
                           qPrintable(name), qPrintable(re4.cap(1).simplified()), qPrintable(parent));
                        }
                  }
            else if (re4b.indexIn(s, 0) != -1) {
                  parseClassDescription = false;
                  QString parent = re4b.cap(2).simplified();
                  if (name == re4b.cap(1).simplified()) {
                        cl.parent = parent;
                        }
                  else {
                        printf("?<%s>!=<%s> derived from <%s>\n",
                           qPrintable(name), qPrintable(re4b.cap(1).simplified()), qPrintable(parent));
                        }
                  }
            }
      classes.append(cl);
      }
Exemplo n.º 7
0
//-----------------------------------------------------------------
QString Utils::formatString(const QString filename,
                            const Utils::FormatConfiguration &conf,
                            bool add_mp3_extension)
{
  // works for filenames and plain strings
  QString formattedName = filename;

  auto fileInfo = QFileInfo(filename);
  if(fileInfo.exists())
  {
    formattedName = fileInfo.absoluteFilePath().split('/').last();

    auto extension = formattedName.split('.').last();
    auto extension_id = QString("*.") + extension;
    bool identified = WAVE_FILE_EXTENSIONS.contains(extension_id)   ||
                      MODULE_FILE_EXTENSIONS.contains(extension_id) ||
                      MOVIE_FILE_EXTENSIONS.contains(extension_id);

    if (identified)
    {
      formattedName.remove(formattedName.lastIndexOf('.'), extension.length() + 1);
    }
  }

  if (conf.apply)
  {
    // delete specified chars
    for (int i = 0; i < conf.chars_to_delete.length(); ++i)
    {
      formattedName.remove(conf.chars_to_delete[i], Qt::CaseInsensitive);
    }

    // replace specified strings
    for (int i = 0; i < conf.chars_to_replace.size(); ++i)
    {
      auto charPair = conf.chars_to_replace[i];
      formattedName.replace(charPair.first, charPair.second, Qt::CaseInsensitive);
    }

    // remove consecutive spaces
    QStringList parts = formattedName.split(' ');
    parts.removeAll("");

    formattedName.clear();
    int index = 0;

    // adjust the number prefix and insert the default separator.
    // Format 1: 01 ...
    QRegExp re1("\\d*");
    auto re1_match = re1.exactMatch(parts[index]);

    // Format 2: 1-01 ...
    QRegExp re2("\\d-\\d*");
    auto re2_match = re2.exactMatch(parts[index]);

    // only check number format if it exists
    if (re1_match || re2_match)
    {
      QString number_string, number_disc_id;
      if(re1_match)
      {
        number_string = parts[index];
      }
      else
      {
        auto splits = parts[index].split('-');
        number_disc_id = splits.first();
        number_string = splits.last();
      }

      while (conf.number_of_digits > number_string.length())
      {
        number_string = "0" + number_string;
      }

      if (index != parts.size() - 1)
      {
        if(parts[index + 1] != QString(conf.number_and_name_separator))
        {
          number_string += QString(' ' + conf.number_and_name_separator + ' ');
        }
        else
        {
          parts[index + 1] = QString(' ' + conf.number_and_name_separator);
        }
      }

      if(!number_disc_id.isEmpty() && conf.prefix_disk_num)
      {
        number_string = number_disc_id + QString("-") + number_string;
      }
      formattedName = number_string;
      ++index;
    }

    // capitalize the first letter of every word
    if (conf.to_title_case)
    {
      int i = index;
      while (i < parts.size())
      {
        if (parts[i].isEmpty()) continue;
        bool starts_with_parenthesis = false;
        bool ends_with_parenthesis = false;
        bool starts_with_quote = false;
        bool ends_with_quote = false;
        int begin_quote_num = 0;
        int end_quote_num = 0;

        if(parts[i].startsWith('(') && parts[i].size() > 1)
        {
          starts_with_parenthesis = true;
          parts[i].remove('(');
        }

        if(parts[i].endsWith(')') && parts[i].size() > 1)
        {
          ends_with_parenthesis = true;
          parts[i].remove(')');
        }
        
        if(parts[i].startsWith('\'') && parts[i].size() > 1)
        {
          starts_with_quote = true;
          while(parts[i].at(begin_quote_num) == QChar('\'') && begin_quote_num < parts[i].size())
          {
            ++begin_quote_num;
          }
        }
        
        if(parts[i].endsWith('\'') && parts[i].size() > 1)
        {
          ends_with_quote = true;
          auto part_size = parts[i].size() - 1;
          while(parts[i].at(part_size - end_quote_num) == QChar('\'') && end_quote_num < parts[i].size())
          {
            ++end_quote_num;
          }
        }

        if(starts_with_quote || ends_with_quote)
        {
          parts[i].remove(QChar('\''));
        }

        if(!isRomanNumeral(parts[i]))
        {
          parts[i] = parts[i].toLower();
          parts[i].replace(0, 1, parts[i].at(0).toUpper());
        }

        if(starts_with_quote)
        {
          while(begin_quote_num > 0)
          {
            parts[i].insert(0, QChar('\''));
            --begin_quote_num;
          }
        }

        if(ends_with_quote)
        {
          while(end_quote_num > 0)
          {
            parts[i].append(QChar('\''));
            --end_quote_num;
          }
        }

        if (starts_with_parenthesis)
        {
          parts[i] = QString('(') + parts[i];
        }

        if (ends_with_parenthesis)
        {
          parts[i] = parts[i] + QString(')');
        }

        ++i;
      }
    }

    if(index < parts.size())
    {
      formattedName += parts[index++];
    }

    // compose the name.
    while (index < parts.size())
    {
      formattedName += ' ' + parts[index++];
    }
  }

  if(add_mp3_extension)
  {
    formattedName += ".mp3";
  }

  // remove any unwanted spaces
  formattedName = formattedName.simplified();

  // check for unwanted unicode chars
  while(formattedName.toLatin1().contains('?'))
  {
    auto index = formattedName.toLatin1().indexOf('?');

    switch(formattedName.at(index).category())
    {
      case QChar::Punctuation_InitialQuote:
      case QChar::Punctuation_FinalQuote:
        formattedName = formattedName.replace(formattedName.at(index), QString("''"));
        break;
      case QChar::Punctuation_Dash:
        formattedName = formattedName.replace(formattedName.at(index), '-');
        break;
      default:
        formattedName = formattedName.replace(formattedName.at(index), ' ');
    }
  }

  return formattedName;
}
Exemplo n.º 8
0
void regexp_pme()
{
   static const char *underline =
      "----------------------------------------------------------------\n";


   // Match tests

   {
      printf("Global matching\n%s", underline);
      TPMERegexp re("ba[rz]", "g");
      TString m("foobarbaz");
      while (re.Match(m))
         re.Print("all");
      printf("\n");

      printf("Global matching with back-refs\n%s", underline);
      TPMERegexp re1("(ba[rz])", "g");
      TString m1("foobarbaz");
      while (re1.Match(m1))
         re1.Print("all");
      printf("\n");

      printf("Matching with nested back-refs\n%s", underline);
      TPMERegexp re2("([\\w\\.-]+)@((\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+))");
      TString m2("[email protected]");
      re2.Match(m2);
      re2.Print("all");
      printf("\n");
   }


   // Split tests

   {
      printf("Split\n%s", underline);
      TPMERegexp re(":");
      TString m("root:x:0:0:root:/root:/bin/bash");
      re.Split(m);
      re.Print("all");
      printf("\n");

      printf("Split with maxfields=5\n%s", underline);
      re.Split(m, 5);
      re.Print("all");
      printf("\n");

      printf("Split with empty elements in the middle and at the end\n"
             "maxfields=0, so trailing empty elements are dropped\n%s", underline);
      m = "root::0:0:root:/root::";
      re.Split(m);
      re.Print("all");
      printf("\n");

      printf("Split with empty elements at the beginning and end\n"
             "maxfields=-1, so trailing empty elements are kept\n%s", underline);
      m = ":x:0:0:root::";
      re.Split(m, -1);
      re.Print("all");
      printf("\n");

      printf("Split with no pattern in string\n%s", underline);
      m = "A dummy line of text.";
      re.Split(m);
      re.Print("all");
      printf("\n");
   }

   {
      printf("Split with regexp potentially matching a null string \n%s", underline);
      TPMERegexp re(" *");
      TString m("hi there");
      re.Split(m);
      re.Print("all");
      printf("\n");
   }

   {
      printf("Split on patteren with back-refs\n%s", underline);
      TPMERegexp re("([,-])");
      TString m("1-10,20");
      re.Split(m);
      re.Print("all");
      printf("\n");
   }


   // Substitute tests

   {
      printf("Substitute\n%s", underline);
      TPMERegexp re("(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)");
      TString m("137.138.170.210");
      TString r("$4.$3.$2.$1");
      TString s(m); re.Substitute(s, r);
      re.Print();
      printf("Substitute '%s','%s' => '%s'\n", m.Data(), r.Data(), s.Data());
      printf("\n");
   }

   {
      printf("Global substitute\n%s", underline);
      TPMERegexp re("(\\w+)\\.(\\w+)@[\\w\\.-]+", "g");
      TString m("[email protected], [email protected], [email protected]");
      TString r("\\u$1 \\U$2\\E");
      TString s(m); re.Substitute(s, r);
      re.Print();
      printf("Substitute '%s','%s' => '%s'\n", m.Data(), r.Data(), s.Data());
      printf("\n");
   }
}
int main() {

{
//! [0]
QRegularExpression re("a pattern");
//! [0]
}

{
//! [1]
QRegularExpression re;
re.setPattern("another pattern");
//! [1]
}

{
//! [2]
// matches two digits followed by a space and a word
QRegularExpression re("\\d\\d \\w+");

// matches a backslash
QRegularExpression re2("\\\\");
//! [2]
}

{
//! [3]
QRegularExpression re("a third pattern");
QString pattern = re.pattern(); // pattern == "a third pattern"
//! [3]
}

{
//! [4]
// matches "Qt rocks", but also "QT rocks", "QT ROCKS", "qT rOcKs", etc.
QRegularExpression re("Qt rocks", QRegularExpression::CaseInsensitiveOption);
//! [4]
}

{
//! [5]
QRegularExpression re("^\\d+$");
re.setPatternOptions(QRegularExpression::MultilineOption);
// re matches any line in the subject string that contains only digits (but at least one)
//! [5]
}

{
//! [6]
QRegularExpression re = QRegularExpression("^two.*words$", QRegularExpression::MultilineOption
                                                           | QRegularExpression::DotMatchesEverythingOption);

QRegularExpression::PatternOptions options = re.patternOptions();
// options == QRegularExpression::MultilineOption | QRegularExpression::DotMatchesEverythingOption
//! [6]
}

{
//! [7]
// match two digits followed by a space and a word
QRegularExpression re("\\d\\d \\w+");
QRegularExpressionMatch match = re.match("abc123 def");
bool hasMatch = match.hasMatch(); // true
//! [7]
}

{
//! [8]
QRegularExpression re("\\d\\d \\w+");
QRegularExpressionMatch match = re.match("abc123 def");
if (match.hasMatch()) {
    QString matched = match.captured(0); // matched == "23 def"
    // ...
}
//! [8]
}

{
//! [9]
QRegularExpression re("\\d\\d \\w+");
QRegularExpressionMatch match = re.match("12 abc 45 def", 1);
if (match.hasMatch()) {
    QString matched = match.captured(0); // matched == "45 def"
    // ...
}
//! [9]
}

{
//! [10]
QRegularExpression re("^(\\d\\d)/(\\d\\d)/(\\d\\d\\d\\d)$");
QRegularExpressionMatch match = re.match("08/12/1985");
if (match.hasMatch()) {
    QString day = match.captured(1); // day == "08"
    QString month = match.captured(2); // month == "12"
    QString year = match.captured(3); // year == "1985"
    // ...
}
//! [10]
}

{
//! [11]
QRegularExpression re("abc(\\d+)def");
QRegularExpressionMatch match = re.match("XYZabc123defXYZ");
if (match.hasMatch()) {
    int startOffset = match.capturedStart(1); // startOffset == 6
    int endOffset = match.capturedEnd(1); // endOffset == 9
    // ...
}
//! [11]
}

{
//! [12]
QRegularExpression re("^(?<date>\\d\\d)/(?<month>\\d\\d)/(?<year>\\d\\d\\d\\d)$");
QRegularExpressionMatch match = re.match("08/12/1985");
if (match.hasMatch()) {
    QString date = match.captured("date"); // date == "08"
    QString month = match.captured("month"); // month == "12"
    QString year = match.captured("year"); // year == 1985
}
//! [12]
}

{
//! [13]
QRegularExpression re("(\\w+)");
QRegularExpressionMatchIterator i = re.globalMatch("the quick fox");
//! [13]

//! [14]
QStringList words;
while (i.hasNext()) {
    QRegularExpressionMatch match = i.next();
    QString word = match.captured(1);
    words << word;
}
// words contains "the", "quick", "fox"
//! [14]
}

{
//! [15]
QString pattern("^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d\\d?, \\d\\d\\d\\d$");
QRegularExpression re(pattern);

QString input("Jan 21,");
QRegularExpressionMatch match = re.match(input, 0, QRegularExpression::PartialPreferCompleteMatch);
bool hasMatch = match.hasMatch(); // false
bool hasPartialMatch = match.hasPartialMatch(); // true
//! [15]
}

{
QString pattern("^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d\\d?, \\d\\d\\d\\d$");
QRegularExpression re(pattern);
//! [16]
QString input("Dec 8, 1985");
QRegularExpressionMatch match = re.match(input, 0, QRegularExpression::PartialPreferCompleteMatch);
bool hasMatch = match.hasMatch(); // true
bool hasPartialMatch = match.hasPartialMatch(); // false
//! [16]
}

{
//! [17]
QRegularExpression re("abc\\w+X|def");
QRegularExpressionMatch match = re.match("abcdef", 0, QRegularExpression::PartialPreferCompleteMatch);
bool hasMatch = match.hasMatch(); // true
bool hasPartialMatch = match.hasPartialMatch(); // false
QString captured = match.captured(0); // captured == "def"
//! [17]
}

{
//! [18]
QRegularExpression re("abc\\w+X|defY");
QRegularExpressionMatch match = re.match("abcdef", 0, QRegularExpression::PartialPreferCompleteMatch);
bool hasMatch = match.hasMatch(); // false
bool hasPartialMatch = match.hasPartialMatch(); // true
QString captured = match.captured(0); // captured == "abcdef"
//! [18]
}

{
//! [19]
QRegularExpression re("abc|ab");
QRegularExpressionMatch match = re.match("ab", 0, QRegularExpression::PartialPreferFirstMatch);
bool hasMatch = match.hasMatch(); // false
bool hasPartialMatch = match.hasPartialMatch(); // true
//! [19]
}

{
//! [20]
QRegularExpression re("abc(def)?");
QRegularExpressionMatch match = re.match("abc", 0, QRegularExpression::PartialPreferFirstMatch);
bool hasMatch = match.hasMatch(); // false
bool hasPartialMatch = match.hasPartialMatch(); // true
//! [20]
}

{
//! [21]
QRegularExpression re("(abc)*");
QRegularExpressionMatch match = re.match("abc", 0, QRegularExpression::PartialPreferFirstMatch);
bool hasMatch = match.hasMatch(); // false
bool hasPartialMatch = match.hasPartialMatch(); // true
//! [21]
}

{
//! [22]
QRegularExpression invalidRe("(unmatched|parenthesis");
bool isValid = invalidRe.isValid(); // false
//! [22]
}

{
//! [23]
QRegularExpression invalidRe("(unmatched|parenthesis");
if (!invalidRe.isValid()) {
    QString errorString = invalidRe.errorString(); // errorString == "missing )"
    int errorOffset = invalidRe.patternErrorOffset(); // errorOffset == 22
    // ...
}
//! [23]
}

{
//! [24]
QRegularExpression re("^this pattern must match exactly$");
//! [24]
}

{
//! [25]
QString p("a .*|pattern");
QRegularExpression re("\\A(?:" + p + ")\\z"); // re matches exactly the pattern string p
//! [25]
}

{
//! [26]
QString escaped = QRegularExpression::escape("a(x) = f(x) + g(x)");
// escaped == "a\\(x\\)\\ \\=\\ f\\(x\\)\\ \\+\\ g\\(x\\)"
//! [26]
}

{
QString name;
QString nickname;
//! [27]
QString pattern = "(" + QRegularExpression::escape(name) +
                  "|" + QRegularExpression::escape(nickname) + ")";
QRegularExpression re(pattern);
//! [27]
}

{
QString string;
QRegularExpression re;
//! [28]
QRegularExpressionMatch match = re.match(string);
for (int i = 0; i <= match.lastCapturedIndex(); ++i) {
    QString captured = match.captured(i);
    // ...
}
//! [28]
}

{
//! [29]
QRegularExpression re("(\\d\\d) (?<name>\\w+)");
QRegularExpressionMatch match = re.match("23 Jordan");
if (match.hasMatch()) {
    QString number = match.captured(1); // first == "23"
    QString name = match.captured("name"); // name == "Jordan"
}
//! [29]
}

{
//! [30]
// extracts the words
QRegularExpression re("(\\w+)");
QString subject("the quick fox");
QRegularExpressionMatchIterator i = re.globalMatch(subject);
while (i.hasNext()) {
    QRegularExpressionMatch match = i.next();
    // ...
}
//! [30]
}

}
Exemplo n.º 10
0
Settings::Settings()
{
  static_assert(TEAM_BLUE == blue && TEAM_RED == red && TEAM_YELLOW == yellow && TEAM_BLACK == black
                && TEAM_WHITE == white && TEAM_GREEN == green && TEAM_ORANGE == orange
                && TEAM_PURPLE == purple && TEAM_BROWN == brown && TEAM_GRAY == gray,
                "These macros and enums have to match!");
  if(!loaded)
  {
    VERIFY(settings.load());
    loaded = true;
  }
  *this = settings;

#ifdef TARGET_SIM
  if(SystemCall::getMode() == SystemCall::simulatedRobot)
  {
    int index = atoi(RoboCupCtrl::controller->getRobotName().c_str() + 5) - 1;
    teamNumber = index < 6 ? 1 : 2;
    teamPort = 10000 + teamNumber;
    teamColor = index < 6
                ? TeamColor(RoboCupCtrl::controller->gameController.teamInfos[0].teamColor)
                : TeamColor(RoboCupCtrl::controller->gameController.teamInfos[1].teamColor);
    playerNumber = index % 6 + 1;
  }

  headName = bodyName = "Nao";

  ConsoleRoboCupCtrl* ctrl = dynamic_cast<ConsoleRoboCupCtrl*>(RoboCupCtrl::controller);
  if(ctrl)
  {
    std::string logFileName = ctrl->getLogFile();
    if(logFileName != "")
    {
      QRegExp re1("([A-Za-z]*)_([A-Za-z]*)__", Qt::CaseSensitive, QRegExp::RegExp2);
      QRegExp re2("([A-Za-z]*)_([A-Za-z]*)_([A-Za-z0-9]*)_([A-Za-z0-9]*)__");
      QRegExp re3("_([0-9][0-9]*)(_\\([0-9][0-9]*\\)){0,1}\\.");

      int pos1 = re1.indexIn(logFileName.c_str());
      int pos2 = re2.indexIn(logFileName.c_str());
      int pos3 = re3.indexIn(logFileName.c_str());

      if(pos2 != -1)
      {
        headName = re2.capturedTexts()[1].toUtf8().constData();
        bodyName = re2.capturedTexts()[2].toUtf8().constData();
        scenario = re2.capturedTexts()[3].toUtf8().constData();
        location = re2.capturedTexts()[4].toUtf8().constData();
      }
      else if(pos1 != -1)
      {
        headName = re1.capturedTexts()[1].toUtf8().constData();
        bodyName = re1.capturedTexts()[2].toUtf8().constData();
      }
      else
        bodyName = headName = "Default";

      if(pos3 != -1)
        playerNumber = re3.capturedTexts()[1].toUtf8().constData()[0] - '0';
    }
  }
#endif
}
Exemplo n.º 11
0
inline qm_real atsmodel<N>::future(qm_real t, qm_real T1, qm_real T2, qm_real tau) const  {
	REXPONENT  re  = this->fwdexp(t,T1,T2,1.0);
	REXPONENT  re2(new rexponent(t,T1,0));
	m_model->rcumulant(re->b,re2);
	return (std::exp(re->a+re2->value(m_model->charFactors())) - 1.)/tau;
}