随笔-60  评论-111  文章-0  trackbacks-0
#define szNumber "[+-]?[0-9]+"
#define szWord "[a-z_][a-z0-9\\_]*"
#define szOp "==?|\\+[=+]?|-[->=]?|\\*=?|/=?|\\|[|=]?|\\\\|\\~|!=?|\\&{1,2}|\\{|\\}|\\[|\\]|\\(|\\)|\\,|\\;|\\:{1,2}|\\?|<[<=]?|>[=>]?|."
#define szString "\".*?\""
#define szString2 "'.*?'"

#define szLineComment "//[^\\n\\r\\f]*"
#define szComment "/\\*[\\s\\S]*?\\*/"
#define szPre "#[^\\n\\r\\f]*"

#define rePack(v) "^\\s*("v")([\\s\\S]*)$"

void ss_dostring(std::string text)
{
    FILE 
* fp=fopen("out.ini","w+");
    
long pos=0;

    
const boost::regex reNumber(rePack(szNumber),boost::regbase::normal|boost::regbase::icase);
    
const boost::regex reWord(rePack(szWord),boost::regbase::normal|boost::regbase::icase);
    
const boost::regex reOp(rePack(szOp),boost::regbase::normal|boost::regbase::icase);
    
const boost::regex reString(rePack(szString),boost::regbase::normal|boost::regbase::icase);
    
const boost::regex reString2(rePack(szString2),boost::regbase::normal|boost::regbase::icase);
    
const boost::regex reLineComment(rePack(szLineComment),boost::regbase::normal|boost::regbase::icase);
    
const boost::regex reComment(rePack(szComment),boost::regbase::normal|boost::regbase::icase);
    
const boost::regex rePre(rePack(szPre),boost::regbase::normal|boost::regbase::icase);
    boost::smatch match;
    
while (true)
    
{
        
if ( boost::regex_match( text, match, reLineComment) )
        
{
            fprintf(fp,
"注释:     %s\n",match.str(1).c_str());
            text
=match.str(2);
            
continue;
        }

        
if ( boost::regex_match( text, match, reComment) )
        
{
            fprintf(fp,
"注释:     %s\n",match.str(1).c_str());
            text
=match.str(2);
            
continue;
        }

        
if ( boost::regex_match( text, match, rePre) )
        
{
            fprintf(fp,
"预处理:   %s\n",match.str(1).c_str());
            text
=match.str(2);
            
continue;
        }

        
if ( boost::regex_match( text, match, reNumber) )
        
{
            fprintf(fp,
"number:   %s\n",match.str(1).c_str());
            text
=match.str(2);
            
continue;
        }

        
if ( boost::regex_match( text, match, reWord) )
        
{
            fprintf(fp,
"reWord:   %s\n",match.str(1).c_str());
            text
=match.str(2);
            
continue;
        }

        
if ( boost::regex_match( text, match, reString) )
        
{
            fprintf(fp,
"String:   %s\n",match.str(1).c_str());
            text
=match.str(2);
            
continue;
        }

        
if ( boost::regex_match( text, match, reString2) )
        
{
            fprintf(fp,
"String:   %s\n",match.str(1).c_str());
            text
=match.str(2);
            
continue;
        }

        
if ( boost::regex_match( text, match, reOp) )
        
{
            fprintf(fp,
"Op:       %s\n",match.str(1).c_str());
            text
=match.str(2);
            
continue;
        }

        
break;
    }

    fprintf(fp,
"剩余:   %s\n",text.substr(0,20).c_str());

    fclose(fp);
}
posted on 2007-04-11 15:20 shaker(太子) 阅读(3103) 评论(0)  编辑 收藏 引用 所属分类: C++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理