correctly handle boost::regex_error in selectors
This commit is contained in:
parent
583de3ba6e
commit
0a385885ff
|
@ -367,49 +367,48 @@ SelectionAndCaptures select_whole_buffer(const Selection& selection)
|
||||||
SelectionAndCaptures select_next_match(const Selection& selection,
|
SelectionAndCaptures select_next_match(const Selection& selection,
|
||||||
const std::string& regex)
|
const std::string& regex)
|
||||||
{
|
{
|
||||||
boost::regex ex(regex);
|
try
|
||||||
|
{
|
||||||
BufferIterator begin = selection.last();
|
BufferIterator begin = selection.last();
|
||||||
BufferIterator end = begin;
|
BufferIterator end = begin;
|
||||||
CaptureList captures;
|
CaptureList captures;
|
||||||
|
|
||||||
try
|
boost::regex ex(regex);
|
||||||
{
|
|
||||||
boost::match_results<BufferIterator> matches;
|
boost::match_results<BufferIterator> matches;
|
||||||
|
|
||||||
if (boost::regex_search(begin+1, begin.buffer().end(), matches,
|
if (boost::regex_search(begin+1, begin.buffer().end(),
|
||||||
ex))
|
matches, ex))
|
||||||
{
|
{
|
||||||
begin = matches[0].first;
|
begin = matches[0].first;
|
||||||
end = matches[0].second;
|
end = matches[0].second;
|
||||||
std::copy(matches.begin(), matches.end(),
|
std::copy(matches.begin(), matches.end(),
|
||||||
std::back_inserter(captures));
|
std::back_inserter(captures));
|
||||||
}
|
}
|
||||||
else if (boost::regex_search(begin.buffer().begin(), begin+1, matches,
|
else if (boost::regex_search(begin.buffer().begin(), begin+1,
|
||||||
ex))
|
matches, ex))
|
||||||
{
|
{
|
||||||
begin = matches[0].first;
|
begin = matches[0].first;
|
||||||
end = matches[0].second;
|
end = matches[0].second;
|
||||||
std::copy(matches.begin(), matches.end(),
|
std::copy(matches.begin(), matches.end(),
|
||||||
std::back_inserter(captures));
|
std::back_inserter(captures));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (boost::regex_error& err)
|
|
||||||
{
|
|
||||||
throw runtime_error("regex error");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (begin == end)
|
if (begin == end)
|
||||||
++end;
|
++end;
|
||||||
|
|
||||||
return SelectionAndCaptures(begin, end - 1, std::move(captures));
|
return SelectionAndCaptures(begin, end - 1, std::move(captures));
|
||||||
}
|
}
|
||||||
|
catch (boost::regex_error& err)
|
||||||
|
{
|
||||||
|
throw runtime_error(std::string("regex error: ") + err.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
typedef boost::regex_iterator<BufferIterator> RegexIterator;
|
typedef boost::regex_iterator<BufferIterator> RegexIterator;
|
||||||
|
|
||||||
SelectionAndCapturesList select_all_matches(const Selection& selection,
|
SelectionAndCapturesList select_all_matches(const Selection& selection,
|
||||||
const std::string& regex)
|
const std::string& regex)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
boost::regex ex(regex);
|
boost::regex ex(regex);
|
||||||
RegexIterator re_it(selection.begin(), selection.end(), ex);
|
RegexIterator re_it(selection.begin(), selection.end(), ex);
|
||||||
|
@ -423,14 +422,22 @@ SelectionAndCapturesList select_all_matches(const Selection& selection,
|
||||||
|
|
||||||
CaptureList captures(re_it->begin(), re_it->end());
|
CaptureList captures(re_it->begin(), re_it->end());
|
||||||
|
|
||||||
result.push_back(SelectionAndCaptures(begin, begin == end ? end : end-1,
|
result.push_back(SelectionAndCaptures(begin,
|
||||||
|
begin == end ? end : end-1,
|
||||||
std::move(captures)));
|
std::move(captures)));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
catch (boost::regex_error& err)
|
||||||
|
{
|
||||||
|
throw runtime_error(std::string("regex error: ") + err.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SelectionAndCapturesList split_selection(const Selection& selection,
|
SelectionAndCapturesList split_selection(const Selection& selection,
|
||||||
const std::string& separator_regex)
|
const std::string& separator_regex)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
boost::regex ex(separator_regex);
|
boost::regex ex(separator_regex);
|
||||||
RegexIterator re_it(selection.begin(), selection.end(), ex,
|
RegexIterator re_it(selection.begin(), selection.end(), ex,
|
||||||
|
@ -449,5 +456,10 @@ SelectionAndCapturesList split_selection(const Selection& selection,
|
||||||
result.push_back(Selection(begin, selection.last()));
|
result.push_back(Selection(begin, selection.last()));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
catch (boost::regex_error& err)
|
||||||
|
{
|
||||||
|
throw runtime_error(std::string("regex error: ") + err.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user