27 #ifndef TOMOGRAPHER_CONSTSTR_H
28 #define TOMOGRAPHER_CONSTSTR_H
59 template<std::
size_t N>
60 constexpr
conststr(
const char(&a)[N]) : _p(a), _sz(N - 1) {}
61 constexpr conststr(
const char *a,
std::size_t n) : _p(a), _sz(n) {}
63 inline constexpr
char operator[](
std::size_t n)
const
67 inline constexpr
std::size_t size()
const {
return _sz; }
69 inline constexpr
bool is_in_range(
std::size_t n)
const
71 return n < _sz ?
true :
false;
73 inline constexpr
bool check_range(
std::size_t n,
bool answer =
true)
const
80 return pos >= _sz ? _sz-1 : pos;
83 inline constexpr
bool startswith(
const conststr& s,
std::size_t StartOffset = 0,
std::size_t S_I = 0)
const {
84 return ((S_I >= s.size())
86 : (StartOffset+S_I < size() && s[S_I] == operator[](StartOffset+S_I)
87 ? startswith(s, StartOffset, S_I+1)
92 inline constexpr
bool operator==(
const conststr& other)
const {
93 return startswith(other) && other.size() == size();
97 return conststr(_p+pos, (pos > size() || count > size() || pos+count>size()) ? (size()-pos) : count);
100 return conststr(_p+pos, (end>size()) ? (size()-pos) : end-pos);
106 return (!is_in_range(pos)
108 : ( startswith(s, pos)
110 : (pos <= size()-s.size()
111 ? find(s, pos+1, not_found)
118 return ((s.size() > size())
120 : ((pos > size()-s.size())
121 ? rfind(s, size()-s.size(), not_found)
122 : ( startswith(s, pos)
125 ? rfind(s, pos-1, not_found)
Base namespace for the Tomographer project.