662ba0c904
selections are now defined with inclusive iterators, which means that Selection(cursor, cursor) is a valid selection of the charateter pointed by cursor. On the user interface side, that means that the cursor is now part of the selection, selectors were adapted to this behavior (and word selectors are now much more intuitive)
32 lines
854 B
C++
32 lines
854 B
C++
#include "regex_selector.hh"
|
|
#include "exception.hh"
|
|
|
|
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;
|
|
|
|
if (boost::regex_search(cursor, cursor.buffer().end(), matches, m_regex, boost::match_nosubs))
|
|
return Selection(matches.begin()->first, matches.begin()->second-1);
|
|
else if (boost::regex_search(cursor.buffer().begin(), cursor, matches, m_regex, boost::match_nosubs))
|
|
return Selection(matches.begin()->first, matches.begin()->second-1);
|
|
}
|
|
catch (boost::regex_error& err)
|
|
{
|
|
throw runtime_error("regex error");
|
|
}
|
|
|
|
return Selection(cursor, cursor);
|
|
}
|
|
|
|
}
|