77#include < cstddef>
88#include < cstring>
99#include < memory>
10+ #include < string>
1011
1112#include " config.hpp"
1213#include " eol.hpp"
@@ -23,30 +24,29 @@ namespace tao
2324{
2425 namespace TAOCPP_JSON_PEGTL_NAMESPACE
2526 {
26- template < typename Reader, typename Eol = lf_crlf_eol >
27+ template < typename Reader, typename Eol = lf_crlf_eol, typename Source = std::string >
2728 class buffer_input
2829 {
2930 public:
31+ static constexpr tracking_mode tracking_mode_v = tracking_mode::IMMEDIATE;
3032 using reader_t = Reader;
33+
3134 using eol_t = Eol;
35+ using source_t = Source;
36+
37+ using iterator_t = internal::iterator;
3238
33- using memory_t = memory_input< Eol >;
34- using action_t = internal::action_input< Eol , tracking_mode::IMMEDIATE >;
39+ using memory_t = memory_input< tracking_mode::IMMEDIATE, Eol, Source >;
40+ using action_t = internal::action_input< buffer_input , tracking_mode::IMMEDIATE >;
3541
3642 template < typename ... As >
37- buffer_input ( const char * in_source, const std::size_t maximum, As&&... as )
43+ buffer_input ( Source in_source, const std::size_t maximum, As&&... as )
3844 : m_reader( std::forward< As >( as )... ),
3945 m_maximum ( maximum ),
4046 m_buffer( new char [ maximum ] ),
41- m_data ( { 0 , 1 , 0 , m_buffer.get () } ),
47+ m_current ( { 0 , 1 , 0 , m_buffer.get () } ),
4248 m_end( m_buffer.get() ),
43- m_source( in_source )
44- {
45- }
46-
47- template < typename ... As >
48- buffer_input ( const std::string& in_source, As&&... as )
49- : buffer_input( in_source.c_str(), std::forward< As >( as )... )
49+ m_source( std::move( in_source ) )
5050 {
5151 }
5252
@@ -56,18 +56,18 @@ namespace tao
5656 bool empty ()
5757 {
5858 require ( 1 );
59- return m_data .data == m_end;
59+ return m_current .data == m_end;
6060 }
6161
6262 std::size_t size ( const std::size_t amount )
6363 {
6464 require ( amount );
65- return std::size_t ( m_end - m_data .data );
65+ return std::size_t ( m_end - m_current .data );
6666 }
6767
68- const char * begin () const noexcept
68+ const char * current () const noexcept
6969 {
70- return m_data .data ;
70+ return m_current .data ;
7171 }
7272
7373 const char * end ( const std::size_t amount )
@@ -78,27 +78,27 @@ namespace tao
7878
7979 std::size_t byte () const noexcept
8080 {
81- return m_data .byte ;
81+ return m_current .byte ;
8282 }
8383
8484 std::size_t line () const noexcept
8585 {
86- return m_data .line ;
86+ return m_current .line ;
8787 }
8888
8989 std::size_t byte_in_line () const noexcept
9090 {
91- return m_data .byte_in_line ;
91+ return m_current .byte_in_line ;
9292 }
9393
94- const char * source () const noexcept
94+ const Source& source () const noexcept
9595 {
9696 return m_source;
9797 }
9898
9999 char peek_char ( const std::size_t offset = 0 ) const noexcept
100100 {
101- return m_data .data [ offset ];
101+ return m_current .data [ offset ];
102102 }
103103
104104 unsigned char peek_byte ( const std::size_t offset = 0 ) const noexcept
@@ -108,32 +108,32 @@ namespace tao
108108
109109 void bump ( const std::size_t in_count = 1 ) noexcept
110110 {
111- internal::bump ( m_data , in_count, Eol::ch );
111+ internal::bump ( m_current , in_count, Eol::ch );
112112 }
113113
114114 void bump_in_this_line ( const std::size_t in_count = 1 ) noexcept
115115 {
116- internal::bump_in_this_line ( m_data , in_count );
116+ internal::bump_in_this_line ( m_current , in_count );
117117 }
118118
119119 void bump_to_next_line ( const std::size_t in_count = 1 ) noexcept
120120 {
121- internal::bump_to_next_line ( m_data , in_count );
121+ internal::bump_to_next_line ( m_current , in_count );
122122 }
123123
124124 void discard () noexcept
125125 {
126- const auto s = m_end - m_data .data ;
127- std::memmove ( m_buffer.get (), m_data .data , s );
128- m_data .data = m_buffer.get ();
126+ const auto s = m_end - m_current .data ;
127+ std::memmove ( m_buffer.get (), m_current .data , s );
128+ m_current .data = m_buffer.get ();
129129 m_end = m_buffer.get () + s;
130130 }
131131
132132 void require ( const std::size_t amount )
133133 {
134- if ( m_data .data + amount > m_end ) {
135- if ( m_data .data + amount <= m_buffer.get () + m_maximum ) {
136- if ( const auto r = m_reader ( const_cast < char * >( m_end ), amount - std::size_t ( m_end - m_data .data ) ) ) {
134+ if ( m_current .data + amount > m_end ) {
135+ if ( m_current .data + amount <= m_buffer.get () + m_maximum ) {
136+ if ( const auto r = m_reader ( const_cast < char * >( m_end ), amount - std::size_t ( m_end - m_current .data ) ) ) {
137137 m_end += r;
138138 }
139139 else {
@@ -144,28 +144,33 @@ namespace tao
144144 }
145145
146146 template < rewind_mode M >
147- internal::marker< internal::iterator, M > mark () noexcept
147+ internal::marker< iterator_t , M > mark () noexcept
148+ {
149+ return internal::marker< iterator_t , M >( m_current );
150+ }
151+
152+ TAOCPP_JSON_PEGTL_NAMESPACE::position position ( const iterator_t & it ) const noexcept
148153 {
149- return internal::marker< internal::iterator, M >( m_data );
154+ return TAOCPP_JSON_PEGTL_NAMESPACE::position ( it, m_source );
150155 }
151156
152157 TAOCPP_JSON_PEGTL_NAMESPACE::position position () const noexcept
153158 {
154- return TAOCPP_JSON_PEGTL_NAMESPACE:: position ( m_data, m_source );
159+ return position ( m_current );
155160 }
156161
157- const internal::iterator & iterator () const noexcept
162+ const iterator_t & iterator () const noexcept
158163 {
159- return m_data ;
164+ return m_current ;
160165 }
161166
162167 private:
163168 Reader m_reader;
164169 std::size_t m_maximum;
165170 std::unique_ptr< char [] > m_buffer;
166- internal::iterator m_data ;
171+ iterator_t m_current ;
167172 const char * m_end;
168- const char * const m_source;
173+ const Source m_source;
169174 };
170175
171176 } // namespace TAOCPP_JSON_PEGTL_NAMESPACE
0 commit comments