inicpp
C++ parser of INI files with schema validation.
parser.h
1 #ifndef INICPP_PARSER_H
2 #define INICPP_PARSER_H
3 
4 #include <fstream>
5 #include <iostream>
6 #include <regex>
7 #include <regex>
8 #include <sstream>
9 #include <string>
10 
11 #include "config.h"
12 #include "dll.h"
13 #include "exception.h"
14 #include "schema.h"
15 #include "string_utils.h"
16 
17 namespace inicpp
18 {
23  class INICPP_API parser
24  {
25  private:
31  static size_t find_first_nonescaped(const std::string &str, char ch);
37  static size_t find_last_escaped(const std::string &str, char ch);
38  static std::string unescape(const std::string &str);
39  static std::string delete_comment(const std::string &str);
40  static std::vector<std::string> parse_option_list(const std::string &str);
41  static void handle_links(const config &cfg,
42  const section &last_section,
43  std::vector<std::string> &option_val_list,
44  size_t line_number);
45  static void validate_identifier(const std::string &str, size_t line_number);
46 
47  static config internal_load(std::istream &str);
48  static void internal_save(const config &cfg, const schema &schm, std::ostream &str);
49 
50  public:
54  parser() = delete;
58  parser(const parser &source) = delete;
62  parser &operator=(const parser &source) = delete;
66  parser(parser &&source) = delete;
70  parser &operator=(parser &&source) = delete;
71 
78  static config load(const std::string &str);
89  static config load(const std::string &str, const schema &schm, schema_mode mode);
96  static config load(std::istream &str);
107  static config load(std::istream &str, const schema &schm, schema_mode mode);
108 
115  static config load_file(const std::string &file);
126  static config load_file(const std::string &file, const schema &schm, schema_mode mode);
127 
133  static void save(const config &cfg, const std::string &file);
139  static void save(const config &cfg, std::ostream &str);
147  static void save(const config &cfg, const schema &schm, const std::string &file);
155  static void save(const config &cfg, const schema &schm, std::ostream &str);
161  static void save(const schema &schm, const std::string &file);
167  static void save(const schema &schm, std::ostream &str);
168  };
169 }
170 
171 #endif
Definition: config.h:15