25#ifndef __DCONV_PROBE_HPP__
26#define __DCONV_PROBE_HPP__
37#define DCONV_LIKELY(x) __builtin_expect ((x), 1)
38#define DCONV_UNLIKELY(x) __builtin_expect ((x), 0)
39#define DCONV_COLD __attribute__ ((cold, noinline))
59 , _end (in ? in + count : in)
82 , _end (in ? in +
std::char_traits<char>::length (in) : in)
121 inline int peek () const noexcept
125 return static_cast<unsigned char> (*_cur);
127 return std::char_traits<char>::eof ();
134 inline int get () noexcept
138 return static_cast<unsigned char> (*_cur++);
140 return std::char_traits<char>::eof ();
148 inline bool getIf (
char expected)
noexcept
167 const char c = *_cur;
168 if ((c | 32) == (expected | 32))
183 inline size_t readDigits (uint64_t& value,
size_t max = std::numeric_limits<size_t>::max ()) noexcept
185 const char* cur = _cur;
186 const char*
end = (
static_cast<size_t> (_end - _cur) > max) ? _cur + max : _end;
189 while ((
end - cur >= 8) &&
190 (std::memcpy (&word, cur, 8),
191 ((word & 0xF0F0F0F0F0F0F0F0ULL) |
192 (((word + 0x0606060606060606ULL) & 0xF0F0F0F0F0F0F0F0ULL) >> 4)) == 0x3333333333333333ULL))
194 word = ((word & 0x0F0F0F0F0F0F0F0FULL) * 2561) >> 8;
195 word = ((word & 0x00FF00FF00FF00FFULL) * 6553601) >> 16;
196 word = ((word & 0x0000FFFF0000FFFFULL) * 42949672960001ULL) >> 32;
197 value = (value * 100000000) + word;
201 while ((cur <
end) && (
static_cast<unsigned char> (*cur -
'0') < 10))
203 value = (value * 10) + (*cur++ -
'0');
206 size_t count = cur - _cur;
217 inline size_t read (
char* buf,
size_t count)
noexcept
219 const size_t available = _end - _cur;
220 const size_t nread = (count < available) ? count : available;
221 std::memcpy (buf, _cur, nread);
266 const char* _cur =
nullptr;
269 const char* _beg =
nullptr;
272 const char* _end =
nullptr;
325 inline int peek () const noexcept
327 return _in->sgetc ();
334 inline int get () noexcept
336 return _in->sbumpc ();
344 inline bool getIf (
char expected)
noexcept
346 if (_in->sgetc () ==
static_cast<int> (
static_cast<unsigned char> (expected)))
361 const int c = _in->sgetc ();
364 if ((
static_cast<char> (c) | 32) == (expected | 32))
379 inline size_t readDigits (uint64_t& value,
size_t max = std::numeric_limits<size_t>::max ()) noexcept
382 while ((count < max) && (
static_cast<unsigned> (
peek () -
'0') < 10))
384 value = (value * 10) + (
get () -
'0');
396 inline size_t read (
char* buf,
size_t count)
noexcept
398 return _in->sgetn (buf, count);
stream probe.
Definition probe.hpp:279
int peek() const noexcept
get character without extracting it.
Definition probe.hpp:325
bool getIf(char expected) noexcept
extracts expected character.
Definition probe.hpp:344
~StreamProbe()=default
destroy instance.
StreamProbe(std::istream &in)
default constructor.
Definition probe.hpp:285
StreamProbe(const StreamProbe &other)=delete
copy constructor.
size_t readDigits(uint64_t &value, size_t max=std::numeric_limits< size_t >::max()) noexcept
read consecutive digits.
Definition probe.hpp:379
StreamProbe & operator=(const StreamProbe &other)=delete
copy assignment.
StreamProbe(StreamProbe &&other)=delete
move constructor.
size_t read(char *buf, size_t count) noexcept
read characters.
Definition probe.hpp:396
int get() noexcept
extracts character.
Definition probe.hpp:334
bool getIfNoCase(char expected) noexcept
extracts expected character (case insensitive, ASCII-only).
Definition probe.hpp:359
string probe.
Definition probe.hpp:47
size_t readDigits(uint64_t &value, size_t max=std::numeric_limits< size_t >::max()) noexcept
read consecutive digits.
Definition probe.hpp:183
ProbePos end() const noexcept
get end position indicator.
Definition probe.hpp:239
StringProbe(const StringProbe &other)=default
copy constructor.
void seek(ProbePos pos) noexcept
seek to the specified position.
Definition probe.hpp:248
~StringProbe()=default
destroy instance.
bool getIf(char expected) noexcept
extracts expected character.
Definition probe.hpp:148
size_t read(char *buf, size_t count) noexcept
read characters.
Definition probe.hpp:217
ProbePos tell() const noexcept
get input position indicator.
Definition probe.hpp:230
StringProbe & operator=(const StringProbe &other)=default
copy assignment.
bool getIfNoCase(char expected) noexcept
extracts expected character (case insensitive, ASCII-only).
Definition probe.hpp:163
int peek() const noexcept
get character without extracting it.
Definition probe.hpp:121
int get() noexcept
extracts character.
Definition probe.hpp:134
constexpr StringProbe(const char *in, size_t count)
default constructor.
Definition probe.hpp:56
StringProbe(const char *in)
default constructor.
Definition probe.hpp:79
const char * ProbePos
Definition probe.hpp:49
StringProbe(StringProbe &&other)=default
move constructor.
constexpr StringProbe(const char *first, const char *last)
default constructor.
Definition probe.hpp:68
#define DCONV_LIKELY(x)
Definition probe.hpp:37