OpenCPN Partial API docs
Loading...
Searching...
No Matches
jsonreader.h
1
2// Name: jsonreader.h
3// Purpose: the parser of JSON text
4// Author: Luciano Cattani
5// Created: 2007/09/15
6// Copyright: (c) 2007 Luciano Cattani
7// Licence: wxWidgets licence
9
10#ifndef WX_JSONREADER_H
11#define WX_JSONREADER_H
12
13// For compilers that support precompilation, includes "wx/wx.h".
14#include <wx/wxprec.h>
15
16// for all others, include the necessary headers (this file is usually all you
17// need because it includes almost all "standard" wxWidgets headers)
18#ifndef WX_PRECOMP
19#include <wx/stream.h>
20#include <wx/string.h>
21#include <wx/arrstr.h>
22#endif
23
24#include "json_defs.h"
25#include "jsonval.h"
26
27// The flags of the parser
28enum {
29 wxJSONREADER_STRICT = 0,
30 wxJSONREADER_ALLOW_COMMENTS = 1,
31 wxJSONREADER_STORE_COMMENTS = 2,
32 wxJSONREADER_CASE = 4,
33 wxJSONREADER_MISSING = 8,
34 wxJSONREADER_MULTISTRING = 16,
35 wxJSONREADER_COMMENTS_AFTER = 32,
36 wxJSONREADER_NOUTF8_STREAM = 64,
37 wxJSONREADER_MEMORYBUFF = 128,
38
39 wxJSONREADER_TOLERANT = wxJSONREADER_ALLOW_COMMENTS | wxJSONREADER_CASE |
40 wxJSONREADER_MISSING | wxJSONREADER_MULTISTRING,
41 wxJSONREADER_COMMENTS_BEFORE =
42 wxJSONREADER_ALLOW_COMMENTS | wxJSONREADER_STORE_COMMENTS
43};
44
45class WXDLLIMPEXP_JSON wxJSONReader {
46public:
47 wxJSONReader(int flags = wxJSONREADER_TOLERANT, int maxErrors = 30);
48 virtual ~wxJSONReader();
49
50 int Parse(const wxString& doc, wxJSONValue* val);
51 int Parse(wxInputStream& doc, wxJSONValue* val);
52
53 int GetDepth() const;
54 int GetErrorCount() const;
55 int GetWarningCount() const;
56 const wxArrayString& GetErrors() const;
57 const wxArrayString& GetWarnings() const;
58
59 static int UTF8NumBytes(char ch);
60
61#if defined(wxJSON_64BIT_INT)
62 static bool Strtoll(const wxString& str, wxInt64* i64);
63 static bool Strtoull(const wxString& str, wxUint64* ui64);
64 static bool DoStrto_ll(const wxString& str, wxUint64* ui64, wxChar* sign);
65#endif
66
67protected:
68 int DoRead(wxInputStream& doc, wxJSONValue& val);
69 void AddError(const wxString& descr);
70 void AddError(const wxString& fmt, const wxString& str);
71 void AddError(const wxString& fmt, wxChar ch);
72 void AddWarning(int type, const wxString& descr);
73 int GetStart(wxInputStream& is);
74 int ReadChar(wxInputStream& is);
75 int PeekChar(wxInputStream& is);
76 void StoreValue(int ch, const wxString& key, wxJSONValue& value,
77 wxJSONValue& parent);
78 int SkipWhiteSpace(wxInputStream& is);
79 int SkipComment(wxInputStream& is);
80 void StoreComment(const wxJSONValue* parent);
81 int ReadString(wxInputStream& is, wxJSONValue& val);
82 int ReadToken(wxInputStream& is, int ch, wxString& s);
83 int ReadValue(wxInputStream& is, int ch, wxJSONValue& val);
84 int ReadUES(wxInputStream& is, char* uesBuffer);
85 int AppendUES(wxMemoryBuffer& utf8Buff, const char* uesBuffer);
86 int NumBytes(char ch);
87 int ConvertCharByChar(wxString& s, const wxMemoryBuffer& utf8Buffer);
88 int ReadMemoryBuff(wxInputStream& is, wxJSONValue& val);
89
92
95
98
101
104
107
110
113
116
118 wxString m_comment;
119
122
124 wxArrayString m_errors;
125
127 wxArrayString m_warnings;
128
131
134};
135
136#endif // WX_JSONREADER_H
The JSON parser.
Definition jsonreader.h:45
int m_colNo
The current column number (start at 1).
Definition jsonreader.h:100
int m_maxErrors
Maximum number of errors stored in the error's array.
Definition jsonreader.h:94
bool m_noUtf8
ANSI: do not convert UTF-8 strings.
Definition jsonreader.h:133
wxJSONValue * m_lastStored
The pointer to the value object that was last stored.
Definition jsonreader.h:112
int m_flags
Flag that control the parser behaviour,.
Definition jsonreader.h:91
int m_lineNo
The current line number (start at 1).
Definition jsonreader.h:97
int m_commentLine
The starting line of the comment string.
Definition jsonreader.h:121
int m_depth
The depth level of the read JSON text.
Definition jsonreader.h:106
wxJSONValue * m_current
The pointer to the value object that is being read.
Definition jsonreader.h:109
int m_level
The current level of object/array annidation (start at ZERO).
Definition jsonreader.h:103
wxArrayString m_errors
The array of error messages.
Definition jsonreader.h:124
wxArrayString m_warnings
The array of warning messages.
Definition jsonreader.h:127
wxJSONValue * m_next
The pointer to the value object that will be read.
Definition jsonreader.h:115
wxString m_comment
The comment string read by SkipComment().
Definition jsonreader.h:118
int m_peekChar
The character read by the PeekChar() function (-1 none)
Definition jsonreader.h:130
The JSON value class implementation.
Definition jsonval.h:79