#include "../include/sleela_regex.hpp" namespace sleela::regex { Pattern::Pattern(const std::string& p,std::regex_constants::syntax_option_type f){try{expression_=std::regex(p,f);valid_=true;}catch(const std::regex_error& e){valid_=false;error_=e.what();}} Pattern Pattern::ere(const std::string& p,bool icase){auto f=std::regex_constants::extended;if(icase)f|=std::regex_constants::icase;return Pattern(p,f);} static Span sp(const std::smatch& m,std::size_t i){Span s;if(i0&&m[0].matched;x.whole=sp(m,0);for(std::size_t i=1;i Pattern::split(const std::string& t)const{std::vector o;if(!valid_){o.push_back(t);return o;}std::sregex_token_iterator i(t.begin(),t.end(),expression_,-1),e;for(;i!=e;++i)o.push_back(*i);return o;} std::string Pattern::escape(const std::string& l){static const std::string m=".^$|()[]*+?{}\\";std::string o;for(char c:l){if(m.find(c)!=std::string::npos)o+='\\';o+=c;}return o;} }