Boost logo

Boost Users :

Subject: [Boost-users] [BOOST::XPRESSIVE] Trouble with functor in regex
From: Norbert Hauck (nhauck_at_[hidden])
Date: 2011-02-04 10:33:36


Hi,
I'm tinkering around with xpressive but have run into a problem. Warning: I'm rather unprofessionnal as a programmer so I might have overlooked something very simple - please bear with me!

------Code-----Code-------
#include "stdafx.h"
#include <boost/xpressive/xpressive_static.hpp>
#include <boost/xpressive/regex_actions.hpp>
#include <boost/xpressive/regex_primitives.hpp>
#include <string>
#include <iostream>

using namespace boost::xpressive;

class DateVerify_Impl
{
   public:
typedef int result_type;
                int operator()(const std::string& cap,wchar_t* pdate)const //val references currdate
                {
                        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))
                                        {
                                                //stringcopy cap to val
                                                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<DateVerify_Impl>::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;
}

-- 
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit 
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net