// df1.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #include using namespace boost::xpressive; class DateVerify_Impl { public: typedef int result_type; int operator()(const std::string& cap,wchar_t* pdate)const { int yy = (cap[0]-'0')*1000 + (cap[1]-'0')*100 + (cap[2]-'0')*10 + (cap[3]-'0'); int mm = (cap[5]-'0')*10 + (cap[6]-'0'); int dd = (cap[8]-'0')*10 + (cap[9]-'0'); if ((yy > 2003 && yy < 2099) && (mm > 0 && mm < 13) && (dd > 0 && dd < 32)) { const int ddinmonth[] = {31,29,31,30,31,30,31,31,30,31,30,31}; if (ddinmonth[(mm-1)] >= dd) { if (!(mm == 2 && dd == 29) || ((yy%400 ? yy%100 ? yy%4 ? false : true : false :true) == 1)) { size_t convertedChars = 0; mbstowcs_s(&convertedChars,pdate,11,cap.c_str(),_TRUNCATE); return 1; } else return 0; } else return 0; } } }; int _tmain(int argc, _TCHAR* argv[]) { wchar_t currdate[11]; std::string date = "2011/02/02"; function::type const dverify = {{}}; mark_tag datetag(1); smatch mtch; sregex tcrgx = bos >> (datetag= (repeat<4>(_d) >> '/' >> repeat<2>(_d) >> '/' >> repeat<2>(_d))) [check(dverify(datetag,&currdate) == 1)] >> eos; if (regex_match(date,mtch,tcrgx)) std::wcout << "YO BABY, YO !" << " ... and the winner is " << currdate << '\n'; return 0; }