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