...
This commit is contained in:
@@ -36,16 +36,27 @@ struct AdcStopSeqSessionProto {
|
||||
|
||||
typedef std::string proto_ident_t;
|
||||
|
||||
proto_ident_t ident() const { return "STOP SEQUENCE PROTO"; }
|
||||
proto_ident_t ident() const
|
||||
{
|
||||
return "STOP SEQUENCE PROTO";
|
||||
}
|
||||
|
||||
template <traits::adc_input_char_range R>
|
||||
auto search(const R& r)
|
||||
{
|
||||
std::tuple<std::ranges::iterator_t<R>, std::ranges::iterator_t<R>, bool> res{r.begin(), r.end(), false};
|
||||
|
||||
std::get<1>(res) = std::search(r.begin(), r.end(), STOP_SEQ.begin(), STOP_SEQ.end());
|
||||
if (std::get<1>(res) != r.end()) { // move iterator to the one-past-the-end position
|
||||
std::advance(std::get<1>(res), STOP_SEQ_SIZE);
|
||||
if (!r.size()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// std::get<1>(res) = std::search(r.begin(), r.end(), STOP_SEQ.begin(), STOP_SEQ.end());
|
||||
auto found = std::ranges::search(r, STOP_SEQ);
|
||||
// if (std::get<1>(res) != r.end()) { // move iterator to the one-past-the-end position
|
||||
if (!found.empty()) { // move iterator to the one-past-the-end position
|
||||
// std::advance(std::get<1>(res), STOP_SEQ_SIZE);
|
||||
// std::get<1>(res) = found.begin() + STOP_SEQ_SIZE;
|
||||
std::get<1>(res) = found.end();
|
||||
std::get<2>(res) = true;
|
||||
}
|
||||
|
||||
@@ -53,6 +64,28 @@ struct AdcStopSeqSessionProto {
|
||||
}
|
||||
|
||||
|
||||
template <std::input_iterator IT>
|
||||
std::pair<IT, bool> search(IT begin, IT end)
|
||||
{
|
||||
auto res = std::make_pair(begin, false);
|
||||
|
||||
if (begin == end) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res.first = std::search(begin, end, STOP_SEQ.begin(), STOP_SEQ.end());
|
||||
if (res.first != end) {
|
||||
std::advance(res.first, STOP_SEQ_SIZE); // move iterator to the one-past-the-end position
|
||||
res.second = true;
|
||||
} else {
|
||||
// may be only a part of valid byte sequence was received,
|
||||
// so start next matching from previous begin-iterator
|
||||
res.first = begin;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template <traits::adc_input_char_range R>
|
||||
auto toProto(const R& r)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user