mirror of
				https://github.com/Laupetin/OpenAssetTools.git
				synced 2025-10-30 18:17:15 +00:00 
			
		
		
		
	Add Simple Parsing implementations for basic parsers
This commit is contained in:
		
							
								
								
									
										65
									
								
								src/Parser/Parsing/Impl/ParserInputStream.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								src/Parser/Parsing/Impl/ParserInputStream.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,65 @@ | ||||
| #include "ParserInputStream.h" | ||||
|  | ||||
| #include <sstream> | ||||
|  | ||||
| ParserInputStream::ParserInputStream(std::istream& stream, std::string fileName) | ||||
|     : m_stream(stream), | ||||
|       m_file_name(std::move(fileName)), | ||||
|       m_line_number(1) | ||||
| { | ||||
| } | ||||
|  | ||||
| ParserLine ParserInputStream::NextLine() | ||||
| { | ||||
|     std::ostringstream str; | ||||
|     auto hasLength = false; | ||||
|  | ||||
|     auto c = m_stream.get(); | ||||
|     while (c != EOF) | ||||
|     { | ||||
|         switch (c) | ||||
|         { | ||||
|         case '\r': | ||||
|             c = m_stream.get(); | ||||
|             if (c == '\n') | ||||
|                 return ParserLine(m_file_name, m_line_number++, str.str()); | ||||
|             str << '\r'; | ||||
|             hasLength = true; | ||||
|             continue; | ||||
|  | ||||
|         case '\n': | ||||
|             return ParserLine(m_file_name, m_line_number++, str.str()); | ||||
|  | ||||
|         default: | ||||
|             str << static_cast<char>(c); | ||||
|             hasLength = true; | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         c = m_stream.get(); | ||||
|     } | ||||
|  | ||||
|     if (hasLength) | ||||
|         return ParserLine(m_file_name, m_line_number, str.str()); | ||||
|  | ||||
|     return ParserLine(); | ||||
| } | ||||
|  | ||||
| bool ParserInputStream::IncludeFile(const std::string& filename) | ||||
| { | ||||
|     return false; | ||||
| } | ||||
|  | ||||
| void ParserInputStream::PopCurrentFile() | ||||
| { | ||||
| } | ||||
|  | ||||
| bool ParserInputStream::IsOpen() const | ||||
| { | ||||
|     return !m_stream.eof(); | ||||
| } | ||||
|  | ||||
| bool ParserInputStream::Eof() const | ||||
| { | ||||
|     return !m_stream.eof(); | ||||
| } | ||||
							
								
								
									
										21
									
								
								src/Parser/Parsing/Impl/ParserInputStream.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/Parser/Parsing/Impl/ParserInputStream.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <istream> | ||||
|  | ||||
| #include "Parsing/IParserLineStream.h" | ||||
|  | ||||
| class ParserInputStream final : public IParserLineStream | ||||
| { | ||||
|     std::istream& m_stream; | ||||
|     std::string m_file_name; | ||||
|     int m_line_number; | ||||
|  | ||||
| public: | ||||
|     ParserInputStream(std::istream& stream, std::string fileName); | ||||
|  | ||||
|     ParserLine NextLine() override; | ||||
|     bool IncludeFile(const std::string& filename) override; | ||||
|     void PopCurrentFile() override; | ||||
|     _NODISCARD bool IsOpen() const override; | ||||
|     _NODISCARD bool Eof() const override; | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user