File: jsonreader.h

package info (click to toggle)
trustedqsl 2.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 38,012 kB
  • sloc: cpp: 36,137; xml: 7,977; javascript: 6,989; ansic: 634; sh: 149; makefile: 19; python: 18
file content (152 lines) | stat: -rwxr-xr-x 4,813 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/////////////////////////////////////////////////////////////////////////////
// Name:        jsonreader.h
// Purpose:     the parser of JSON text
// Author:      Luciano Cattani
// Created:     2007/09/15
// RCS-ID:      $Id: jsonreader.h,v 1.3 2008/03/03 19:05:45 luccat Exp $
// Copyright:   (c) 2007 Luciano Cattani
// Licence:     wxWidgets licence
/////////////////////////////////////////////////////////////////////////////

#if !defined(_WX_JSONREADER_H)
#define _WX_JSONREADER_H

#ifdef __GNUG_
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-pragmas"
    #pragma interface "jsonreader.h"
#pragma clang diagnostic pop
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
    #include <wx/stream.h>
    #include <wx/string.h>
    #include <wx/arrstr.h>
#endif

#include <string>

#include "json_defs.h"
#include "jsonval.h"

// The flags of the parser
enum {
    wxJSONREADER_STRICT          = 0,
    wxJSONREADER_ALLOW_COMMENTS  = 1,
    wxJSONREADER_STORE_COMMENTS  = 2,
    wxJSONREADER_CASE            = 4,
    wxJSONREADER_MISSING         = 8,
    wxJSONREADER_MULTISTRING     = 16,
    wxJSONREADER_COMMENTS_AFTER  = 32,
    wxJSONREADER_NOUTF8_STREAM   = 64,
    wxJSONREADER_MEMORYBUFF      = 128,

    wxJSONREADER_TOLERANT        = wxJSONREADER_ALLOW_COMMENTS | wxJSONREADER_CASE |
                                 wxJSONREADER_MISSING | wxJSONREADER_MULTISTRING,
    wxJSONREADER_COMMENTS_BEFORE = wxJSONREADER_ALLOW_COMMENTS | wxJSONREADER_STORE_COMMENTS
};


class WXDLLIMPEXP_JSON  wxJSONReader {
 public:
    explicit wxJSONReader(int flags = wxJSONREADER_TOLERANT, int maxErrors = 30);
    virtual ~wxJSONReader();

    int Parse(const wxString& doc, wxJSONValue* val);
    int Parse(wxInputStream& doc, wxJSONValue* val);

    int   GetDepth() const;
    int   GetErrorCount() const;
    int   GetWarningCount() const;
    const wxArrayString& GetErrors() const;
    const wxArrayString& GetWarnings() const;

    static int  UTF8NumBytes(char ch);

#if defined(wxJSON_64BIT_INT)
    static bool Strtoll(const wxString& str, wxInt64* i64);
    static bool Strtoull(const wxString& str, wxUint64* ui64);
    static bool DoStrto_ll(const wxString& str, wxUint64* ui64, wxChar* sign);
#endif

 protected:
    int  DoRead(wxInputStream& doc, wxJSONValue& val);
    void AddError(const wxString& descr);
    void AddError(const wxString& fmt, const wxString& str);
    void AddError(const wxString& fmt, wxChar ch);
    void AddWarning(int type, const wxString& descr);
    int  GetStart(wxInputStream& is);
    int  ReadChar(wxInputStream& is);
    int  PeekChar(wxInputStream& is);
    void StoreValue(int ch, const wxString& key, wxJSONValue& value, wxJSONValue& parent);
    int  SkipWhiteSpace(wxInputStream& is);
    int  SkipComment(wxInputStream& is);
    void StoreComment(const wxJSONValue* parent);
    int  ReadString(wxInputStream& is, wxJSONValue& val);
    int  ReadToken(wxInputStream& is, int ch, wxString& s);
    int  ReadValue(wxInputStream& is, int ch, wxJSONValue& val);
    int  ReadUES(wxInputStream& is, char* uesBuffer);
    int  AppendUES(wxMemoryBuffer& utf8Buff, const char* uesBuffer);
    int  NumBytes(char ch);
    int  ConvertCharByChar(wxString& s, const wxMemoryBuffer& utf8Buffer);
    int  ReadMemoryBuff(wxInputStream& is, wxJSONValue& val);

    //! Flag that control the parser behaviour,
    int  m_flags;

    //! Maximum number of errors stored in the error's array
    int  m_maxErrors;

    //! The current line number (start at 1).
    int  m_lineNo;

    //! The current column number (start at 1).
    int  m_colNo;

    //! The current level of object/array annidation (start at ZERO).
    int  m_level;

    //! The depth level of the read JSON text
    int  m_depth;

    //! The pointer to the value object that is being read.
    wxJSONValue* m_current;

    //! The pointer to the value object that was last stored.
    wxJSONValue* m_lastStored;

    //! The pointer to the value object that will be read.
    wxJSONValue* m_next;

    //! The comment string read by SkipComment().
    wxString     m_comment;

    //! The starting line of the comment string.
    int          m_commentLine;

    //! The array of error messages.
    wxArrayString m_errors;

    //! The array of warning messages.
    wxArrayString m_warnings;

    //! The character read by the PeekChar() function (-1 none)
    int           m_peekChar;

    //! ANSI: do not convert UTF-8 strings
    bool        m_noUtf8;
};


#endif            // not defined _WX_JSONREADER_H