25#ifndef JOIN_DATA_VIEW_HPP
26#define JOIN_DATA_VIEW_HPP
51 for (
unsigned i = 0; i < 0x20; ++i)
95 , _end (in ? in + count : in)
118 , _end (in ? in +
std::char_traits<char>::length (in) : in)
157 inline int peek () const noexcept
161 return static_cast<unsigned char> (*_cur);
163 return std::char_traits<char>::eof ();
170 inline int get () noexcept
174 return static_cast<unsigned char> (*_cur++);
176 return std::char_traits<char>::eof ();
184 inline bool getIf (
char expected)
noexcept
186 if (
JOIN_LIKELY (_cur < _end) && (*_cur == expected))
203 const char c = *_cur;
204 if ((c | 32) == (expected | 32))
219 inline size_t read (
char* buf,
size_t count)
noexcept
221 const size_t available = _end - _cur;
222 const size_t nread = (count < available) ? count : available;
223 std::memcpy (buf, _cur, nread);
234 const char* beg = _cur;
235 const char* cur = _cur;
236 const char* end = _end;
243 out.append (beg,
static_cast<size_t> (cur - beg));
253 const char* cur = _cur;
254 const char* end = _end;
272 const char* cur = _cur;
273 const char* end = _end;
282 if (cur >= end || *cur !=
'/')
298 if (*cur ==
'*' && (cur + 1 < end) && *(cur + 1) ==
'/')
311 else if (*cur ==
'/')
314 const char* p =
static_cast<const char*
> (memchr (cur,
'\n', end - cur));
359 const char* _cur =
nullptr;
362 const char* _beg =
nullptr;
365 const char* _end =
nullptr;
371 template <
bool Seekable = true>
421 inline int peek () const noexcept
423 return _in->sgetc ();
430 inline int get () noexcept
432 return _in->sbumpc ();
440 inline bool getIf (
char expected)
noexcept
442 if (_in->sgetc () ==
static_cast<int> (
static_cast<unsigned char> (expected)))
457 const int c = _in->sgetc ();
458 if (
JOIN_LIKELY (c != std::char_traits<char>::eof ()))
460 if ((
static_cast<char> (c) | 32) == (expected | 32))
475 inline size_t read (
char* buf,
size_t count)
noexcept
477 return _in->sgetn (buf, count);
487 while ((c = _in->sgetc ()) != std::char_traits<char>::eof () &&
490 out.push_back (
static_cast<char> (c));
502 while ((c = _in->sgetc ()) != std::char_traits<char>::eof () &&
519 while ((c = _in->sgetc ()) != std::char_traits<char>::eof ())
521 while ((c = _in->sgetc ()) != std::char_traits<char>::eof () &&
535 if (c == std::char_traits<char>::eof ())
545 while ((c = _in->sbumpc ()) != std::char_traits<char>::eof ())
547 if (c ==
'*' && _in->sgetc () ==
'/')
564 while ((c = _in->sbumpc ()) != std::char_traits<char>::eof () && c !=
'\n')
581 template <
bool S = Seekable>
582 inline typename std::enable_if<S, ViewPos>::type
tell () const noexcept
584 return _in->pubseekoff (0, std::ios::cur, std::ios::in);
591 template <
bool S = Seekable>
592 inline typename std::enable_if<S, void>::type
seek (
ViewPos pos)
noexcept
594 _in->pubseekpos (pos, std::ios::in);
621 template <
typename ViewType>
645 template <typename ViewType, bool Seekable = is_seekable<ViewType>::value>
651 template <
typename ViewType>
661 , _beg (view.tell ())
669 inline int peek () const noexcept
671 return _view.peek ();
678 inline int get () noexcept
688 inline bool getIf (
char expected)
noexcept
690 return _view.getIf (expected);
700 return _view.getIfNoCase (expected);
709 size_t len = _view.tell () - _beg;
713 _view.read (&out[0], len);
723 _beg = _view.tell ();
731 typename ViewType::ViewPos _beg;
737 template <
typename ViewType>
748 static thread_local std::vector<char> buffer;
758 inline int peek () const noexcept
760 return _view.peek ();
767 inline int get () noexcept
769 const int c = _view.get ();
770 if (
JOIN_LIKELY (c != std::char_traits<char>::eof ()))
772 _buf->push_back (
static_cast<char> (c));
782 inline bool getIf (
char expected)
noexcept
784 if (_view.peek () ==
static_cast<int> (
static_cast<unsigned char> (expected)))
786 _buf->push_back (
static_cast<char> (_view.get ()));
799 const int c = _view.peek ();
800 if (
JOIN_LIKELY (c != std::char_traits<char>::eof ()))
802 if ((
static_cast<char> (c) | 32) == (expected | 32))
804 _buf->push_back (
static_cast<char> (_view.get ()));
817 out.assign (_buf->data (), _buf->size ());
835 std::vector<char>* _buf =
nullptr;
basic stream view.
Definition view.hpp:373
int get() noexcept
extracts character.
Definition view.hpp:430
std::enable_if< S, void >::type seek(ViewPos pos) noexcept
seek to the specified position.
Definition view.hpp:592
BasicStreamView(const BasicStreamView &other)=delete
copy constructor.
size_t read(char *buf, size_t count) noexcept
read characters.
Definition view.hpp:475
BasicStreamView(BasicStreamView &&other)=delete
move constructor.
void readUntilEscaped(std::string &out) noexcept
read characters until escaped.
Definition view.hpp:484
std::enable_if< S, ViewPos >::type tell() const noexcept
get input position indicator.
Definition view.hpp:582
std::streampos ViewPos
Definition view.hpp:375
~BasicStreamView()=default
destroy instance.
int skipWhitespaces() noexcept
skip whitespaces.
Definition view.hpp:499
int skipWhitespacesAndComments() noexcept
skip whitespaces and comments.
Definition view.hpp:515
int peek() const noexcept
get character without extracting it.
Definition view.hpp:421
bool getIf(char expected) noexcept
extracts expected character.
Definition view.hpp:440
BasicStreamView & operator=(const BasicStreamView &other)=delete
copy assignment.
BasicStreamView(std::istream &in)
default constructor.
Definition view.hpp:381
bool getIfNoCase(char expected) noexcept
extracts expected character (case insensitive, ASCII-only).
Definition view.hpp:455
BufferingView(ViewType &view)
default constructor.
Definition view.hpp:745
bool getIfNoCase(char expected) noexcept
extracts expected character (case insensitive, ASCII-only).
Definition view.hpp:797
void consume(std::string &out)
consume buffered data.
Definition view.hpp:824
void snapshot(std::string &out)
get snapshot.
Definition view.hpp:815
int peek() const noexcept
get character without extracting it.
Definition view.hpp:758
bool getIf(char expected) noexcept
extracts expected character.
Definition view.hpp:782
int get() noexcept
extracts character.
Definition view.hpp:767
int get() noexcept
extracts character.
Definition view.hpp:678
void consume(std::string &out)
consume buffered data.
Definition view.hpp:720
int peek() const noexcept
get character without extracting it.
Definition view.hpp:669
void snapshot(std::string &out)
get snapshot.
Definition view.hpp:707
bool getIfNoCase(char expected) noexcept
extracts expected character (case insensitive, ASCII-only).
Definition view.hpp:698
BufferingView(ViewType &view)
default constructor.
Definition view.hpp:659
bool getIf(char expected) noexcept
extracts expected character.
Definition view.hpp:688
buffering view adapter
Definition view.hpp:646
string view.
Definition view.hpp:83
bool getIfNoCase(char expected) noexcept
extracts expected character (case insensitive, ASCII-only).
Definition view.hpp:199
void readUntilEscaped(std::string &out) noexcept
read characters until escaped.
Definition view.hpp:232
StringView & operator=(const StringView &other)=default
copy assignment.
StringView(const StringView &other)=default
copy constructor.
StringView(const char *in)
default constructor.
Definition view.hpp:115
const char * ViewPos
Definition view.hpp:85
constexpr StringView(const char *in, size_t count)
default constructor.
Definition view.hpp:92
StringView(StringView &&other)=default
move constructor.
int peek() const noexcept
get character without extracting it.
Definition view.hpp:157
ViewPos tell() const noexcept
get input position indicator.
Definition view.hpp:332
~StringView()=default
destroy instance.
void seek(ViewPos pos) noexcept
seek to the specified position.
Definition view.hpp:341
size_t read(char *buf, size_t count) noexcept
read characters.
Definition view.hpp:219
int skipWhitespaces() noexcept
skip whitespaces.
Definition view.hpp:251
int skipWhitespacesAndComments() noexcept
skip whitespaces and comments.
Definition view.hpp:270
int get() noexcept
extracts character.
Definition view.hpp:170
bool getIf(char expected) noexcept
extracts expected character.
Definition view.hpp:184
constexpr StringView(const char *first, const char *last)
default constructor.
Definition view.hpp:104
constexpr WhitespaceTable whitespaceLookup
Definition view.hpp:76
constexpr EscapedTable escapedLookup
Definition view.hpp:60
Definition acceptor.hpp:32
uint8_t data[256]
Definition view.hpp:46
constexpr EscapedTable()
Definition view.hpp:48
constexpr WhitespaceTable()
Definition view.hpp:66
uint8_t data[256]
Definition view.hpp:64
trait to determine if a view type is seekable.
Definition view.hpp:623
#define JOIN_LIKELY(x)
Definition utils.hpp:46