28 #ifndef TOMOGRAPHER_CONSTSTR_H 29 #define TOMOGRAPHER_CONSTSTR_H 60 template<std::
size_t N>
61 constexpr
conststr(
const char(&a)[N]) : _p(a), _sz(N - 1) {}
62 constexpr conststr(
const char *a,
std::size_t n) : _p(a), _sz(n) {}
64 inline constexpr
char operator[](
std::size_t n)
const 68 inline constexpr
std::size_t size()
const {
return _sz; }
70 inline constexpr
bool is_in_range(
std::size_t n)
const 72 return n < _sz ?
true :
false;
74 inline constexpr
bool check_range(
std::size_t n,
bool answer =
true)
const 81 return pos >= _sz ? _sz-1 : pos;
84 inline constexpr
bool startswith(
const conststr& s,
std::size_t StartOffset = 0,
std::size_t S_I = 0)
const {
85 return ((S_I >= s.size())
87 : (StartOffset+S_I < size() && s[S_I] == operator[](StartOffset+S_I)
88 ? startswith(s, StartOffset, S_I+1)
93 inline constexpr
bool operator==(
const conststr& other)
const {
94 return startswith(other) && other.size() == size();
98 return conststr(_p+pos, (pos > size() || count > size() || pos+count>size()) ? (size()-pos) : count);
101 return conststr(_p+pos, (end>size()) ? (size()-pos) : end-pos);
107 return (!is_in_range(pos)
109 : ( startswith(s, pos)
111 : (pos <= size()-s.size()
112 ? find(s, pos+1, not_found)
119 return ((s.size() > size())
121 : ((pos > size()-s.size())
122 ? rfind(s, size()-s.size(), not_found)
123 : ( startswith(s, pos)
126 ? rfind(s, pos-1, not_found)
Base namespace for the Tomographer project.