diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-06-24 13:38:59 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-06-24 13:39:45 +0200 |
commit | 266fed8c00725882558b319e75aedfe071c8fd5f (patch) | |
tree | 2b4b4778657539ecce7dde5f841e880fb6395dd1 /AK/JsonParser.h | |
parent | 8392c549a3f8af09fce0218b680f766f593aaf3a (diff) | |
download | serenity-266fed8c00725882558b319e75aedfe071c8fd5f.zip |
AK: Let's put the JSON parsing in a separate class.
Diffstat (limited to 'AK/JsonParser.h')
-rw-r--r-- | AK/JsonParser.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/AK/JsonParser.h b/AK/JsonParser.h new file mode 100644 index 0000000000..76f7d7e5bf --- /dev/null +++ b/AK/JsonParser.h @@ -0,0 +1,47 @@ +#pragma once + +#include <AK/JsonValue.h> + +namespace AK { + +class JsonParser { +public: + explicit JsonParser(const StringView& input) + : m_input(input) + { + } + ~JsonParser() + { + } + + JsonValue parse(); + +private: + char peek() const; + char consume(); + void consume_whitespace(); + void consume_specific(char expected_ch); + void consume_string(const char*); + String consume_quoted_string(); + JsonValue parse_array(); + JsonValue parse_object(); + JsonValue parse_number(); + JsonValue parse_string(); + JsonValue parse_false(); + JsonValue parse_true(); + JsonValue parse_null(); + JsonValue parse_undefined(); + + template<typename C> + void consume_while(C); + + template<typename C> + String extract_while(C); + + StringView m_input; + int m_index { 0 }; +}; + +} + +using AK::JsonParser; |