MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
json_parser.hpp
1#ifndef MSTL_CORE_FILE_JSON_JSON_PARSER_HPP__
2#define MSTL_CORE_FILE_JSON_JSON_PARSER_HPP__
4#include "json_value.hpp"
6
7class MSTL_API json_parser {
8private:
9 string json;
10 size_t length;
11 size_t pos = 0;
12
13 void skip_space() noexcept {
14 while (pos < length && _MSTL is_space(json[pos])) {
15 pos++;
16 }
17 }
18
19 char current() const noexcept {
20 if (pos < length) return json[pos];
21 return '\0';
22 }
23
24 bool eof() const noexcept { return pos >= length; }
25
26
27 unique_ptr<json_string> parse_string();
28 unique_ptr<json_number> parse_number();
29 unique_ptr<json_value> parse_keyword();
30 unique_ptr<json_array> parse_array();
31 unique_ptr<json_object> parse_object();
32 unique_ptr<json_value> parse_value();
33
34public:
35 explicit json_parser(string json_str) noexcept
36 : json(_MSTL move(json_str)), length(json.size()) {}
37
38 unique_ptr<json_value> parse();
39 optional<unique_ptr<json_value>> try_parse();
40};
41
43#endif // MSTL_CORE_FILE_JSON_JSON_PARSER_HPP__
MSTL_PURE_FUNCTION MSTL_CONSTEXPR14 bool is_space(const CharT c) noexcept
检查字符是否为空白字符
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result)
移动范围元素
MSTL可选值类型