Boost logo

Boost :

From: Renato Tegon Forti (re.tf_at_[hidden])
Date: 2005-11-22 11:06:35


 

Hi All,

 

I have one system that receive many messages (TCP/IP transport) on one
second, and I validate these messages whit a sequence of if,s and switch’s,
see exemple of message:

19092;1;12345678;1111222233334444;123;0512;10000;1;0

 

I would like know if I use regex to do this I will have improvement in
performance of my system, or I will have delay in my system?

 

My regex to validate this message is:
"\\d{1,5};1;\\d{1,8};\\d{16};\\d{3};\\d{4};\\d{1,8};([0-9]|10|11|12);[012]"

 

My code sample (in old version I need same about 300 lines to do the same):

 

class CParser

{

public:

 

      CParser(const std::string& toparser, const RWDBDatabase &database)

      {

 
if(validate("\\d{1,5};1;\\d{1,8};\\d{16};\\d{3};\\d{4};\\d{1,8};([0-9]|10|11
|12);[012]", toparser))

            {

                  CContext<CProcessMessage1> process;

            }

            else if(validate("\\d{1,5};3;\\d{16};\\d{11};[01]", toparser))

            {


            }

            else if(validate("\\d{1,5};5;\\d{16};\\d{11}", toparser))

            {


            }

            else if(validate("\\d{1,5};7;\\d{16};\\d{11}", toparser))

            {


            }

            else

            {

                  throw CParserException("bad_message");

            }

      }

 

protected:

      

      bool validate(const std::string& regex, const std::string&
to_validate)

      {

            try

            {

                  const boost::regex e(regex);

                  return regex_match(to_validate.c_str(), e);

            }

            catch (...)

            {

                  throw CParserException("bad_regex_syntax");

            }

      }

 

};

 

Thanks to help

 

  _____

Esta mensagem foi verificada pelo E-mail Protegido Terra
<http://mail.terra.com.br/> .
Scan engine: McAfee VirusScan / Atualizado em 21/11/2005 / Versão:
4.4.00/4633
Proteja o seu e-mail Terra: http://mail.terra.com.br/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk