c++ - Create functions at Run Time Or dispatch Right Function -


i have situation don't know how define it. have regular expression functions allow me extract specific patterns text: in total have 9 functions:

bool extractdate(const char *); bool extractheurefax(const char*); bool extractfaxphone(const char*); bool extractformepolitesse(const char*); bool extractcodepostal(const char*); bool extractdate2(const char*); bool extracttelephone2(const char*); bool extractnumbers(const char*); bool extractalphanumeric(const char*); bool extractnumeric(const char*); bool extractpagenumber(const char*); 

the problem each time want add regular expression have modify whole code not idea.

one of solution put regular expression in text file. each time want add new regular expression can add text file, , load them @ run time. every regular expression in text contains id , re example:

date: ^([0]?[1-9]|[1|2][0-9]|[3][0|1])([\\.\\-\\/\\ ])([0]?[1-9]|[1][0-2])([\\.\\-\\/\\ ])([0-9]{4}|[0-9]{2})$ heure: ([0-1][0-9]|[2][0-3]):([0-5][0-9])$ telephone: ^(01|02|03|04|05|06|08)(([\\.\\-\\/\\ ])?[0-9][0-9]){4} formule politesse: ^((c|c)ordialement|sinc(è|\u00e8)rement|sinc(è|\u00e8)re|croire|agr(é|\u00e9)er|agreer|l'expression|distingu(é|\u00e9)s|sentiments|salutations|consid(e|é|\u00e9)ration)$ code postal: ^((0[1-9])|([1-8][0-9])|(9[0-8])|(2a)|(2b))[0-9]{3}$ 

then save text in vector , try regular expressions until right 1 found.

inside code: that's how handle functions

                    if(extractdate(e->getname().c_str()))                     {                          e->settype(0);                      }                      else if(extractheurefax(e->getname().c_str()))                     {                          e->settype(1);                         //  int x0 = e->getxcenter();                         //  int y0 = e->getycenter();                         //  markpoints(xmlfile,x0,y0,20,0,255,0);                     }                     //telephone = bleu                     else if(extractfaxphone(e->getname().c_str()))                     {                         e->settype(2);                      }                      else if(extractcodepostal(e->getname().c_str()))                     {                         e->settype(3);                      } 

extractdate(), extractheurefax() etc.. regular expression functions:

bool keywords::extractcodepostal(const char * code) {     // cout <<"code postal"<<endl;     const boost::regex e("^((0[1-9])|([1-8][0-9])|(9[0-8])|(2a)|(2b))[0-9]{3}$");     return boost::regex_match(code,e); }///end function   bool keywords::extractdate2(const char*date2) {     const boost::regex e("((j|j)anvier|(f|f)\u00e9vrier|(f|f)évrier|(f|f)evrier|(m|m)ars|(a|a)vril|(m|m)ai|(j|j)uin|(j|j)uillet|juillet|(a|a)o\u00fbt|(a|a)oût|aout|(s|s)eptembre|(o|o)ctobre|(n|n)ovembre|(d|d)\u00e9cembre|(d|d)écembre|(d|d)ecembre|janvier|fevrier|mars|avril|mai|juin|juillet|aout|septembre|octobre|novembre|decembre)");     return boost::regex_match(date2,e); }///end function 

enter image description here


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -