/ webserv / practice / config / JsonParser.hpp
JsonParser.hpp
 1  #ifndef __JSONPARSER_HPP__
 2  #define __JSONPARSER_HPP__
 3  
 4  #include <fstream>
 5  #include <iostream>
 6  #include <string>
 7  
 8  #include "JsonData.hpp"
 9  
10  class JsonParser
11  {
12  	private:
13  		JsonData	_json;
14  
15  	public:
16  		JsonParser(void);
17  		~JsonParser(void);
18  
19  	public:
20  		JsonData const&						getJson(void) const;
21  		JsonData							parseJson(
22  												std::string const& filepath
23  											);
24  
25  	private:
26  		void								readFile(
27  												std::string const& filepath,
28  												std::string& output
29  											);
30  		std::pair<std::string, JsonData>	retriveKeyValuePair(
31  												std::string const& text,
32  												std::string::iterator& it
33  											);
34  		std::vector<JsonData>				parseArray(
35  												std::string const& text,
36  												std::string::iterator& it
37  											);
38  		JsonData							parseObject(
39  												std::string const& text,
40  												std::string::iterator& it
41  											);
42  		bool								checkElementEnd(
43  												std::string const& text,
44  												std::string::iterator& it
45  											);
46  		bool								checkKeyValueEnd(
47  												std::string const& text,
48  												std::string::iterator& it
49  											);
50  		std::string							parsePrimitive(
51  												std::string::iterator& it,
52  												jsonType& type
53  											);
54  		std::string							parseStringKey(
55  												std::string const& text,
56  												std::string::iterator& it
57  											);
58  		std::string							parseStringValue(
59  												std::string const& text,
60  												std::string::iterator& it
61  											);
62  		std::string							getStringData(
63  												std::string const& text,
64  												std::string::iterator& it
65  											);
66  		jsonType							getPrimitiveType(
67  												std::string const& str
68  											);
69  };
70  
71  #endif	/* __JSONPARSER_HPP__ */