9 #ifndef ICARUSCODE_PMT_ALGORITHMS_PARSINGTOOLKIT_H
10 #define ICARUSCODE_PMT_ALGORITHMS_PARSINGTOOLKIT_H
17 #include <initializer_list>
19 #include <string_view>
26 namespace icarus {
struct ParsingToolkit; }
84 template <
int (*CCTF)(
int)>
86 template <
typename Ch>
88 {
return CCTF(static_cast<unsigned char>(c)); }
146 std::pair<std::string, unsigned int>
readMultiline(std::istream&
in)
const;
185 template <
typename Delim>
187 (std::string
const&
s, Delim isDelimiter)
const;
190 std::vector<std::string_view>
splitWords(std::string
const&
s)
const
204 template <
typename Iter>
215 template <
typename WordType>
217 { words.erase(
findCommentWord(words.begin(), words.end()), words.end()); }
226 (std::string_view sv)
const;
237 (std::string_view sv, std::string
const& quotEnd)
const;
263 template <
typename BIter,
typename EIter>
265 (std::string_view sv, BIter beginKey, EIter endKey)
const;
289 template <
typename Keys>
291 (std::string_view sv, Keys
const& keys)
const;
293 template <
typename Key>
295 (std::string_view sv, std::initializer_list<Key> keys)
const;
317 template <
typename BIter,
typename EIter>
319 (std::string_view sv, BIter beginKey, EIter endKey)
const;
339 template <
typename Keys>
341 (std::string_view sv, Keys
const& keys)
const;
343 template <
typename Key>
345 (std::string_view sv, std::initializer_list<Key> keys)
const;
364 static SplitView_t
splitOn(std::string_view sv, std::string_view sep);
387 template <
typename BIter>
400 template <
typename Sel>
402 (std::string_view
s, Sel select)
const;
416 template <
typename CType>
418 (std::string_view
s, CType charType)
const;
464 template <
typename Words>
465 std::vector<std::string>
removeEscapes(Words
const& words)
const;
502 template <
typename Words>
511 {
return make_view(s.begin(), s.end()); }
514 template <
typename BIter,
typename EIter>
516 {
return { &*b,
static_cast<std::size_t
>(
std::distance(b, e)) }; }
543 template <
typename Delim>
545 (std::string
const&
s, Delim isDelimiter )
const
560 Delim
const& isDelimiter;
561 std::string_view& sv;
562 std::vector<std::string_view> words;
563 std::string_view::const_iterator wStart;
565 WordTracker(
ParsingToolkit const& tk, Delim
const& d, std::string_view& sv)
566 : tk{ tk }, isDelimiter{ d }, sv{ consumeDelim(sv) }, wStart{ sv.begin() }
570 words.push_back(
make_view(wStart, sv.begin()));
571 wStart = consumeDelim().begin();
573 void moveEndTo(std::string_view::const_iterator it)
574 { moveEndBy(it - sv.begin()); }
575 void moveEndBy(std::size_t
n) { sv.remove_prefix(n); }
576 std::vector<std::string_view> finish()
577 {
if (wStart != sv.begin()) startNew();
return std::move(words); }
578 std::string_view& consumeDelim(std::string_view& s)
const
580 std::string_view& consumeDelim() {
return consumeDelim(sv); }
584 WordTracker words { *
this, isDelimiter, sv };
588 while (!sv.empty()) {
594 auto const qstart = qsv.begin();
602 if (sv.begin() == qstart)
break;
611 assert(sv.substr(0, qptr->first.length()) == qptr->first);
613 words.moveEndBy(qptr->first.length());
617 words.moveEndTo(quotEnd.begin());
620 if (!quotEnd.empty()) words.moveEndBy(qptr->second.length());
626 return words.finish();
632 template <
typename BIter,
typename EIter>
634 (std::string_view sv, BIter beginKey, EIter endKey)
const
637 typename std::iterator_traits<BIter>::value_type
const* key =
nullptr;
638 std::size_t keyPos = std::string_view::npos;
640 for (
auto iKey = beginKey; iKey != endKey; ++iKey) {
643 while (pos < sv.length()) {
644 pos = sv.find(*iKey, pos);
649 if (pos >= std::min(keyPos, sv.length()))
continue;
657 std::size_t
const keyLength =
make_view(*key).length();
658 return { sv.data() + keyPos, keyLength };
660 else return { sv.data() + sv.length(), 0 };
665 template <
typename Keys>
667 (std::string_view sv, Keys
const& keys)
const
675 template <
typename Key>
677 (std::string_view sv, std::initializer_list<Key> keys)
const
682 template <
typename BIter,
typename EIter>
684 (std::string_view sv, BIter beginKey, EIter endKey)
const
689 auto findKey = [
this,beginKey,endKey]
690 (std::string_view::const_iterator b, std::string_view::const_iterator
e)
693 std::string_view key{ sv.data() + sv.length(), 0 };
694 while (!sv.empty()) {
700 key = findKey(sv.begin(), fromQ.begin());
701 if (!key.empty())
break;
707 sv.remove_prefix(qptr->first.length());
712 if (afterQ.empty()) {
714 key = findKey(fromQ.begin(), fromQ.end());
720 sv.remove_prefix(qptr->second.length());
730 template <
typename Keys>
732 (std::string_view sv, Keys
const& keys)
const
740 template <
typename Key>
742 (std::string_view sv, std::initializer_list<Key> keys)
const
747 template <
typename Iter>
750 for (
auto it = beginWord; it != endWord; ++it) {
759 template <
typename Iter>
762 unsigned int nEscapes = 0U;
763 while (itCh-- != begin) {
770 return (nEscapes & 1) == 1;
776 template <
typename Sel>
778 (std::string_view s, Sel selector)
const
780 auto const sbegin = s.begin(), send = s.end();
783 it = std::find_if(it, send, selector);
792 template <
typename CType>
794 (std::string_view s, CType charType)
const
800 if (!charType(s.front()))
break;
808 template <
typename Words>
810 (Words
const& words)
const
813 std::vector<std::string> nv;
814 nv.reserve(
size(words));
821 template <
typename Words>
823 (Words
const& words)
const
826 std::vector<std::string> nv;
827 nv.reserve(
size(words));
835 #endif // ICARUSCODE_PMT_ALGORITHMS_PARSINGTOOLKIT_H
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
std::size_t size(FixedBins< T, C > const &) noexcept
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
auto end(FixedBins< T, C > const &) noexcept
auto begin(FixedBins< T, C > const &) noexcept
bool equal(double a, double b)
Comparison tolerance, in centimeters.
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
then echo File list $list not found else cat $list while read file do echo $file sed s