1 // Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
2 // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
3 
4 #ifndef TAO_PEGTL_POSITION_HPP
5 #define TAO_PEGTL_POSITION_HPP
6 
7 #include <cstdlib>
8 #include <ostream>
9 #include <sstream>
10 #include <string>
11 #include <utility>
12 
13 #include "config.hpp"
14 
15 #include "internal/iterator.hpp"
16 
17 namespace tao
18 {
19    namespace TAO_PEGTL_NAMESPACE
20    {
21       struct position
22       {
23          template< typename T >
positiontao::TAO_PEGTL_NAMESPACE::position24          position( const internal::iterator& in_iter, T&& in_source )
25             : byte( in_iter.byte ),
26               line( in_iter.line ),
27               byte_in_line( in_iter.byte_in_line ),
28               source( std::forward< T >( in_source ) )
29          {
30          }
31 
32          std::size_t byte;
33          std::size_t line;
34          std::size_t byte_in_line;
35          std::string source;
36       };
37 
operator <<(std::ostream & o,const position & p)38       inline std::ostream& operator<<( std::ostream& o, const position& p )
39       {
40          return o << p.source << ':' << p.line << ':' << p.byte_in_line << '(' << p.byte << ')';
41       }
42 
to_string(const position & p)43       inline std::string to_string( const position& p )
44       {
45          std::ostringstream o;
46          o << p;
47          return o.str();
48       }
49 
50    }  // namespace TAO_PEGTL_NAMESPACE
51 
52 }  // namespace tao
53 
54 #endif
55