File: jsonwriter.h

package info (click to toggle)
trustedqsl 2.8.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 38,156 kB
  • sloc: cpp: 36,377; xml: 7,984; javascript: 6,989; ansic: 634; sh: 149; makefile: 19; python: 18
file content (122 lines) | stat: -rwxr-xr-x 3,851 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
/////////////////////////////////////////////////////////////////////////////
// Name:        jsonwriter.h
// Purpose:     the generator of JSON text from a JSON value
// Author:      Luciano Cattani
// Created:     2007/09/15
// RCS-ID:      $Id: jsonwriter.h,v 1.4 2008/03/03 19:05:45 luccat Exp $
// Copyright:   (c) 2007 Luciano Cattani
// Licence:     wxWidgets licence
/////////////////////////////////////////////////////////////////////////////

#if !defined(_WX_JSONWRITER_H)
#define _WX_JSONWRITER_H

#ifdef __GNUG_
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-pragmas"
    #pragma interface "jsonwriter.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>
#endif

#include <string>

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

enum {
    wxJSONWRITER_NONE            = 0,
    wxJSONWRITER_STYLED          = 1,
    wxJSONWRITER_WRITE_COMMENTS  = 2,
    wxJSONWRITER_COMMENTS_BEFORE = 4,
    wxJSONWRITER_COMMENTS_AFTER  = 8,
    wxJSONWRITER_SPLIT_STRING    = 16,
    wxJSONWRITER_NO_LINEFEEDS    = 32,
    wxJSONWRITER_ESCAPE_SOLIDUS     = 64,
    wxJSONWRITER_MULTILINE_STRING   = 128,
    wxJSONWRITER_RECOGNIZE_UNSIGNED = 256,
    wxJSONWRITER_TAB_INDENT         = 512,
    wxJSONWRITER_NO_INDENTATION     = 1024,
    wxJSONWRITER_NOUTF8_STREAM      = 2048,
    wxJSONWRITER_MEMORYBUFF         = 4096
};

// class declaration

class WXDLLIMPEXP_JSON wxJSONWriter {
 public:
    explicit wxJSONWriter(int style = wxJSONWRITER_STYLED, int indent = 0, int step = 3);
    ~wxJSONWriter();

    void Write(const wxJSONValue& value, wxString& str);
    void Write(const wxJSONValue& value, wxOutputStream& os);
    void SetDoubleFmtString(const char* fmt);

 protected:
    int  DoWrite(wxOutputStream& os, const wxJSONValue& value, const wxString* key, bool comma);
    int  WriteIndent(wxOutputStream& os);
    int  WriteIndent(wxOutputStream& os, int num);
    bool IsSpace(wxChar ch);
    bool IsPunctuation(wxChar ch);

    int  WriteString(wxOutputStream& os, const wxString& str);
    int  WriteStringValue(wxOutputStream& os, const wxString& str);
    int  WriteNullValue(wxOutputStream& os);
    int  WriteIntValue(wxOutputStream& os, const wxJSONValue& v);
    int  WriteUIntValue(wxOutputStream& os, const wxJSONValue& v);
    int  WriteBoolValue(wxOutputStream& os, const wxJSONValue& v);
    int  WriteDoubleValue(wxOutputStream& os, const wxJSONValue& v);
    int  WriteMemoryBuff(wxOutputStream& os, const wxMemoryBuffer& buff);

    int  WriteInvalid(wxOutputStream& os);
    int  WriteSeparator(wxOutputStream& os);

    int  WriteKey(wxOutputStream& os, const wxString& key);
    int  WriteComment(wxOutputStream& os, const wxJSONValue& value, bool indent);

    int  WriteError(const wxString& err);

 private:
    //! The style flag is a combination of wxJSONWRITER_(something) constants.
    int   m_style;

    //! The initial indentation value, in number of spaces.
    int   m_indent;

    //! The indentation increment, in number of spaces.
    int   m_step;

    //! JSON value objects can be nested; this is the level of annidation (used internally).
    int   m_level;

    // The line number when printing JSON text output (not yet used)
    int   m_lineNo;

    // The column number when printing JSON text output
    int   m_colNo;

    // Flag used in ANSI mode that controls UTF-8 conversion
    bool  m_noUtf8;

    // The format string for printing doubles
    char* m_fmt;
};


#endif            // not defined _WX_JSONWRITER_H