/*************************************************************************** regex_mod.cpp - description ------------------- begin : Wed Sep 14 13:03:46 2005 copyright : (C) 2002 by Cavalli Andrea email : cavalli@bioc.unizh.ch **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include //using namespace Almost; template<> inline string to_string(const boost::regex & exp){ return exp.str(); } boost::regex build(string r){ return boost::regex(r.c_str());} string regex_replace(const string & in, const boost::regex & re, const string & frm){ return boost::regex_replace(in,re,frm); } bool regex_contains(const string & in, const boost::regex & re){ return boost::regex_search(in,re); } vector regex_split(const string & in, const boost::regex & re){ vector res; boost::sregex_token_iterator i(in.begin(), in.end(), re, -1); boost::sregex_token_iterator j; while(i!=j){ res.push_back(*i); ++i; } return res; } extern "C" { void init_regex(){ //declarations here Module mod = Module("regex","Regular Expression Engine"); mod.def_function("regex","Regular expression constructor",build); mod.def_function("regex_replace","Replaces matches according to format string",regex_replace); mod.def_function("regex_contains","Return true if the string contains a sub-string that matches the regular expression",regex_contains); mod.def_function("regex_split","Splits the the input string according to the given regular expression",regex_split); } }