2011-09-02 18:51:20 +02:00
|
|
|
#include "regex_selector.hh"
|
2011-09-09 20:40:59 +02:00
|
|
|
#include "exception.hh"
|
2011-09-02 18:51:20 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
RegexSelector::RegexSelector(const std::string& exp)
|
|
|
|
: m_regex(exp) {}
|
|
|
|
|
|
|
|
Selection RegexSelector::operator()(const BufferIterator& cursor) const
|
|
|
|
{
|
|
|
|
BufferIterator line_end = cursor + 1;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
boost::match_results<BufferIterator> matches;
|
|
|
|
|
2011-09-02 20:38:10 +02:00
|
|
|
if (boost::regex_search(cursor, cursor.buffer().end(), matches, m_regex, boost::match_nosubs))
|
2011-09-02 18:51:20 +02:00
|
|
|
return Selection(matches.begin()->first, matches.begin()->second);
|
|
|
|
}
|
|
|
|
catch (boost::regex_error& err)
|
|
|
|
{
|
2011-09-09 20:40:59 +02:00
|
|
|
throw runtime_error("regex error");
|
2011-09-02 18:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Selection(cursor, cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|